Skip to content

Commit

Permalink
migrate instructor notif e2e (#12792)
Browse files Browse the repository at this point in the history
Co-authored-by: Cedric Ong <[email protected]>
  • Loading branch information
dishenggg and cedricongjh authored Feb 24, 2024
1 parent fc0fbd1 commit 8125d53
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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}.
Expand All @@ -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<String> 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<String, Instant> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"accounts": {
"INotifs.instr": {
"id": "00000000-0000-4000-8000-000000000001",
"googleId": "tm.e2e.INotifs.instr",
"name": "Teammates Test",
"email": "[email protected]"
}
},
"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": "<p>This notification is shown to general users</p>",
"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": "<p>This notification is shown to students only</p>",
"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": "<p>This notification is shown to instructors only</p>",
"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": "<p>This notification has been read by the user</p>",
"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": "<p>This notification has expired</p>",
"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"
}
}
}
}

0 comments on commit 8125d53

Please sign in to comment.