Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

XWIKI-7381: Add the Actions column to the applications live table

* Add functional tests.
* Update tests that were using DeletePage and DeleteConfirmationPage.
  • Loading branch information...
commit fbd0f090527919105a9ddc1fc6fe3527abf429d9 1 parent 6ec250b
@mflorea mflorea authored
View
5 ...terprise-test-pageobjects/src/main/java/org/xwiki/test/po/appwithinminutes/AppWithinMinutesHomePage.java
@@ -21,7 +21,6 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
-import org.xwiki.test.ui.po.LiveTableElement;
import org.xwiki.test.ui.po.ViewPage;
/**
@@ -43,7 +42,7 @@
/**
* The live table that lists the existing applications.
*/
- private LiveTableElement appsLiveTable = new LiveTableElement("livetable");
+ private ApplicationsLiveTableElement appsLiveTable = new ApplicationsLiveTableElement();
/**
* Opens the App Within Minutes home page.
@@ -78,7 +77,7 @@ public ApplicationCreatePage clickCreateApplication()
/**
* @return the live table that list existing applications
*/
- public LiveTableElement getAppsLiveTable()
+ public ApplicationsLiveTableElement getAppsLiveTable()
{
return appsLiveTable;
}
View
145 ...rise-test-pageobjects/src/main/java/org/xwiki/test/po/appwithinminutes/ApplicationsLiveTableElement.java
@@ -0,0 +1,145 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.test.po.appwithinminutes;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.xwiki.test.ui.po.ConfirmationPage;
+import org.xwiki.test.ui.po.LiveTableElement;
+
+/**
+ * Represents the live table that lists the existing applications on the AppWithinMinuts home page.
+ *
+ * @version $Id$
+ * @since 4.0M2
+ */
+public class ApplicationsLiveTableElement extends LiveTableElement
+{
+ /**
+ * Identifies the application name filter input.
+ */
+ private static final String APP_NAME_FILTER_ID = "xwiki-livetable-livetable-filter-1";
+
+ /**
+ * The title of the live table column that displays the application name.
+ */
+ private static final String APP_NAME_COLUMN_TITLE = "Application name";
+
+ /**
+ * Creates a new instance.
+ */
+ public ApplicationsLiveTableElement()
+ {
+ super("livetable");
+ }
+
+ /**
+ * @param appName the name of an application
+ * @return {@code true} if the specified application is listed, {@code false} otherwise
+ */
+ public boolean isApplicationListed(String appName)
+ {
+ return hasRow(APP_NAME_COLUMN_TITLE, appName);
+ }
+
+ /**
+ * Clicks on the link to delete the specified application.
+ *
+ * @param appName the name of the application to delete
+ */
+ public ConfirmationPage clickDeleteApplication(String appName)
+ {
+ clickAction(appName, "delete");
+ return new ConfirmationPage();
+ }
+
+ /**
+ * @param appName the name of an application
+ * @return {@code true} if the delete link is displayed for the specified application
+ */
+ public boolean canDeleteApplication(String appName)
+ {
+ return hasAction(appName, "delete");
+ }
+
+ /**
+ * Clicks on the link to edit the specified application.
+ *
+ * @param appName the name of the application to delete.
+ */
+ public ApplicationClassEditPage clickEditApplication(String appName)
+ {
+ clickAction(appName, "edit");
+ return new ApplicationClassEditPage();
+ }
+
+ /**
+ * @param appName the name of an application
+ * @return {@code true} if the edit link is displayed for the specified application
+ */
+ public boolean canEditApplication(String appName)
+ {
+ return hasAction(appName, "edit");
+ }
+
+ /**
+ * Clicks one of the action links corresponding to the specified application.
+ *
+ * @param appName the action target
+ * @param action the action name
+ */
+ protected void clickAction(String appName, String action)
+ {
+ String escapedAppName = appName.replace("\\", "\\\\").replace("'", "\\'");
+ String actionLinkXPath =
+ "//tr[td[contains(@class, 'doc_space') and . = '" + escapedAppName
+ + "']]/td[@class = 'actions']//a[contains(@class, 'action" + action + "')]";
+ WebElement liveTableBody = getDriver().findElement(By.id("livetable-display"));
+ liveTableBody.findElement(By.xpath(actionLinkXPath)).click();
+ }
+
+ /**
+ * @return {@code true} if the given action is listed for the specified application, {@code false} otherwise
+ */
+ protected boolean hasAction(String appName, String action)
+ {
+ String escapedAppName = appName.replace("\\", "\\\\").replace("'", "\\'");
+ String actionLinkXPath =
+ "//tr[td[contains(@class, 'doc_space') and . = '" + escapedAppName
+ + "']]/td[@class = 'actions']//a[contains(@class, 'action" + action + "')]";
+ WebElement liveTableBody = getDriver().findElement(By.id("livetable-display"));
+ return liveTableBody.findElements(By.xpath(actionLinkXPath)).size() > 0;
+ }
+
+ /**
+ * Filters by application name.
+ *
+ * @param appNameFilter the string to filter the application names with
+ */
+ public void filterApplicationName(String appNameFilter)
+ {
+ super.filterColumn(APP_NAME_FILTER_ID, appNameFilter);
+ }
+
+ public String getApplicationNameFilter()
+ {
+ return super.getFilterValue(APP_NAME_FILTER_ID);
+ }
+}
View
6 ...-test/xwiki-enterprise-test-pageobjects/src/main/java/org/xwiki/test/po/scheduler/SchedulerHomePage.java
@@ -22,7 +22,7 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
-import org.xwiki.test.ui.po.DeletePage;
+import org.xwiki.test.ui.po.ConfirmationPage;
import org.xwiki.test.ui.po.ViewPage;
import org.xwiki.test.po.scheduler.editor.SchedulerEditPage;
@@ -69,10 +69,10 @@ public SchedulerEditPage clickJobActionEdit(String jobName)
return sep;
}
- public DeletePage clickJobActionDelete(String jobName)
+ public ConfirmationPage clickJobActionDelete(String jobName)
{
clickAction(jobName, "delete");
- return new DeletePage();
+ return new ConfirmationPage();
}
public void clickJobActionScheduler(String jobName)
View
20 xwiki-enterprise-test/xwiki-enterprise-test-ui/src/test/it/org/xwiki/test/ui/DeletePageTest.java
@@ -25,10 +25,10 @@
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
-import org.xwiki.test.ui.po.DeleteConfirmationPage;
-import org.xwiki.test.ui.po.DeletePage;
-import org.xwiki.test.ui.po.ViewPage;
import org.xwiki.test.po.xe.HomePage;
+import org.xwiki.test.ui.po.ConfirmationPage;
+import org.xwiki.test.ui.po.DeletePageOutcomePage;
+import org.xwiki.test.ui.po.ViewPage;
/**
* Tests the Delete button present in the top level menu.
@@ -67,13 +67,14 @@ public void setUp()
@Test
public void testDeleteOkWhenConfirming()
{
- DeletePage deletePage = this.viewPage.delete();
+ ConfirmationPage confirmationPage = this.viewPage.delete();
// This tests for regression of XWIKI-1388
Assert.assertNotNull("The interface should not show the user as logged out while deleting page",
- this.viewPage.getCurrentUser());
- DeleteConfirmationPage deleteConfirmationPage = deletePage.confirm();
- Assert.assertEquals(LOGGED_USERNAME, deleteConfirmationPage.getPageDeleter());
- Assert.assertEquals(CONFIRMATION, deleteConfirmationPage.getConfirmationMessage());
+ confirmationPage.getCurrentUser());
+ confirmationPage.clickYes();
+ DeletePageOutcomePage deleteOutcome = new DeletePageOutcomePage();
+ Assert.assertEquals(LOGGED_USERNAME, deleteOutcome.getPageDeleter());
+ Assert.assertEquals(CONFIRMATION, deleteOutcome.getMessage());
}
/**
@@ -108,8 +109,7 @@ public void testDeletePageCanDoRedirect()
@Test
public void testDeletePageGoesToOriginalPageWhenCancelled()
{
- DeletePage deletePage = this.viewPage.delete();
- deletePage.cancel();
+ this.viewPage.delete().clickNo();
Assert.assertTrue(getDriver().getCurrentUrl().equals(getUtil().getURL(SPACE_VALUE, PAGE_VALUE)));
}
View
177 ...rise-test/xwiki-enterprise-test-ui/src/test/it/org/xwiki/test/ui/appwithinminutes/AppsLiveTableTest.java
@@ -0,0 +1,177 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.test.ui.appwithinminutes;
+
+import junit.framework.Assert;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.xwiki.test.po.appwithinminutes.AppWithinMinutesHomePage;
+import org.xwiki.test.po.appwithinminutes.ApplicationClassEditPage;
+import org.xwiki.test.po.appwithinminutes.ApplicationCreatePage;
+import org.xwiki.test.po.appwithinminutes.ApplicationHomeEditPage;
+import org.xwiki.test.po.appwithinminutes.ApplicationHomePage;
+import org.xwiki.test.po.appwithinminutes.ApplicationsLiveTableElement;
+import org.xwiki.test.po.appwithinminutes.ClassFieldEditPane;
+import org.xwiki.test.ui.AbstractTest;
+
+/**
+ * Tests the live table that lists the existing applications on the AppWithinMinutes home page.
+ *
+ * @version $Id$
+ * @since 4.0M2
+ */
+public class AppsLiveTableTest extends AbstractTest
+{
+ /**
+ * The page being tested.
+ */
+ private AppWithinMinutesHomePage homePage = new AppWithinMinutesHomePage();
+
+ @Before
+ public void setUp()
+ {
+ // Register a simple user, login and go to the AppWithinMinutes home page.
+ String userName = RandomStringUtils.randomAlphanumeric(5);
+ String password = RandomStringUtils.randomAlphanumeric(6);
+ getUtil().registerLoginAndGotoPage(userName, password, homePage.getURL());
+ }
+
+ /**
+ * Creates an application and deletes it using the Actions column from the applications live table.
+ */
+ @Test
+ public void testDeleteApplication()
+ {
+ // Create the application.
+ String appName = RandomStringUtils.randomAlphabetic(6);
+ createApplication(appName);
+
+ // Check the the applications live table lists the created application.
+ ApplicationsLiveTableElement appsLiveTable = homePage.getAppsLiveTable();
+ appsLiveTable.waitUntilReady();
+ Assert.assertTrue(appsLiveTable.hasColumn("Actions"));
+ appsLiveTable.filterApplicationName(appName.substring(0, 3));
+ Assert.assertTrue(appsLiveTable.isApplicationListed(appName));
+
+ // Click the delete icon then cancel the confirmation.
+ appsLiveTable.clickDeleteApplication(appName).clickNo();
+ // We should be taken back to the AppWithinMinutes home page.
+ homePage = new AppWithinMinutesHomePage();
+ appsLiveTable = homePage.getAppsLiveTable();
+ appsLiveTable.waitUntilReady();
+ // The application name filter should've been preserved.
+ Assert.assertEquals(appName.substring(0, 3), appsLiveTable.getApplicationNameFilter());
+
+ // Click the delete icon again and this confirm the action.
+ appsLiveTable.clickDeleteApplication(appName).clickYes();
+ // We should be taken back to the AppWithinMinutes home page.
+ homePage = new AppWithinMinutesHomePage();
+ appsLiveTable = homePage.getAppsLiveTable();
+ appsLiveTable.waitUntilReady();
+ // The application name filter should've been preserved.
+ Assert.assertEquals(appName.substring(0, 3), appsLiveTable.getApplicationNameFilter());
+ // And the deleted application shouldn't be listed anymore.
+ Assert.assertFalse(appsLiveTable.isApplicationListed(appName));
+ }
+
+ /**
+ * Creates an application and edits it using the Actions column from the applications live table.
+ */
+ @Test
+ public void testEditApplication()
+ {
+ // Create the application.
+ String appName = RandomStringUtils.randomAlphabetic(6);
+ createApplication(appName);
+
+ // Edit the application.
+ ApplicationsLiveTableElement appsLiveTable = homePage.getAppsLiveTable();
+ appsLiveTable.waitUntilReady();
+ ApplicationClassEditPage classEditor = appsLiveTable.clickEditApplication(appName);
+
+ // Edit the existing class field.
+ ClassFieldEditPane fieldEditPane = new ClassFieldEditPane("shortText1");
+ fieldEditPane.setPrettyName("City Name");
+ fieldEditPane.openConfigPanel();
+ fieldEditPane.setName("cityName");
+
+ // Move to the next step.
+ ApplicationHomeEditPage homeEditPage = classEditor.clickNextStep();
+ homeEditPage.setDescription("demo");
+
+ // Finish editing.
+ ApplicationHomePage homePage = homeEditPage.clickFinish();
+ Assert.assertTrue(homePage.getContent().contains("demo"));
+ }
+
+ /**
+ * Tests that the actions are displayed only when the current user has the right to perform them.
+ */
+ @Test
+ public void testActionRights()
+ {
+ // Create the application.
+ String appName = RandomStringUtils.randomAlphabetic(6);
+ createApplication(appName);
+
+ // The application author should be able to edit and delete the application.
+ ApplicationsLiveTableElement appsLiveTable = homePage.getAppsLiveTable();
+ appsLiveTable.waitUntilReady();
+ appsLiveTable.filterApplicationName(appName);
+ Assert.assertTrue(appsLiveTable.canEditApplication(appName));
+ Assert.assertTrue(appsLiveTable.canDeleteApplication(appName));
+
+ // Logout. Guests shouldn't be able to edit nor delete the application.
+ homePage.logout();
+ getUtil().recacheSecretToken();
+ homePage = new AppWithinMinutesHomePage();
+ appsLiveTable = homePage.getAppsLiveTable();
+ appsLiveTable.waitUntilReady();
+ appsLiveTable.filterApplicationName(appName);
+ Assert.assertFalse(appsLiveTable.canEditApplication(appName));
+ Assert.assertFalse(appsLiveTable.canDeleteApplication(appName));
+
+ // Login with a different user. The new user shouldn't be able to delete the application.
+ getUtil().registerLoginAndGotoPage("someOtherUser", "somePassword", homePage.getURL());
+ appsLiveTable = new AppWithinMinutesHomePage().getAppsLiveTable();
+ appsLiveTable.waitUntilReady();
+ appsLiveTable.filterApplicationName(appName);
+ Assert.assertTrue(appsLiveTable.canEditApplication(appName));
+ Assert.assertFalse(appsLiveTable.canDeleteApplication(appName));
+ }
+
+ /**
+ * Creates an application with the specified name. The application class will have just one field.
+ *
+ * @param appName the name of the application to create
+ */
+ private void createApplication(String appName)
+ {
+ ApplicationCreatePage appCreatePage = homePage.clickCreateApplication();
+ appCreatePage.setApplicationName(appName);
+ appCreatePage.waitForApplicationNamePreview();
+ ApplicationClassEditPage classEditPage = appCreatePage.clickNextStep();
+ classEditPage.addField("Short Text");
+ classEditPage.clickNextStep().clickFinish().clickBreadcrumbLink(AppWithinMinutesHomePage.TITLE);
+ homePage = new AppWithinMinutesHomePage();
+ }
+}
View
5 ...-enterprise-test/xwiki-enterprise-test-ui/src/test/it/org/xwiki/test/ui/appwithinminutes/WizardTest.java
@@ -29,6 +29,7 @@
import org.xwiki.test.po.appwithinminutes.ApplicationCreatePage;
import org.xwiki.test.po.appwithinminutes.ApplicationHomeEditPage;
import org.xwiki.test.po.appwithinminutes.ApplicationHomePage;
+import org.xwiki.test.po.appwithinminutes.ApplicationsLiveTableElement;
import org.xwiki.test.po.appwithinminutes.ClassFieldEditPane;
import org.xwiki.test.po.appwithinminutes.EntryEditPage;
import org.xwiki.test.po.appwithinminutes.EntryNamePane;
@@ -196,9 +197,9 @@ public void testCreateApplication()
AppWithinMinutesHomePage appWithinMinutesHomePage = new AppWithinMinutesHomePage();
// Assert that the created application is listed in the live table.
- LiveTableElement appsLiveTable = appWithinMinutesHomePage.getAppsLiveTable();
+ ApplicationsLiveTableElement appsLiveTable = appWithinMinutesHomePage.getAppsLiveTable();
appsLiveTable.waitUntilReady();
- Assert.assertTrue(appsLiveTable.hasRow("Application name", appName));
+ Assert.assertTrue(appsLiveTable.isApplicationListed(appName));
}
/**
View
8 xwiki-enterprise-test/xwiki-enterprise-test-ui/src/test/it/org/xwiki/test/ui/scheduler/SchedulerTest.java
@@ -25,12 +25,11 @@
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
-import org.xwiki.test.ui.AbstractAdminAuthenticatedTest;
-import org.xwiki.test.ui.po.DeletePage;
-import org.xwiki.test.ui.po.ViewPage;
import org.xwiki.test.po.scheduler.SchedulerHomePage;
import org.xwiki.test.po.scheduler.SchedulerPage;
import org.xwiki.test.po.scheduler.editor.SchedulerEditPage;
+import org.xwiki.test.ui.AbstractAdminAuthenticatedTest;
+import org.xwiki.test.ui.po.ViewPage;
/**
* Tests Scheduler application features.
@@ -91,8 +90,7 @@ public void testJobActions()
schedulerHomePage = schedulerPage.backToHome();
// Delete and Restore Job
- DeletePage deletePage = schedulerHomePage.clickJobActionDelete(jobName);
- deletePage.confirm();
+ schedulerHomePage.clickJobActionDelete(jobName).clickYes();
schedulerHomePage = SchedulerHomePage.gotoPage();
Assert.assertFalse(getUtil().hasElement(By.linkText(jobName)));
getUtil().gotoPage("Scheduler", "SchedulerTestJob");
Please sign in to comment.
Something went wrong with that request. Please try again.