From 8125d5353307b0d225e90fc671c3f7420e8602a4 Mon Sep 17 00:00:00 2001 From: DS Date: Sat, 24 Feb 2024 21:08:39 +0800 Subject: [PATCH] migrate instructor notif e2e (#12792) Co-authored-by: Cedric Ong <67156011+cedricongjh@users.noreply.github.com> --- .../InstructorNotificationsPageE2ETest.java | 49 +++++++------ ...rNotificationsPageE2ETest_SqlEntities.json | 73 +++++++++++++++++++ 2 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 src/e2e/resources/data/InstructorNotificationsPageE2ETest_SqlEntities.json diff --git a/src/e2e/java/teammates/e2e/cases/InstructorNotificationsPageE2ETest.java b/src/e2e/java/teammates/e2e/cases/InstructorNotificationsPageE2ETest.java index 8de2b045e71..e153f6e8f71 100644 --- a/src/e2e/java/teammates/e2e/cases/InstructorNotificationsPageE2ETest.java +++ b/src/e2e/java/teammates/e2e/cases/InstructorNotificationsPageE2ETest.java @@ -1,17 +1,19 @@ package teammates.e2e.cases; -import java.time.Instant; -import java.util.HashMap; -import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; -import teammates.common.datatransfer.attributes.AccountAttributes; import teammates.common.datatransfer.attributes.NotificationAttributes; import teammates.common.util.AppUrl; import teammates.common.util.Const; import teammates.e2e.pageobjects.InstructorNotificationsPage; +import teammates.storage.sqlentity.Account; +import teammates.storage.sqlentity.Notification; +import teammates.ui.output.AccountData; /** * SUT: {@link Const.WebPageURIs#INSTRUCTOR_NOTIFICATIONS_PAGE}. @@ -22,43 +24,48 @@ public class InstructorNotificationsPageE2ETest extends BaseE2ETestCase { protected void prepareTestData() { testData = loadDataBundle("/InstructorNotificationsPageE2ETest.json"); removeAndRestoreDataBundle(testData); + sqlTestData = removeAndRestoreSqlDataBundle( + loadSqlDataBundle("/InstructorNotificationsPageE2ETest_SqlEntities.json")); } @Test @Override public void testAll() { - AccountAttributes account = testData.accounts.get("INotifs.instr"); + Account account = sqlTestData.accounts.get("INotifs.instr"); AppUrl notificationsPageUrl = createFrontendUrl(Const.WebPageURIs.INSTRUCTOR_NOTIFICATIONS_PAGE); InstructorNotificationsPage notificationsPage = loginToPage(notificationsPageUrl, InstructorNotificationsPage.class, account.getGoogleId()); ______TS("verify that only active notifications with correct target user are shown"); - NotificationAttributes[] notShownNotifications = { - testData.notifications.get("notification2"), - testData.notifications.get("expiredNotification1"), + Notification[] notShownNotifications = { + sqlTestData.notifications.get("notification2"), + sqlTestData.notifications.get("expiredNotification1"), }; - NotificationAttributes[] shownNotifications = { - testData.notifications.get("notification1"), - testData.notifications.get("notification3"), - testData.notifications.get("notification4"), + Notification[] shownNotifications = { + sqlTestData.notifications.get("notification1"), + sqlTestData.notifications.get("notification3"), + sqlTestData.notifications.get("notification4"), }; + Notification[] readNotifications = { + sqlTestData.notifications.get("notification4"), + }; + + Set readNotificationsIds = Stream.of(readNotifications) + .map(readNotification -> readNotification.getId().toString()) + .collect(Collectors.toSet()); + notificationsPage.verifyNotShownNotifications(notShownNotifications); - notificationsPage.verifyShownNotifications(shownNotifications, account.getReadNotifications().keySet()); + notificationsPage.verifyShownNotifications(shownNotifications, readNotificationsIds); ______TS("mark notification as read"); - NotificationAttributes notificationToMarkAsRead = testData.notifications.get("notification3"); + Notification notificationToMarkAsRead = sqlTestData.notifications.get("notification3"); notificationsPage.markNotificationAsRead(notificationToMarkAsRead); notificationsPage.verifyStatusMessage("Notification marked as read."); // Verify that account's readNotifications attribute is updated - Map readNotifications = new HashMap<>(); - readNotifications.put(notificationToMarkAsRead.getNotificationId(), notificationToMarkAsRead.getEndTime()); - readNotifications.putAll(account.getReadNotifications()); - account.setReadNotifications(readNotifications); - verifyPresentInDatabase(account); - - notificationsPage.verifyNotificationTab(notificationToMarkAsRead, account.getReadNotifications().keySet()); + AccountData accountFromDb = BACKDOOR.getAccountData(account.getGoogleId()); + assertTrue(accountFromDb.getReadNotifications().containsKey(notificationToMarkAsRead.getId().toString())); ______TS("notification banner is not visible"); assertFalse(notificationsPage.isBannerVisible()); diff --git a/src/e2e/resources/data/InstructorNotificationsPageE2ETest_SqlEntities.json b/src/e2e/resources/data/InstructorNotificationsPageE2ETest_SqlEntities.json new file mode 100644 index 00000000000..bff18c00791 --- /dev/null +++ b/src/e2e/resources/data/InstructorNotificationsPageE2ETest_SqlEntities.json @@ -0,0 +1,73 @@ +{ + "accounts": { + "INotifs.instr": { + "id": "00000000-0000-4000-8000-000000000001", + "googleId": "tm.e2e.INotifs.instr", + "name": "Teammates Test", + "email": "INotifs.instr@gmail.tmt" + } + }, + "notifications": { + "notification1": { + "id": "00000000-0000-4000-8000-000000001101", + "startTime": "2011-01-01T00:00:00Z", + "endTime": "2099-01-01T00:00:00Z", + "style": "DANGER", + "targetUser": "GENERAL", + "title": "INotifs.notification1", + "message": "

This notification is shown to general users

", + "shown": false + }, + "notification2": { + "id": "00000000-0000-4000-8000-000000001102", + "startTime": "2011-02-02T00:00:00Z", + "endTime": "2099-02-02T00:00:00Z", + "style": "SUCCESS", + "targetUser": "STUDENT", + "title": "INotifs.notification2", + "message": "

This notification is shown to students only

", + "shown": false + }, + "notification3": { + "id": "00000000-0000-4000-8000-000000001103", + "startTime": "2011-03-03T00:00:00Z", + "endTime": "2099-03-03T00:00:00Z", + "style": "SUCCESS", + "targetUser": "INSTRUCTOR", + "title": "INotifs.notification3", + "message": "

This notification is shown to instructors only

", + "shown": false + }, + "notification4": { + "id": "00000000-0000-4000-8000-000000001104", + "startTime": "2011-04-04T00:00:00Z", + "endTime": "2099-04-04T00:00:00Z", + "style": "WARNING", + "targetUser": "GENERAL", + "title": "INotifs.notification4", + "message": "

This notification has been read by the user

", + "shown": false + }, + "expiredNotification1": { + "id": "00000000-0000-4000-8000-000000001105", + "startTime": "2011-01-01T00:00:00Z", + "endTime": "2011-02-02T00:00:00Z", + "style": "DANGER", + "targetUser": "GENERAL", + "title": "INotifs.expiredNotification1", + "message": "

This notification has expired

", + "shown": false + } + }, + "readNotifications": { + "notification4INotifs.instr": { + "id": "00000000-0000-4000-8000-000000002100", + "account": { + "id": "00000000-0000-4000-8000-000000000001" + }, + "notification": { + "id": "00000000-0000-4000-8000-000000001104" + } + } + } +}