Skip to content

Commit

Permalink
XWIKI-18998: Replace the Livetable of the System Filters of the Notif…
Browse files Browse the repository at this point in the history
…ications Administration with a Live Data macro
  • Loading branch information
manuelleduc committed Jan 26, 2024
1 parent 858d0c7 commit b3722f9
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebElement> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
-->

<!--
DisplayerToggle is a special custom displayer that displays actions
concerning the entry.
Actions are links to specific pages, whose url is a property of the entry.
DisplayerToggle is a special custom displayer that displays a toggle element supported by bootstrap-switch.
It is sending a "xwiki:livedata:toggle" even on state change, to be listen for by external scripts.
-->
<template>
<!--
Uses the BaseDisplayer as root element, as it handles for us
all the displayer default behavior
Uses the BaseDisplayer as root element, as it handles for us all the displayer default behavior.
-->
<BaseDisplayer
class="displayer-toggle"
Expand All @@ -36,23 +34,20 @@
:is-empty="false"
:intercept-touch="false"
>

<!-- Provide the Action Viewer widget to the `viewer` slot -->
<template #viewer>
<input
type='checkbox'
class='toggleableFilterPreferenceCheckbox'
ref="input"
/>
<!-- We keep this section hidden as it is only there to be copied when initializing the toggle -->
<!-- We keep this section hidden as it is only there to be copied when initializing the toggle. -->
<span v-show="false">
<XWikiIcon
:icon-descriptor="{name: iconName}"
ref="icon"
@ready="iconReady = true"
/>
</span>

</template>

<!--
Expand All @@ -62,8 +57,6 @@
so that user can't possibly switch to the Editor widget.
-->
<template #editor></template>


</BaseDisplayer>
</template>

Expand All @@ -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`],
Expand Down Expand Up @@ -132,8 +126,4 @@ export default {
}
}
}
</script>

<style scoped>
</style>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@
<artifactId>xwiki-platform-index-tree-test-pageobjects</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Required to test Live Data UIs. -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-livedata-test-pageobjects</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;

Expand Down Expand Up @@ -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<NotificationFilterPreference> getNotificationFilterPreferences()
{
List<NotificationFilterPreference> 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<SystemNotificationFilterPreference> getSystemNotificationFilterPreferences()
{
LiveDataElement notificationSystemFilterPreferencesLiveData =
new LiveDataElement("notificationSystemFilterPreferencesLiveData");
TableLayoutElement tableLayout = notificationSystemFilterPreferencesLiveData.getTableLayout();

List<SystemNotificationFilterPreference> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,31 @@
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
*/
public abstract class AbstractNotificationFilterPreference
{
private AbstractNotificationsSettingsPage parentPage;

private WebElement livetableRow;
private WebElement row;

private String filterName;

private List<String> 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.
Expand All @@ -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<WebElement> formatElements = row.findElement(By.className("notificationFormats"))
this.row = row;
this.filterName = getNameElement(row).getText();
List<WebElement> 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.
*/
Expand All @@ -85,11 +111,11 @@ public AbstractNotificationsSettingsPage getParentPage()
}

/**
* @return the livetable row.
* @return the row
*/
public WebElement getLivetableRow()
public WebElement getRow()
{
return livetableRow;
return row;
}

/**
Expand All @@ -105,11 +131,12 @@ public List<String> 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
*/
Expand All @@ -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!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CustomNotificationFilterPreference extends AbstractNotificationFilt
{
/**
* Represents the possible actions for such filter.
*
* @version $Id$
*/
public enum FilterAction
Expand All @@ -55,10 +56,12 @@ public enum FilterAction
}

private List<String> 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.
Expand All @@ -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.
*/
Expand All @@ -97,7 +118,7 @@ public List<String> 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");
}

/**
Expand All @@ -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!");
Expand Down
Loading

0 comments on commit b3722f9

Please sign in to comment.