use of org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage in project xwiki-platform by xwiki.
the class NotificationsIT method testNotifications.
@Test
public void testNotifications() throws Exception {
NotificationsUserProfilePage p;
NotificationsTrayPage tray;
// The user 1 creates a new page, the user 2 shouldn’t receive any notification
getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
getUtil().createPage(getTestClassName(), "WebHome", "Content from " + FIRST_USER_NAME, "Page title");
getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
getUtil().gotoPage(getTestClassName(), "WebHome");
tray = new NotificationsTrayPage();
assertFalse(tray.areNotificationsAvailable());
// The user 2 will now enable his notifications for new pages
p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME);
p.getApplication(SYSTEM).setCollapsed(false);
p.setEventTypeState(SYSTEM, CREATE, ALERT_FORMAT, BootstrapSwitch.State.ON);
// Yes we wait on a timer, but it is to be sure the following events will be stored AFTER the settings have been
// changed.
Thread.sleep(1000);
// We create a lot of pages in order to test the notification badge
getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
for (int i = 1; i < PAGES_TOP_CREATION_COUNT; i++) {
getUtil().createPage(getTestClassName(), "Page" + i, "Simple content", "Simple title");
}
getUtil().createPage(getTestClassName(), "DTP", "Deletion test page", "Deletion test content");
// Check that the badge is showing «20+»
getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
getUtil().gotoPage(getTestClassName(), "WebHome");
tray = new NotificationsTrayPage();
assertEquals(Integer.MAX_VALUE, tray.getNotificationsCount());
// Ensure that the notification list is displaying the correct amount of unread notifications
// (max 10 notifications by default)
assertEquals(10, tray.getUnreadNotificationsCount());
assertEquals(0, tray.getReadNotificationsCount());
tray.markAsRead(0);
assertEquals(9, tray.getUnreadNotificationsCount());
assertEquals(1, tray.getReadNotificationsCount());
// Ensure that a notification has a correct type
assertEquals("create", tray.getNotificationType(0));
// Reset the notifications count of the user 2
tray.clearAllNotifications();
assertEquals(0, tray.getNotificationsCount());
assertFalse(tray.areNotificationsAvailable());
// The user 2 will get notifications only for pages deletions
p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME);
p.getApplication(SYSTEM).setCollapsed(false);
p.setEventTypeState(SYSTEM, CREATE, ALERT_FORMAT, BootstrapSwitch.State.OFF);
p.setEventTypeState(SYSTEM, DELETE, ALERT_FORMAT, BootstrapSwitch.State.ON);
// Yes we wait on a timer, but it is to be sure the following events will be stored AFTER the settings have been
// changed.
Thread.sleep(1000);
// Delete the "Deletion test page" and test the notification
getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
getUtil().deletePage(getTestClassName(), "DTP");
getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
getUtil().gotoPage(getTestClassName(), "WebHome");
tray = new NotificationsTrayPage();
assertEquals(1, tray.getNotificationsCount());
}
Aggregations