From b3722f912c36280aff668de349c039ec58bc0ea3 Mon Sep 17 00:00:00 2001 From: Manuel Leduc Date: Fri, 26 Jan 2024 16:21:22 +0100 Subject: [PATCH] XWIKI-18998: Replace the Livetable of the System Filters of the Notifications Administration with a Live Data macro --- .../livedata/test/po/TableLayoutElement.java | 9 ++++ .../main/vue/displayers/DisplayerToggle.vue | 22 +++----- .../src/main/vue/utilities/XWikiIcon.vue | 2 + .../test/ui/NotificationsEmailsIT.java | 2 +- .../pom.xml | 6 +++ .../po/AbstractNotificationsSettingsPage.java | 42 ++++----------- .../AbstractNotificationFilterPreference.java | 53 ++++++++++++++----- .../CustomNotificationFilterPreference.java | 25 ++++++++- .../SystemNotificationFilterPreference.java | 24 +++++++-- .../xwiki-platform-notifications-ui/pom.xml | 15 ++++++ 10 files changed, 134 insertions(+), 66 deletions(-) diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-test/xwiki-platform-livedata-test-pageobjects/src/main/java/org/xwiki/livedata/test/po/TableLayoutElement.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-test/xwiki-platform-livedata-test-pageobjects/src/main/java/org/xwiki/livedata/test/po/TableLayoutElement.java index f86fcd2b23b5..89ce2dd81842 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-test/xwiki-platform-livedata-test-pageobjects/src/main/java/org/xwiki/livedata/test/po/TableLayoutElement.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-test/xwiki-platform-livedata-test-pageobjects/src/main/java/org/xwiki/livedata/test/po/TableLayoutElement.java @@ -76,6 +76,15 @@ public class TableLayoutElement extends BaseElement private final LiveDataElement liveData; + /** + * @return the list of rows Web Elements + * @since 16.1.0RC1 + */ + public List getRows() + { + return getRoot().findElements(By.cssSelector("tbody > tr")); + } + /** * A matcher for the cell containing links. The matcher assert of a given {@link WebElement} contains a {@code a} * tag with the expected text and link. diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-webjar/src/main/vue/displayers/DisplayerToggle.vue b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-webjar/src/main/vue/displayers/DisplayerToggle.vue index e46f361b7e28..1f0f856e2cfd 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-webjar/src/main/vue/displayers/DisplayerToggle.vue +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-webjar/src/main/vue/displayers/DisplayerToggle.vue @@ -19,14 +19,12 @@ --> @@ -86,6 +79,7 @@ export default { }, data() { return { + // When this value changes to true following the ready from XWikiIcon, the toggle is initialized. iconReady: false, innerChecked: this.entry[`${this.propertyId}_checked`], innerDisabled: this.entry[`${this.propertyId}_disabled`], @@ -132,8 +126,4 @@ export default { } } } - - - \ No newline at end of file + \ No newline at end of file diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-webjar/src/main/vue/utilities/XWikiIcon.vue b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-webjar/src/main/vue/utilities/XWikiIcon.vue index 2e297bb8cb00..ca0f22ed2cdc 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-webjar/src/main/vue/utilities/XWikiIcon.vue +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-webjar/src/main/vue/utilities/XWikiIcon.vue @@ -125,6 +125,8 @@ export default { } // Set the icon to the resolved value of the promise. this.remoteIconDescriptor = await iconCache[iconName]; + // Send a ready even once initialize so that parent containers can know when this component is in a stable + // state. this.$emit('ready'); }, immediate: true diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-docker/src/test/it/org/xwiki/platform/notifications/test/ui/NotificationsEmailsIT.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-docker/src/test/it/org/xwiki/platform/notifications/test/ui/NotificationsEmailsIT.java index 0984671213ce..d152f7572954 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-docker/src/test/it/org/xwiki/platform/notifications/test/ui/NotificationsEmailsIT.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-docker/src/test/it/org/xwiki/platform/notifications/test/ui/NotificationsEmailsIT.java @@ -114,7 +114,7 @@ public void setup(TestUtils testUtils, TestConfiguration testConfiguration) thro p = NotificationsUserProfilePage.gotoPage(FIRST_USER_NAME); p.disableAllParameters(); // Enable own filter - p.getNotificationFilterPreferences().get(2).setEnabled(true); + p.getSystemNotificationFilterPreferences().get(2).setEnabled(true); testUtils.login(SECOND_USER_NAME, SECOND_USER_PASSWORD); p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/pom.xml b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/pom.xml index 1edbb8f7f90f..187a9ba457c0 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/pom.xml +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/pom.xml @@ -47,5 +47,11 @@ xwiki-platform-index-tree-test-pageobjects ${project.version} + + + org.xwiki.platform + xwiki-platform-livedata-test-pageobjects + ${project.version} + diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/AbstractNotificationsSettingsPage.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/AbstractNotificationsSettingsPage.java index 5b3dc7619e9e..6c8fb0703d90 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/AbstractNotificationsSettingsPage.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/AbstractNotificationsSettingsPage.java @@ -27,21 +27,22 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; +import org.xwiki.livedata.test.po.LiveDataElement; +import org.xwiki.livedata.test.po.TableLayoutElement; import org.xwiki.platform.notifications.test.po.preferences.AbstractNotificationPreferences; import org.xwiki.platform.notifications.test.po.preferences.ApplicationPreferences; import org.xwiki.platform.notifications.test.po.preferences.EventTypePreferences; import org.xwiki.platform.notifications.test.po.preferences.filters.CustomNotificationFilterModal; import org.xwiki.platform.notifications.test.po.preferences.filters.CustomNotificationFilterPreference; -import org.xwiki.platform.notifications.test.po.preferences.filters.NotificationFilterPreference; import org.xwiki.platform.notifications.test.po.preferences.filters.SystemNotificationFilterPreference; import org.xwiki.test.ui.po.BootstrapSwitch; import org.xwiki.test.ui.po.Select; import org.xwiki.test.ui.po.ViewPage; /** - * Represents a page for notification settings. - * This kind of page can be seen in user profile or in global administration. - * + * Represents a page for notification settings. This kind of page can be seen in user profile or in global + * administration. + * * @version $Id$ * @since 13.2RC1 */ @@ -57,9 +58,6 @@ public abstract class AbstractNotificationsSettingsPage extends ViewPage private static final String ROW_TAG = "tr"; - @FindBy(id = "notificationSystemFilterPreferencesLiveTable-display") - protected WebElement notificationSystemFilterPreferencesLivetable; - @FindBy(id = "notificationCustomFilterPreferencesLiveTable-display") protected WebElement notificationCustomFilterPreferencesLivetable; @@ -278,37 +276,19 @@ public void disableAllParameters() } } - /** - * @return the notification filter preferences, as they are described in the corresponding livetable - * - * @since 10.8RC1 - * @since 9.11.8 - * @deprecated Since 13.2RC1 you should use - * {@link #getSystemNotificationFilterPreferences()} or - * {@link #getCustomNotificationFilterPreferences()}. - */ - @Deprecated - public List getNotificationFilterPreferences() - { - List preferences = new ArrayList<>(); - for (WebElement row : this.notificationSystemFilterPreferencesLivetable.findElements(By.tagName(ROW_TAG))) { - preferences.add(new NotificationFilterPreference(this, row, this.getDriver())); - } - for (WebElement row : this.notificationCustomFilterPreferencesLivetable.findElements(By.tagName(ROW_TAG))) { - preferences.add(new NotificationFilterPreference(this, row, this.getDriver())); - } - return preferences; - } - /** * @return the system notification filter preferences. * @since 13.2RC1 */ public List getSystemNotificationFilterPreferences() { + LiveDataElement notificationSystemFilterPreferencesLiveData = + new LiveDataElement("notificationSystemFilterPreferencesLiveData"); + TableLayoutElement tableLayout = notificationSystemFilterPreferencesLiveData.getTableLayout(); + List preferences = new ArrayList<>(); - for (WebElement row : this.notificationSystemFilterPreferencesLivetable.findElements(By.tagName(ROW_TAG))) { - preferences.add(new SystemNotificationFilterPreference(this, row, this.getDriver())); + for (WebElement row : tableLayout.getRows()) { + preferences.add(new SystemNotificationFilterPreference(this, row, getDriver())); } return preferences; } diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/AbstractNotificationFilterPreference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/AbstractNotificationFilterPreference.java index 82f745ccb0d5..efd71a8e21d9 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/AbstractNotificationFilterPreference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/AbstractNotificationFilterPreference.java @@ -28,9 +28,13 @@ import org.xwiki.test.ui.XWikiWebDriver; import org.xwiki.test.ui.po.BootstrapSwitch; +import static org.xwiki.test.ui.po.BootstrapSwitch.State.OFF; +import static org.xwiki.test.ui.po.BootstrapSwitch.State.ON; + /** * Abstract representation of the notification filter preferences which covers common needs for * {@link SystemNotificationFilterPreference} and {@link CustomNotificationFilterPreference}. + * * @version $Id$ * @since 13.2RC1 */ @@ -38,15 +42,17 @@ public abstract class AbstractNotificationFilterPreference { private AbstractNotificationsSettingsPage parentPage; - private WebElement livetableRow; + private WebElement row; private String filterName; + private List formats = new ArrayList<>(); private BootstrapSwitch enabledSwitch; /** * Default constructor. + * * @param parentPage the page where the settings are displayed. * @param row the row of the livetable for this filter. * @param webDriver the webdriver to initialize the switches. @@ -55,19 +61,39 @@ public AbstractNotificationFilterPreference(AbstractNotificationsSettingsPage pa XWikiWebDriver webDriver) { this.parentPage = parentPage; - this.livetableRow = row; - this.filterName = row.findElement(By.className("name")).getText(); - List formatElements = row.findElement(By.className("notificationFormats")) + this.row = row; + this.filterName = getNameElement(row).getText(); + List formatElements = getFormatsElement(row) .findElements(By.tagName("li")); for (WebElement format : formatElements) { this.formats.add(format.getText()); } - this.enabledSwitch = new BootstrapSwitch( - row.findElement(By.className("isEnabled")).findElement(By.className("bootstrap-switch")), - webDriver - ); + this.enabledSwitch = new BootstrapSwitch(getBootstrapSwitchElement(row), webDriver); } + /** + * @param row the row to get the name from + * @return the {@link WebElement} containing the name of the row + * @since 16.1.0RC1 + */ + protected abstract WebElement getNameElement(WebElement row); + + /** + * @param row the row to get the formats from + * @return the {@link WebElement} containing the formats of the row + * @since 16.1.0RC1 + */ + + protected abstract WebElement getFormatsElement(WebElement row); + + /** + * @param row the row to get the switch from + * @return the {@link WebElement} containing the switch element of the row + * @since 16.1.0RC1 + */ + + protected abstract WebElement getBootstrapSwitchElement(WebElement row); + /** * @return the filter name. */ @@ -85,11 +111,11 @@ public AbstractNotificationsSettingsPage getParentPage() } /** - * @return the livetable row. + * @return the row */ - public WebElement getLivetableRow() + public WebElement getRow() { - return livetableRow; + return row; } /** @@ -105,11 +131,12 @@ public List getFormats() */ public boolean isEnabled() { - return enabledSwitch.getState() == BootstrapSwitch.State.ON; + return enabledSwitch.getState() == ON; } /** * Enable or disable the current filter. + * * @param enabled either or not the filter must be enabled * @throws Exception if the expected state cannot be set */ @@ -119,7 +146,7 @@ public void setEnabled(boolean enabled) throws Exception return; } - this.enabledSwitch.setState(enabled ? BootstrapSwitch.State.ON : BootstrapSwitch.State.OFF); + this.enabledSwitch.setState(enabled ? ON : OFF); this.parentPage.waitForNotificationSuccessMessage("Filter preference saved!"); } } diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/CustomNotificationFilterPreference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/CustomNotificationFilterPreference.java index 036a1384c90c..cf12d60ed4c3 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/CustomNotificationFilterPreference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/CustomNotificationFilterPreference.java @@ -39,6 +39,7 @@ public class CustomNotificationFilterPreference extends AbstractNotificationFilt { /** * Represents the possible actions for such filter. + * * @version $Id$ */ public enum FilterAction @@ -55,10 +56,12 @@ public enum FilterAction } private List eventTypes = new ArrayList<>(); + private FilterAction filterAction; /** * Default constructor. + * * @param parentPage the page where the settings are displayed. * @param row the row of the livetable for this filter. * @param webDriver the webdriver to initialize the switches. @@ -84,6 +87,24 @@ public CustomNotificationFilterPreference(AbstractNotificationsSettingsPage pare } } + @Override + protected WebElement getNameElement(WebElement row) + { + return row.findElement(By.className("name")); + } + + @Override + protected WebElement getFormatsElement(WebElement row) + { + return row.findElement(By.className("notificationFormats")); + } + + @Override + protected WebElement getBootstrapSwitchElement(WebElement row) + { + return row.findElement(By.className("isEnabled")).findElement(By.className("bootstrap-switch")); + } + /** * @return the event types or an empty list in case of all events. */ @@ -97,7 +118,7 @@ public List getEventTypes() */ public String getLocation() { - return this.getLivetableRow().findElement(By.cssSelector("td.name ol")).getAttribute("data-entity"); + return this.getRow().findElement(By.cssSelector("td.name ol")).getAttribute("data-entity"); } /** @@ -113,7 +134,7 @@ public FilterAction getFilterAction() */ public void delete() { - this.getLivetableRow().findElement(By.cssSelector("td.actions a.actiondelete")).click(); + this.getRow().findElement(By.cssSelector("td.actions a.actiondelete")).click(); ConfirmationBox confirmationBox = new ConfirmationBox(); confirmationBox.clickYes(); this.getParentPage().waitForNotificationSuccessMessage("Filter preference deleted!"); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/SystemNotificationFilterPreference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/SystemNotificationFilterPreference.java index 9a209e15f247..d4e78ccafa26 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/SystemNotificationFilterPreference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-test/xwiki-platform-notifications-test-pageobjects/src/main/java/org/xwiki/platform/notifications/test/po/preferences/filters/SystemNotificationFilterPreference.java @@ -32,7 +32,7 @@ */ public class SystemNotificationFilterPreference extends AbstractNotificationFilterPreference { - private String description; + private final String description; /** * Default constructor. @@ -44,7 +44,25 @@ public SystemNotificationFilterPreference(AbstractNotificationsSettingsPage pare XWikiWebDriver webDriver) { super(parentPage, row, webDriver); - this.description = row.findElement(By.className("filterType")).getText(); + this.description = row.findElement(By.cssSelector("td[data-title='Description'] .view")).getText(); + } + + @Override + protected WebElement getNameElement(WebElement row) + { + return row.findElement(By.cssSelector("td[data-title='Name'] .view")); + } + + @Override + protected WebElement getFormatsElement(WebElement row) + { + return row.findElement(By.cssSelector("td[data-title='Formats'] .view")); + } + + @Override + protected WebElement getBootstrapSwitchElement(WebElement row) + { + return row.findElement(By.className("displayer-toggle")).findElement(By.className("bootstrap-switch")); } /** @@ -52,6 +70,6 @@ public SystemNotificationFilterPreference(AbstractNotificationsSettingsPage pare */ public String getDescription() { - return description; + return this.description; } } diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-ui/pom.xml b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-ui/pom.xml index 545fc4c503a9..fcd3bd41601c 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-ui/pom.xml +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-ui/pom.xml @@ -133,6 +133,21 @@ ${project.version} runtime + + + org.xwiki.platform + xwiki-platform-livedata-macro + ${project.version} + runtime + + + org.xwiki.platform + xwiki-platform-livedata-livetable + ${project.version} + runtime + + + org.xwiki.platform xwiki-platform-test-page