Skip to content

Commit

Permalink
[#11572] Add notification banner E2E test (E2E in individual pages) (#…
Browse files Browse the repository at this point in the history
…11749)

* Add notification banner E2E test

* Remove unnecessary new line
  • Loading branch information
NicolasCwy authored Apr 17, 2022
1 parent 7d4873e commit 87ae891
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public void testAll() {
homePage.verifyCourseTabDetails(otherCourseIndex, otherCourse, otherCourseSessions);
homePage.verifyCourseTabDetails(courseIndex, course, courseSessions);

______TS("notification banner is visible");
assertTrue(homePage.isBannerVisible());

______TS("verify response rate");
for (int i = 0; i < courseSessions.length; i++) {
homePage.verifyResponseRate(courseIndex, i, getExpectedResponseRate(courseSessions[i]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public void testAll() {

notificationsPage.verifyNotificationTab(notificationToMarkAsRead, account.getReadNotifications().keySet());

______TS("notification banner is not visible");
assertFalse(notificationsPage.isBannerVisible());

______TS("delete test notifications from database");
for (NotificationAttributes notification : testData.notifications.values()) {
BACKDOOR.deleteNotification(notification.getNotificationId());
Expand Down
67 changes: 67 additions & 0 deletions src/e2e/java/teammates/e2e/cases/NotificationBannerE2ETest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package teammates.e2e.cases;

import java.time.Instant;
import java.util.HashMap;
import java.util.Map;

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.StudentHomePage;

/**
* SUT: The reusable notification banner, which can be displayed across many pages.
* {@link Const.WebPageURIs#STUDENT_HOME_PAGE} is used to test the behaviour of the banner in this case,
* {@link Const.WebPageURIs#STUDENT_PROFILE_PAGE}, {@link Const.WebPageURIs#STUDENT_NOTIFICATIONS_PAGE}
*/
public class NotificationBannerE2ETest extends BaseE2ETestCase {
@Override
protected void prepareTestData() {
testData = loadDataBundle("/NotificationBannerE2ETest.json");
removeAndRestoreDataBundle(testData);
}

@Test
@Override
protected void testAll() {
AccountAttributes account = testData.accounts.get("NotifBanner.student");
NotificationAttributes notification = testData.notifications.get("notification1");
AppUrl studentHomePageUrl = createFrontendUrl(Const.WebPageURIs.STUDENT_HOME_PAGE);
StudentHomePage studentHomePage = loginToPage(studentHomePageUrl, StudentHomePage.class,
account.getGoogleId());

______TS("verify active notification with correct information is shown");
assertTrue(studentHomePage.isBannerVisible());
studentHomePage.verifyBannerContent(notification);

______TS("close notification");
// After user closes a notification banner, it should not appear till user refreshes page
studentHomePage.clickCloseNotificationBannerButton();
assertFalse(studentHomePage.isBannerVisible());
studentHomePage.reloadPage();
assertTrue(studentHomePage.isBannerVisible());

______TS("mark notification as read");
studentHomePage.reloadPage();
assertTrue(studentHomePage.isBannerVisible());

studentHomePage.clickMarkAsReadButton();
studentHomePage.verifyStatusMessage("Notification marked as read.");
assertFalse(studentHomePage.isBannerVisible());

Map<String, Instant> readNotifications = new HashMap<>();
readNotifications.put(notification.getNotificationId(), notification.getEndTime());

account.setReadNotifications(readNotifications);
verifyPresentInDatabase(account);

______TS("delete test notifications from database");
for (NotificationAttributes n : testData.notifications.values()) {
BACKDOOR.deleteNotification(n.getNotificationId());
verifyAbsentInDatabase(n);
}
}
}
4 changes: 4 additions & 0 deletions src/e2e/java/teammates/e2e/cases/StudentHomePageE2ETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void testAll() {
AppUrl url = createFrontendUrl(Const.WebPageURIs.STUDENT_HOME_PAGE);
StudentHomePage homePage = loginToPage(url, StudentHomePage.class, "tm.e2e.SHome.student");

______TS("courses visible to student are shown");
List<String> courseIds = getAllVisibleCourseIds();

for (int i = 0; i < courseIds.size(); i++) {
Expand All @@ -43,6 +44,9 @@ public void testAll() {

homePage.verifyVisibleFeedbackSessionToStudents(feedbackSessionName, i);
}

______TS("notification banner is visible");
assertTrue(homePage.isBannerVisible());
}

private List<String> getAllVisibleCourseIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public void testAll() {

notificationsPage.verifyNotificationTab(notificationToMarkAsRead, account.getReadNotifications().keySet());

______TS("notification banner is not visible");
assertFalse(notificationsPage.isBannerVisible());

______TS("delete test notifications from database");
for (NotificationAttributes notification : testData.notifications.values()) {
BACKDOOR.deleteNotification(notification.getNotificationId());
Expand Down
13 changes: 13 additions & 0 deletions src/e2e/java/teammates/e2e/pageobjects/AppPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.openqa.selenium.support.ui.WebDriverWait;

import teammates.common.datatransfer.FeedbackParticipantType;
import teammates.common.datatransfer.attributes.NotificationAttributes;
import teammates.common.util.TimeHelper;
import teammates.e2e.util.MaximumRetriesExceededException;
import teammates.e2e.util.RetryManager;
Expand Down Expand Up @@ -448,6 +449,18 @@ protected void verifyTableRowValues(WebElement row, String[] expectedRowValues)
}
}

public void verifyBannerContent(NotificationAttributes expected) {
WebElement banner = browser.driver.findElement(By.className("banner"));
String title = banner.findElement(By.tagName("h5")).getText();
String message = banner.findElement(By.className("banner-text")).getAttribute("innerHTML");
assertEquals(expected.getTitle(), title);
assertEquals(expected.getMessage(), message);
}

public boolean isBannerVisible() {
return isElementVisible(By.className("banner"));
}

/**
* Clicks the element and clicks 'Yes' in the follow up dialog box.
* Fails if there is no dialog box.
Expand Down
14 changes: 14 additions & 0 deletions src/e2e/java/teammates/e2e/pageobjects/StudentHomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ public void verifyVisibleFeedbackSessionToStudents(String feedbackSessionName, i
.contains(feedbackSessionName));
}

public void clickCloseNotificationBannerButton() {
WebElement closeNotifButton = browser.driver.findElement(By.id("btn-close-notif"));
waitForElementToBeClickable(closeNotifButton);
click(closeNotifButton);
waitUntilAnimationFinish();
}

public void clickMarkAsReadButton() {
WebElement markNotifAsReadButton = browser.driver.findElement(By.id("btn-mark-as-read"));
waitForElementToBeClickable(markNotifAsReadButton);
click(markNotifAsReadButton);
waitUntilAnimationFinish();
}

}
2 changes: 1 addition & 1 deletion src/e2e/java/teammates/e2e/util/TestDataValidityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private String constructIdRegex(String testPage) {
.replace("Confirmation", "Conf")
.replace("Profile", "Prof")
.replace("Reminders", "Rem")
.replace("Notifications", "Notifs")
.replace("Notification", "Notif")
.replace("IndividualExtension", "Ie");

// Shorten question types
Expand Down
16 changes: 15 additions & 1 deletion src/e2e/resources/data/InstructorHomePageE2ETest.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,19 @@
}
},
"feedbackResponseComments": {},
"profiles": {}
"profiles": {},
"notifications": {
"notification1": {
"notificationId": "notification1",
"startTime": "2011-01-01T00:00:00Z",
"endTime": "2099-01-01T00:00:00Z",
"createdAt": "2011-01-01T00:00:00Z",
"updatedAt": "2011-01-01T00:00:00Z",
"style": "DANGER",
"targetUser": "GENERAL",
"title": "A deprecation note",
"message": "<p>Deprecation happens in three minutes</p>",
"shown": false
}
}
}
86 changes: 86 additions & 0 deletions src/e2e/resources/data/NotificationBannerE2ETest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"accounts": {
"NotifBanner.instructor": {
"googleId": "tm.e2e.NotifBanner.instructor",
"name": "Teammates Test Instructor",
"email": "[email protected]",
"readNotifications": {}
},
"NotifBanner.student": {
"googleId": "tm.e2e.NotifBanner.student",
"name": "Teammates Test Student",
"email": "[email protected]",
"readNotifications": {}
}
},
"courses": {
"typicalCourse1": {
"id": "tm.e2e.NotifBanner.course1",
"name": "Typical Course 1",
"institute": "TEAMMATES Test Institute 1",
"timeZone": "Africa/Johannesburg"
}
},
"instructors": {
"teammates.test.CS2104": {
"googleId": "tm.e2e.NotifBanner.instructor",
"courseId": "tm.e2e.NotifBanner.CS2104",
"name": "Teammates Test Instructor",
"email": "[email protected]",
"role": "Co-owner",
"isDisplayedToStudents": true,
"displayedName": "Instructor",
"privileges": {
"courseLevel": {
"canViewStudentInSections": true,
"canSubmitSessionInSections": true,
"canModifySessionCommentsInSections": true,
"canModifyCourse": true,
"canViewSessionInSections": true,
"canModifySession": true,
"canModifyStudent": true,
"canModifyInstructor": true
},
"sectionLevel": {},
"sessionLevel": {}
}
}
},
"students": {
"SNotifications.student": {
"googleId": "tm.e2e.NotifBanner.student",
"email": "[email protected]",
"course": "tm.e2e.NotifBanner.course1",
"name": "Amy Betsy</option></td></div>'\"",
"comments": "This student's name is Amy Betsy</option></td></div>'\"",
"team": "Team 1</td></div>'\"",
"section": "None"
}
},
"notifications": {
"notification1": {
"notificationId": "notification1",
"startTime": "2011-01-01T00:00:00Z",
"endTime": "2099-01-01T00:00:00Z",
"createdAt": "2011-01-01T00:00:00Z",
"updatedAt": "2011-01-01T00:00:00Z",
"style": "DANGER",
"targetUser": "GENERAL",
"title": "A deprecation note",
"message": "<p>Deprecation happens in three minutes</p>",
"shown": false
},
"notification2": {
"notificationId": "notification2",
"startTime": "2011-01-01T00:00:00Z",
"endTime": "2099-01-01T00:00:00Z",
"createdAt": "2011-01-01T00:00:00Z",
"updatedAt": "2011-01-01T00:00:00Z",
"style": "INFO",
"targetUser": "STUDENT",
"title": "New Update",
"message": "<p>Information on new update</p>",
"shown": false
}
}
}
16 changes: 15 additions & 1 deletion src/e2e/resources/data/StudentHomePageE2ETest.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,19 @@
},
"feedbackResponses": {},
"feedbackResponseComments": {},
"profiles": {}
"profiles": {},
"notifications": {
"notification1": {
"notificationId": "notification1",
"startTime": "2011-01-01T00:00:00Z",
"endTime": "2099-01-01T00:00:00Z",
"createdAt": "2011-01-01T00:00:00Z",
"updatedAt": "2011-01-01T00:00:00Z",
"style": "DANGER",
"targetUser": "GENERAL",
"title": "A deprecation note",
"message": "<p>Deprecation happens in three minutes</p>",
"shown": false
}
}
}
1 change: 1 addition & 0 deletions src/e2e/resources/testng-e2e.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<class name="teammates.e2e.cases.InstructorSessionIndividualExtensionPageE2ETest" />
<class name="teammates.e2e.cases.InstructorStudentListPageE2ETest" />
<class name="teammates.e2e.cases.InstructorStudentRecordsPageE2ETest" />
<class name="teammates.e2e.cases.NotificationBannerE2ETest" />
<class name="teammates.e2e.cases.StudentCourseDetailsPageE2ETest" />
<class name="teammates.e2e.cases.StudentCourseJoinConfirmationPageE2ETest" />
<class name="teammates.e2e.cases.StudentHomePageE2ETest" />
Expand Down

0 comments on commit 87ae891

Please sign in to comment.