diff --git a/src/e2e/java/teammates/e2e/cases/AdminNotificationsPageE2ETest.java b/src/e2e/java/teammates/e2e/cases/AdminNotificationsPageE2ETest.java index cb1d2aa3341..24c3a668257 100644 --- a/src/e2e/java/teammates/e2e/cases/AdminNotificationsPageE2ETest.java +++ b/src/e2e/java/teammates/e2e/cases/AdminNotificationsPageE2ETest.java @@ -3,30 +3,33 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.UUID; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import teammates.common.datatransfer.NotificationStyle; import teammates.common.datatransfer.NotificationTargetUser; -import teammates.common.datatransfer.attributes.NotificationAttributes; import teammates.common.util.AppUrl; import teammates.common.util.Const; import teammates.e2e.pageobjects.AdminNotificationsPage; +import teammates.storage.sqlentity.Notification; +import teammates.ui.output.NotificationData; /** * SUT: {@link Const.WebPageURIs#ADMIN_NOTIFICATIONS_PAGE}. */ public class AdminNotificationsPageE2ETest extends BaseE2ETestCase { - private NotificationAttributes[] notifications = new NotificationAttributes[2]; + private Notification[] notifications = new Notification[2]; @Override protected void prepareTestData() { testData = loadDataBundle("/AdminNotificationsPageE2ETest.json"); removeAndRestoreDataBundle(testData); - - notifications[0] = testData.notifications.get("notification1"); - notifications[1] = testData.notifications.get("notification2"); + sqlTestData = removeAndRestoreSqlDataBundle( + loadSqlDataBundle("/AdminNotificationsPageE2ETest_SqlEntities.json")); + notifications[0] = sqlTestData.notifications.get("notification1"); + notifications[1] = sqlTestData.notifications.get("notification2"); } @Test @@ -40,20 +43,25 @@ public void testAll() { // This is because the page will display all notifications in the database, which is not predictable notificationsPage.verifyNotificationsTableRow(notifications[0]); notificationsPage.verifyNotificationsTableRow(notifications[1]); - verifyPresentInDatabase(notifications[0]); - verifyPresentInDatabase(notifications[1]); + NotificationData notif = BACKDOOR.getNotificationData(notifications[0].getId().toString()); + assertEquals(notif.getNotificationId(), notifications[0].getId().toString()); + assertEquals(notif.getMessage(), notifications[0].getMessage()); + assertEquals(notif.getTitle(), notifications[0].getTitle()); + notif = BACKDOOR.getNotificationData(notifications[1].getId().toString()); + assertEquals(notif.getNotificationId(), notifications[1].getId().toString()); + assertEquals(notif.getMessage(), notifications[1].getMessage()); + assertEquals(notif.getTitle(), notifications[1].getTitle()); ______TS("add new notification"); int currentYear = LocalDate.now().getYear(); - NotificationAttributes newNotification = NotificationAttributes - .builder("placeholder-notif-id") - .withStartTime(LocalDateTime.of(currentYear + 8, 1, 2, 12, 0).atZone(ZoneId.of("UTC")).toInstant()) - .withEndTime(LocalDateTime.of(currentYear + 8, 1, 3, 12, 0).atZone(ZoneId.of("UTC")).toInstant()) - .withStyle(NotificationStyle.SUCCESS) - .withTargetUser(NotificationTargetUser.GENERAL) - .withTitle("E2E test notification 1") - .withMessage("
E2E test notification message
") - .build(); + Notification newNotification = new Notification( + LocalDateTime.of(currentYear + 5, 2, 2, 12, 0).atZone(ZoneId.of("UTC")).toInstant(), + LocalDateTime.of(currentYear + 5, 2, 3, 12, 0).atZone(ZoneId.of("UTC")).toInstant(), + NotificationStyle.INFO, + NotificationTargetUser.STUDENT, + "New E2E test notification 1", + "New E2E test notification message
" + ); notificationsPage.addNotification(newNotification); notificationsPage.verifyStatusMessage("Notification created successfully."); @@ -61,11 +69,14 @@ public void testAll() { // Replace placeholder ID with actual ID of created notification notificationsPage.sortNotificationsTableByDescendingCreateTime(); String newestNotificationId = notificationsPage.getFirstRowNotificationId(); - newNotification.setNotificationId(newestNotificationId); + newNotification.setId(UUID.fromString(newestNotificationId)); // Checks that notification is in the database first // so that newNotification is updated with the created time before checking table row - verifyPresentInDatabase(newNotification); + notif = BACKDOOR.getNotificationData(newestNotificationId); + assertEquals(notif.getNotificationId(), newestNotificationId); + assertEquals(notif.getMessage(), newNotification.getMessage()); + assertEquals(notif.getTitle(), newNotification.getTitle()); notificationsPage.verifyNotificationsTableRow(newNotification); ______TS("edit notification"); @@ -87,14 +98,14 @@ public void testAll() { ______TS("delete notification"); notificationsPage.deleteNotification(newNotification); notificationsPage.verifyStatusMessage("Notification has been deleted."); - verifyAbsentInDatabase(newNotification); - + notif = BACKDOOR.getNotificationData(newestNotificationId); + assertNull(notif); } @AfterClass public void classTeardown() { - for (NotificationAttributes notification : testData.notifications.values()) { - BACKDOOR.deleteNotification(notification.getNotificationId()); + for (Notification notification : sqlTestData.notifications.values()) { + BACKDOOR.deleteNotification(notification.getId().toString()); } } diff --git a/src/e2e/java/teammates/e2e/pageobjects/AdminNotificationsPage.java b/src/e2e/java/teammates/e2e/pageobjects/AdminNotificationsPage.java index 9b7bbd1f01a..ef01c2b70fa 100644 --- a/src/e2e/java/teammates/e2e/pageobjects/AdminNotificationsPage.java +++ b/src/e2e/java/teammates/e2e/pageobjects/AdminNotificationsPage.java @@ -11,7 +11,7 @@ import teammates.common.datatransfer.NotificationStyle; import teammates.common.datatransfer.NotificationTargetUser; -import teammates.common.datatransfer.attributes.NotificationAttributes; +import teammates.storage.sqlentity.Notification; /** * Page Object Model for the admin notifications page. @@ -66,12 +66,12 @@ protected boolean containsExpectedPageContents() { return getPageSource().contains("Notifications"); } - public void verifyNotificationsTableRow(NotificationAttributes notification) { - WebElement notificationRow = notificationsTable.findElement(By.id(notification.getNotificationId())); + public void verifyNotificationsTableRow(Notification notification) { + WebElement notificationRow = notificationsTable.findElement(By.id(notification.getId().toString())); verifyTableRowValues(notificationRow, getNotificationTableDisplayDetails(notification)); } - public void addNotification(NotificationAttributes notification) { + public void addNotification(Notification notification) { clickAddNotificationButton(); waitForElementPresence(By.id("btn-create-notification")); @@ -81,8 +81,8 @@ public void addNotification(NotificationAttributes notification) { waitForPageToLoad(true); } - public void editNotification(NotificationAttributes notification) { - WebElement notificationRow = notificationsTable.findElement(By.id(notification.getNotificationId())); + public void editNotification(Notification notification) { + WebElement notificationRow = notificationsTable.findElement(By.id(notification.getId().toString())); WebElement editButton = notificationRow.findElement(By.className("btn-light")); editButton.click(); waitForElementPresence(By.id("btn-edit-notification")); @@ -93,8 +93,8 @@ public void editNotification(NotificationAttributes notification) { waitForPageToLoad(true); } - public void deleteNotification(NotificationAttributes notification) { - WebElement notificationRow = notificationsTable.findElement(By.id(notification.getNotificationId())); + public void deleteNotification(Notification notification) { + WebElement notificationRow = notificationsTable.findElement(By.id(notification.getId().toString())); WebElement deleteButton = notificationRow.findElement(By.className("btn-danger")); deleteButton.click(); @@ -102,7 +102,7 @@ public void deleteNotification(NotificationAttributes notification) { waitForPageToLoad(true); } - public void fillNotificationForm(NotificationAttributes notification) { + public void fillNotificationForm(Notification notification) { selectDropdownOptionByText(notificationTargetUserDropdown, getTargetUserText(notification.getTargetUser())); selectDropdownOptionByText(notificationStyleDropdown, getNotificationStyle(notification.getStyle())); fillTextBox(notificationTitleTextBox, notification.getTitle()); @@ -153,14 +153,13 @@ private void setDateTime(WebElement dateBox, WebElement timeBox, Instant startIn selectDropdownOptionByText(timeBox.findElement(By.tagName("select")), getInputTimeString(startInstant)); } - private String[] getNotificationTableDisplayDetails(NotificationAttributes notification) { + private String[] getNotificationTableDisplayDetails(Notification notification) { return new String[] { notification.getTitle(), getTableDisplayDateString(notification.getStartTime()), getTableDisplayDateString(notification.getEndTime()), notification.getTargetUser().toString(), getNotificationStyle(notification.getStyle()), - getTableDisplayDateString(notification.getCreatedAt()), }; } diff --git a/src/e2e/resources/data/AdminNotificationsPageE2ETest_SqlEntities.json b/src/e2e/resources/data/AdminNotificationsPageE2ETest_SqlEntities.json new file mode 100644 index 00000000000..ddbaf5245a6 --- /dev/null +++ b/src/e2e/resources/data/AdminNotificationsPageE2ETest_SqlEntities.json @@ -0,0 +1,26 @@ +{ + "notifications": { + "notification1": { + "id": "00000000-0000-4000-8000-000000001103", + "startTime": "2011-01-01T00:00:00Z", + "endTime": "2099-01-01T00:00:00Z", + "createdAt": "2011-01-01T00:00:00Z", + "style": "DANGER", + "targetUser": "GENERAL", + "title": "A deprecation note", + "message": "Deprecation happens in three minutes
", + "shown": false + }, + "notification2": { + "id": "00000000-0000-4000-8000-000000001103", + "startTime": "2011-02-02T00:00:00Z", + "endTime": "2099-02-02T00:00:00Z", + "createdAt": "2011-01-01T00:00:00Z", + "style": "SUCCESS", + "targetUser": "STUDENT", + "title": "A note for update", + "message": "Exciting features
", + "shown": false + } + } +} diff --git a/src/main/java/teammates/ui/output/NotificationData.java b/src/main/java/teammates/ui/output/NotificationData.java index 789e785274d..a2c29fcdd3b 100644 --- a/src/main/java/teammates/ui/output/NotificationData.java +++ b/src/main/java/teammates/ui/output/NotificationData.java @@ -1,5 +1,7 @@ package teammates.ui.output; +import org.threeten.bp.Instant; + import teammates.common.datatransfer.NotificationStyle; import teammates.common.datatransfer.NotificationTargetUser; import teammates.common.datatransfer.attributes.NotificationAttributes; @@ -36,7 +38,8 @@ public NotificationData(Notification notification) { this.notificationId = notification.getId().toString(); this.startTimestamp = notification.getStartTime().toEpochMilli(); this.endTimestamp = notification.getEndTime().toEpochMilli(); - this.createdAt = notification.getCreatedAt().toEpochMilli(); + this.createdAt = notification.getCreatedAt() == null + ? Instant.now().toEpochMilli() : notification.getCreatedAt().toEpochMilli(); this.style = notification.getStyle(); this.targetUser = notification.getTargetUser(); this.title = notification.getTitle();