use of org.xwiki.platform.notifications.test.po.NotificationsTrayPage in project xwiki-platform by xwiki.
the class NotificationsIT method testNotificationDisplayerClass.
@Test
public void testNotificationDisplayerClass() throws Exception {
// Create the pages and a custom displayer for "update" events
getUtil().login(SUPERADMIN_USER_NAME, SUPERADMIN_PASSWORD);
getUtil().gotoPage(getTestClassName(), "WebHome");
getUtil().createPage(getTestClassName(), "ARandomPageThatShouldBeModified", "Page used for the tests of the NotificationDisplayerClass XObject.", "Test page");
getUtil().createPage(getTestClassName(), "NotificationDisplayerClassTest", "Page used for the tests of the NotificationDisplayerClass XObject.", "Test page 2");
Map<String, String> notificationDisplayerParameters = new HashMap<String, String>() {
{
put("XWiki.Notifications.Code.NotificationDisplayerClass_0_eventType", "update");
put("XWiki.Notifications.Code.NotificationDisplayerClass_0_notificationTemplate", "This is a test template");
}
};
ObjectEditPage editObjects = getUtil().editObjects(getTestClassName(), "NotificationDisplayerClassTest");
editObjects.addObject("XWiki.Notifications.Code.NotificationDisplayerClass");
editObjects.getObjectsOfClass("XWiki.Notifications.Code.NotificationDisplayerClass").get(0).fillFieldsByName(notificationDisplayerParameters);
editObjects.clickSaveAndContinue(true);
// Login as first user, and enable notifications on document updates
getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
NotificationsUserProfilePage p = NotificationsUserProfilePage.gotoPage(FIRST_USER_NAME);
p.getApplication(SYSTEM).setCollapsed(false);
p.setEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT, BootstrapSwitch.State.ON);
// Login as second user and modify ARandomPageThatShouldBeModified
getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
ViewPage viewPage = getUtil().gotoPage(getTestClassName(), "ARandomPageThatShouldBeModified");
viewPage.edit();
WikiEditPage editPage = new WikiEditPage();
editPage.setContent("Something");
editPage.clickSaveAndView(true);
// Login as the first user, ensure that the notification is displayed with a custom template
getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
getUtil().gotoPage(getTestClassName(), "WebHome");
NotificationsTrayPage tray = new NotificationsTrayPage();
assertEquals("This is a test template", tray.getNotificationRawContent(0));
}
use of org.xwiki.platform.notifications.test.po.NotificationsTrayPage in project xwiki-platform by xwiki.
the class NotificationsIT method testCompositeNotifications.
@Test
public void testCompositeNotifications() throws Exception {
NotificationsUserProfilePage p;
NotificationsTrayPage tray;
// Now we enable "create", "update" and "comment" for user 2
getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME);
p.getApplication(SYSTEM).setCollapsed(false);
p.setEventTypeState(SYSTEM, CREATE, ALERT_FORMAT, BootstrapSwitch.State.OFF);
p.setEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT, BootstrapSwitch.State.ON);
p.setEventTypeState(SYSTEM, ADD_COMMENT, ALERT_FORMAT, BootstrapSwitch.State.ON);
getUtil().gotoPage("Main", "WebHome");
tray = new NotificationsTrayPage();
tray.clearAllNotifications();
// Create a page, edit it twice, and finally add a comment
getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
getUtil().createPage(getTestClassName(), "Linux", "Simple content", "Linux as a title");
ViewPage page = getUtil().gotoPage(getTestClassName(), "Linux");
page.edit();
WikiEditPage edit = new WikiEditPage();
edit.setContent("Linux is a part of GNU/Linux");
edit.clickSaveAndContinue(true);
edit.setContent("Linux is a part of GNU/Linux - it's the kernel");
edit.clickSaveAndView(true);
page = getUtil().gotoPage(getTestClassName(), "Linux");
CommentsTab commentsTab = page.openCommentsDocExtraPane();
commentsTab.postComment("Linux is a great OS", true);
// Check that events have been grouped together (see: https://jira.xwiki.org/browse/XWIKI-14114)
getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
getUtil().gotoPage(getTestClassName(), "WebHome");
tray = new NotificationsTrayPage();
assertEquals(2, tray.getNotificationsCount());
assertEquals("Linux as a title", tray.getNotificationPage(0));
assertTrue(tray.getNotificationDescription(0).startsWith("commented by user1"));
assertEquals("Linux as a title", tray.getNotificationPage(1));
assertEquals("update", tray.getNotificationType(1));
assertTrue(tray.getNotificationDescription(1).startsWith("edited by user1"));
tray.clearAllNotifications();
}
use of org.xwiki.platform.notifications.test.po.NotificationsTrayPage 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