Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12048] Migrate instructor notification page e2e test #12792

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "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": "<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"
}
}
}
}
Loading