Search in sources :

Example 6 with NotificationsUserProfilePage

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());
}
Also used : NotificationsUserProfilePage(org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage) NotificationsTrayPage(org.xwiki.platform.notifications.test.po.NotificationsTrayPage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

NotificationsUserProfilePage (org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage)6 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)5 Test (org.junit.Test)5 AbstractTest (org.xwiki.test.ui.AbstractTest)5 NotificationsTrayPage (org.xwiki.platform.notifications.test.po.NotificationsTrayPage)3 ViewPage (org.xwiki.test.ui.po.ViewPage)2 WikiEditPage (org.xwiki.test.ui.po.editor.WikiEditPage)2 HashMap (java.util.HashMap)1 MimeMessage (javax.mail.internet.MimeMessage)1 Before (org.junit.Before)1 Email (org.simplejavamail.email.Email)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 ApplicationPreferences (org.xwiki.platform.notifications.test.po.preferences.ApplicationPreferences)1 SchedulerHomePage (org.xwiki.scheduler.test.po.SchedulerHomePage)1 CommentsTab (org.xwiki.test.ui.po.CommentsTab)1 ObjectEditPage (org.xwiki.test.ui.po.editor.ObjectEditPage)1 ProfileEditPage (org.xwiki.user.test.po.ProfileEditPage)1