Skip to content

Commit

Permalink
XWIKI-21848: Migrate NotificationFilterPreferenceLivetableResults to …
Browse files Browse the repository at this point in the history
…a Live Data source

  * Fix integration tests
  • Loading branch information
surli committed Mar 27, 2024
1 parent 3f7ba76 commit 1783fd9
Showing 1 changed file with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.xwiki.index.tree.test.po.DocumentTreeElement;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.SpaceReference;
import org.xwiki.model.reference.WikiReference;
import org.xwiki.platform.notifications.test.po.AbstractNotificationsSettingsPage;
import org.xwiki.platform.notifications.test.po.NotificationsAdministrationPage;
import org.xwiki.platform.notifications.test.po.NotificationsTrayPage;
Expand Down Expand Up @@ -103,7 +104,7 @@ void setup(TestUtils testUtils)
@AfterEach
void tearDown(TestUtils testUtils)
{
//testUtils.deletePage("XWiki", FIRST_USER_NAME);
testUtils.deletePage("XWiki", FIRST_USER_NAME);
}

@Test
Expand Down Expand Up @@ -254,7 +255,7 @@ void filterAndWatchedPage(TestUtils testUtils, TestReference testReference) thro
NotificationsUserProfilePage.gotoPage(FIRST_USER_NAME);

// Create a page
testUtils.createPage(testReference.getLastSpaceReference().getName(), testReference.getName(), "", "");
testUtils.createPage(testReference, "", "");
NotificationsTrayPage trayPage = new NotificationsTrayPage();
trayPage.showNotificationTray();

Expand All @@ -272,18 +273,20 @@ void filterAndWatchedPage(TestUtils testUtils, TestReference testReference) thro
customPrefLiveData.getCustomNotificationFilterPreferences();
assertEquals(1, preferences.size());

String pageName =
testUtils.serializeReference(testReference.removeParent(new WikiReference("xwiki")));

// Filter 0
assertEquals("Page only", preferences.get(0).getScope());
assertEquals(testReference.getLastSpaceReference().getName() + ".WebHome",
preferences.get(0).getLocation());
assertEquals(pageName, preferences.get(0).getLocation());
assertEquals(CustomNotificationFilterPreference.FilterAction.NOTIFY_EVENT,
preferences.get(0).getFilterAction());
assertTrue(preferences.get(0).getEventTypes().isEmpty());
assertTrue(preferences.get(0).getFormats().containsAll(List.of("Email", "Alert")));
assertTrue(preferences.get(0).isEnabled());

// back to the page
testUtils.gotoPage(testReference.getLastSpaceReference().getName(), testReference.getName());
testUtils.gotoPage(testReference);
trayPage = new NotificationsTrayPage();
// Unwatch the page
trayPage.setPageOnlyWatchedState(false);
Expand All @@ -300,7 +303,7 @@ void filterAndWatchedPage(TestUtils testUtils, TestReference testReference) thro
assertTrue(preferences.isEmpty());

// back to the page
testUtils.gotoPage(testReference.getLastSpaceReference().getName(), testReference.getName());
testUtils.gotoPage(testReference);
trayPage = new NotificationsTrayPage();
trayPage.showNotificationTray();

Expand All @@ -318,16 +321,15 @@ void filterAndWatchedPage(TestUtils testUtils, TestReference testReference) thro

// Filter 1
assertEquals("Page and children", preferences.get(0).getScope());
assertEquals(testReference.getLastSpaceReference().getName() + ".WebHome",
preferences.get(0).getLocation());
assertEquals(pageName, preferences.get(0).getLocation());
assertEquals(CustomNotificationFilterPreference.FilterAction.NOTIFY_EVENT,
preferences.get(0).getFilterAction());
assertTrue(preferences.get(0).getEventTypes().isEmpty());
assertTrue(preferences.get(0).getFormats().containsAll(List.of("Email", "Alert")));
assertTrue(preferences.get(0).isEnabled());

// back to the page
testUtils.gotoPage(testReference.getLastSpaceReference().getName(), testReference.getName());
testUtils.gotoPage(testReference);
trayPage = new NotificationsTrayPage();
trayPage.showNotificationTray();

Expand All @@ -346,27 +348,26 @@ void filterAndWatchedPage(TestUtils testUtils, TestReference testReference) thro
assertEquals(2, preferences.size());

// Filter 2
assertEquals("Page only", preferences.get(1).getScope());
assertEquals(testReference.getLastSpaceReference().getName() + "." + testReference.getName(),
preferences.get(1).getLocation());
assertEquals("Page only", preferences.get(0).getScope());
assertEquals(pageName, preferences.get(0).getLocation());
assertEquals(CustomNotificationFilterPreference.FilterAction.IGNORE_EVENT,
preferences.get(1).getFilterAction());
assertTrue(preferences.get(1).getEventTypes().isEmpty());
assertTrue(preferences.get(1).getFormats().containsAll(List.of("Email", "Alert")));
assertTrue(preferences.get(1).isEnabled());
preferences.get(0).getFilterAction());
assertTrue(preferences.get(0).getEventTypes().isEmpty());
assertTrue(preferences.get(0).getFormats().containsAll(List.of("Email", "Alert")));
assertTrue(preferences.get(0).isEnabled());

// Disable filter 2
preferences.get(1).setEnabled(false);
preferences.get(0).setEnabled(false);
// Refresh the page
notificationsUserProfilePage = NotificationsUserProfilePage.gotoPage(FIRST_USER_NAME);
customPrefLiveData =
notificationsUserProfilePage.getCustomNotificationFilterPreferencesLiveData();
preferences = customPrefLiveData.getCustomNotificationFilterPreferences();
// Verify the change have been saved
assertFalse(preferences.get(1).isEnabled());
assertFalse(preferences.get(0).isEnabled());

// Go back to the page to check how it impacts the watch
testUtils.gotoPage(testReference.getLastSpaceReference().getName(), testReference.getName());
testUtils.gotoPage(testReference);
trayPage = new NotificationsTrayPage();
trayPage.showNotificationTray();
// Verify the whole status
Expand All @@ -384,7 +385,7 @@ void filterAndWatchedPage(TestUtils testUtils, TestReference testReference) thro
preferences.get(0).delete();

// Verify it's all like the beginning
testUtils.gotoPage(testReference.getLastSpaceReference().getName(), testReference.getName());
testUtils.gotoPage(testReference);
trayPage = new NotificationsTrayPage();
trayPage.showNotificationTray();
assertFalse(trayPage.isPageOnlyWatched());
Expand All @@ -399,7 +400,7 @@ void filterAndWatchedPage(TestUtils testUtils, TestReference testReference) thro
assertTrue(preferences.isEmpty());
} finally {
// Clean up
testUtils.rest().deletePage(testReference.getLastSpaceReference().getName(), testReference.getName());
testUtils.rest().delete(testReference);

NotificationsUserProfilePage p = NotificationsUserProfilePage.gotoPage(FIRST_USER_NAME);
CustomNotificationFilterPreferencesLiveDataElement customPrefLiveData =
Expand Down Expand Up @@ -585,7 +586,7 @@ void globalAndOtherUserSettings(TestUtils testUtils, TestReference testReference
*/
@Test
@Order(5)
void customFiltersAndLiveData(TestUtils testUtils, TestReference testReference) throws Exception
void customFiltersAndLiveData(TestUtils testUtils) throws Exception
{
// Create pages for the filter locations
SpaceReference lastSpaceReference = new SpaceReference("xwiki", NotificationsSettingsIT.class.getSimpleName());
Expand Down Expand Up @@ -759,13 +760,14 @@ void customFiltersAndLiveData(TestUtils testUtils, TestReference testReference)
NotificationsUserProfilePage.gotoPage(secondUserUsername);
notificationsUserProfilePage.setAutoWatchMode(AbstractNotificationsSettingsPage.AutowatchMode.NEW);

SpaceReference newPagesSpaceRef = new SpaceReference("NewPages", lastSpaceReference);
// Create multiple pages
for (int i = 0; i < 15; i++) {
DocumentReference pageRef = new DocumentReference("Page_" + i, testReference.getLastSpaceReference());
DocumentReference pageRef = new DocumentReference("Page_" + i, newPagesSpaceRef);
testUtils.rest().savePage(pageRef, "Content of page " + i, "Title of page " + i );
}
String pageSpaceName =
NotificationsSettingsIT.class.getSimpleName() + "." + testReference.getLastSpaceReference().getName();
NotificationsSettingsIT.class.getSimpleName() + "." + newPagesSpaceRef.getName();

notificationsUserProfilePage =
NotificationsUserProfilePage.gotoPage(secondUserUsername);
Expand All @@ -786,7 +788,7 @@ void customFiltersAndLiveData(TestUtils testUtils, TestReference testReference)
assertEquals("XWiki." + FIRST_USER_NAME, filterPreference.getLocation());

customPrefLiveData.clearAllFilters();
customPrefLiveData.filterLocation(testReference.getLastSpaceReference().getName());
customPrefLiveData.filterLocation(newPagesSpaceRef.getName());
// Click twice to order descending
customPrefLiveData.sortLocation();
customPrefLiveData.sortLocation();
Expand Down

0 comments on commit 1783fd9

Please sign in to comment.