From 3bdccddcc2060aa32fff881fa995bef2dd6b5bf3 Mon Sep 17 00:00:00 2001 From: Dominic Berzin Date: Sun, 25 Feb 2024 11:31:01 +0800 Subject: [PATCH] Fix e2e tests and lint fix reset google id test fix e2e tests fix e2e tests fix tests remove double click fix unknown symbol add toast check change toast verification message remove toast check --- .../e2e/cases/AdminSearchPageE2ETest.java | 74 ++++++++----------- .../e2e/pageobjects/AdminSearchPage.java | 45 +++++++++-- .../AdminSearchPageE2ETest_SQLEntities.json | 11 +-- .../sqllogic/api/SqlEmailGenerator.java | 8 +- .../sqllogic/core/DataBundleLogic.java | 12 --- .../test/BaseTestCaseWithDatabaseAccess.java | 2 +- 6 files changed, 81 insertions(+), 71 deletions(-) diff --git a/src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java b/src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java index 71f70e58548..42a0c72197b 100644 --- a/src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java +++ b/src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java @@ -11,9 +11,9 @@ import teammates.e2e.util.TestProperties; import teammates.storage.sqlentity.AccountRequest; import teammates.storage.sqlentity.Course; +import teammates.storage.sqlentity.FeedbackSession; import teammates.storage.sqlentity.Instructor; import teammates.storage.sqlentity.Student; -import teammates.storage.sqlentity.FeedbackSession; /** * SUT: {@link Const.WebPageURIs#ADMIN_SEARCH_PAGE}. @@ -26,10 +26,9 @@ protected void prepareTestData() { return; } testData = loadDataBundle("/AdminSearchPageE2ETest.json"); - sqlTestData = - removeAndRestoreSqlDataBundle( + sqlTestData = removeAndRestoreSqlDataBundle( loadSqlDataBundle("/AdminSearchPageE2ETest_SQLEntities.json")); - putDocumentsSQL(sqlTestData); + putDocumentsSql(sqlTestData); removeAndRestoreDataBundle(testData); putDocuments(testData); } @@ -61,18 +60,14 @@ public void testAll() { studentHomePageLink); searchPage.verifyStudentExpandedLinks(student, numExpandedRows); - // ______TS("Typical case: Reset student google id"); - // searchPage.resetStudentGoogleId(student); - // student.setGoogleId(null); - // studentManageAccountLink = getExpectedStudentManageAccountLink(student); - // studentHomePageLink = getExpectedStudentHomePageLink(student); - // searchPage.verifyStudentRowContent(student, course, studentDetails, studentManageAccountLink, - // studentHomePageLink); + ______TS("Typical case: Reset student google id"); + searchPage.resetStudentGoogleId(student); + student.setGoogleId(null); + searchPage.verifyStudentRowContentAfterReset(student, course); ______TS("Typical case: Regenerate registration key for a course student"); searchPage.clickExpandStudentLinks(); String originalJoinLink = searchPage.getStudentJoinLink(student); - searchPage.regenerateStudentKey(student); searchPage.verifyRegenerateStudentKey(student, originalJoinLink); searchPage.waitForPageToLoad(); @@ -88,18 +83,13 @@ public void testAll() { instructorHomePageLink); searchPage.verifyInstructorExpandedLinks(instructor); - // ______TS("Typical case: Reset instructor google id"); - // searchPage.resetInstructorGoogleId(instructor); - // instructor.setGoogleId(null); - // instructorManageAccountLink = getExpectedInstructorManageAccountLink(instructor); - // instructorHomePageLink = getExpectedInstructorHomePageLink(instructor); - // searchPage.verifyInstructorRowContent(instructor, course, instructorManageAccountLink, - // instructorHomePageLink); + ______TS("Typical case: Reset instructor google id"); + searchPage.resetInstructorGoogleId(instructor); + searchPage.verifyInstructorRowContentAfterReset(instructor, course); ______TS("Typical case: Regenerate registration key for an instructor"); searchPage.clickExpandInstructorLinks(); originalJoinLink = searchPage.getInstructorJoinLink(instructor); - searchPage.regenerateInstructorKey(instructor); searchPage.verifyRegenerateInstructorKey(instructor, originalJoinLink); searchPage.waitForPageToLoad(); @@ -112,27 +102,25 @@ public void testAll() { searchPage.verifyAccountRequestRowContent(accountRequest); searchPage.verifyAccountRequestExpandedLinks(accountRequest); - // ______TS("Typical case: Search common search key"); - // searchPage.clearSearchBox(); - // searchContent = "Course1"; - // searchPage.inputSearchContent(searchContent); - // searchPage.clickSearchButton(); - // searchPage.verifyStudentRowContent(student, course, studentDetails, studentManageAccountLink, - // studentHomePageLink); - // searchPage.verifyInstructorRowContent(instructor, course, instructorManageAccountLink, - // instructorHomePageLink); - // searchPage.verifyAccountRequestRowContent(accountRequest); - - // ______TS("Typical case: Expand and collapse links"); - // searchPage.verifyLinkExpansionButtons(student, instructor, accountRequest); - - // ______TS("Typical case: Reset account request successful"); - // searchContent = "unregisteredinstructor1"; - // searchPage.clearSearchBox(); - // searchPage.inputSearchContent(searchContent); - // searchPage.clickSearchButton(); - // searchPage.clickResetAccountRequestButton(accountRequest); - // assertNull(BACKDOOR.getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute()).getRegisteredAt()); + ______TS("Typical case: Search common search key"); + searchPage.clearSearchBox(); + searchContent = "Course1"; + searchPage.inputSearchContent(searchContent); + searchPage.clickSearchButton(); + searchPage.verifyStudentRowContentAfterReset(student, course); + searchPage.verifyInstructorRowContentAfterReset(instructor, course); + searchPage.verifyAccountRequestRowContent(accountRequest); + + ______TS("Typical case: Expand and collapse links"); + searchPage.verifyLinkExpansionButtons(student, instructor, accountRequest); + + ______TS("Typical case: Reset account request successful"); + searchContent = "unregisteredinstructor1"; + searchPage.clearSearchBox(); + searchPage.inputSearchContent(searchContent); + searchPage.clickSearchButton(); + searchPage.clickResetAccountRequestButton(accountRequest); + assertNull(BACKDOOR.getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute()).getRegisteredAt()); ______TS("Typical case: Delete account request successful"); accountRequest = sqlTestData.accountRequests.get("unregisteredInstructor1"); @@ -146,7 +134,9 @@ public void testAll() { private String getExpectedStudentDetails(Student student) { return String.format("%s [%s] (%s)", student.getCourse().getId(), - student.getSection() == null ? Const.DEFAULT_SECTION : student.getSection().getName(), student.getTeam().getName()); + student.getSection() == null + ? Const.DEFAULT_SECTION + : student.getSection().getName(), student.getTeam().getName()); } private String getExpectedStudentHomePageLink(Student student) { diff --git a/src/e2e/java/teammates/e2e/pageobjects/AdminSearchPage.java b/src/e2e/java/teammates/e2e/pageobjects/AdminSearchPage.java index 72f38ce26b2..2b98b62a388 100644 --- a/src/e2e/java/teammates/e2e/pageobjects/AdminSearchPage.java +++ b/src/e2e/java/teammates/e2e/pageobjects/AdminSearchPage.java @@ -11,7 +11,6 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -import teammates.common.util.Const; import teammates.common.util.StringHelper; import teammates.storage.sqlentity.AccountRequest; import teammates.storage.sqlentity.Course; @@ -147,8 +146,10 @@ public WebElement getStudentRow(Student student) { List rows = table.findElements(By.tagName("tr")); for (WebElement row : rows) { List columns = row.findElements(By.tagName("td")); - if (columns.size() >= 3 && removeSpanFromText(columns.get(2) - .getAttribute("innerHTML")).contains(student.getGoogleId())) { + if (columns.size() >= 3 && (removeSpanFromText(columns.get(2) + .getAttribute("innerHTML")).contains(student.getGoogleId()) + || removeSpanFromText(columns.get(1) + .getAttribute("innerHTML")).contains(student.getName()))) { return row; } } @@ -210,8 +211,10 @@ public WebElement getInstructorRow(Instructor instructor) { List rows = table.findElements(By.tagName("tr")); for (WebElement row : rows) { List columns = row.findElements(By.tagName("td")); - if (columns.size() >= 3 && removeSpanFromText(columns.get(2) - .getAttribute("innerHTML")).contains(instructor.getGoogleId())) { + if (columns.size() >= 3 && (removeSpanFromText(columns.get(2) + .getAttribute("innerHTML")).contains(instructor.getGoogleId()) + || removeSpanFromText(columns.get(1) + .getAttribute("innerHTML")).contains(instructor.getName()))) { return row; } } @@ -271,7 +274,7 @@ public WebElement getAccountRequestRow(AccountRequest accountRequest) { for (WebElement row : rows) { List columns = row.findElements(By.tagName("td")); if (columns.size() >= 2 && removeSpanFromText(columns.get(1) - .getAttribute("innerHTML")).contains(email)) { + .getAttribute("innerHTML")).contains(email)) { return row; } } @@ -372,6 +375,21 @@ public void verifyStudentRowContent(Student student, Course course, assertEquals(expectedHomePageLink, actualHomepageLink); } + public void verifyStudentRowContentAfterReset(Student student, Course course) { + WebElement studentRow = getStudentRow(student); + String actualName = getStudentName(studentRow); + String actualInstitute = getStudentInstitute(studentRow); + String actualComment = getStudentComments(studentRow); + + String expectedName = student.getName(); + String expectedInstitute = StringHelper.convertToEmptyStringIfNull(course.getInstitute()); + String expectedComment = StringHelper.convertToEmptyStringIfNull(student.getComments()); + + assertEquals(expectedName, actualName); + assertEquals(expectedInstitute, actualInstitute); + assertEquals(expectedComment, actualComment); + } + public void verifyStudentExpandedLinks(Student student, int expectedNumExpandedRows) { clickExpandStudentLinks(); WebElement studentRow = getStudentRow(student); @@ -409,6 +427,21 @@ public void verifyInstructorRowContent(Instructor instructor, Course course, assertEquals(expectedManageAccountLink, actualManageAccountLink); } + public void verifyInstructorRowContentAfterReset(Instructor instructor, Course course) { + WebElement instructorRow = getInstructorRow(instructor); + String actualCourseId = getInstructorCourseId(instructorRow); + String actualName = getInstructorName(instructorRow); + String actualInstitute = getInstructorInstitute(instructorRow); + + String expectedCourseId = instructor.getCourseId(); + String expectedName = instructor.getName(); + String expectedInstitute = StringHelper.convertToEmptyStringIfNull(course.getInstitute()); + + assertEquals(expectedCourseId, actualCourseId); + assertEquals(expectedName, actualName); + assertEquals(expectedInstitute, actualInstitute); + } + public void verifyInstructorExpandedLinks(Instructor instructor) { clickExpandInstructorLinks(); WebElement instructorRow = getInstructorRow(instructor); diff --git a/src/e2e/resources/data/AdminSearchPageE2ETest_SQLEntities.json b/src/e2e/resources/data/AdminSearchPageE2ETest_SQLEntities.json index cde0057cd8d..699baae6fe9 100644 --- a/src/e2e/resources/data/AdminSearchPageE2ETest_SQLEntities.json +++ b/src/e2e/resources/data/AdminSearchPageE2ETest_SQLEntities.json @@ -2,19 +2,19 @@ "accounts": { "instructor1OfCourse1": { "id": "00000000-0000-4000-8000-000000000001", - "googleId": "tm.e2e.ASearch.instr1", + "googleId": "tm.e2e.ASearch.instr", "name": "Instructor 1", "email": "ASearch.instructor1@gmail.tmt" }, "unregisteredInstructor1": { "id": "00000000-0000-4000-8000-000000000006", - "googleId": "unregisteredInstructor1", + "googleId": "unregisteredInstructor", "name": "Unregistered Instructor 1 of Course1", "email": "unregisteredinstructor1@gmail.tmt" }, "student1InCourse1": { "id": "00000000-0000-4000-8000-000000000101", - "googleId": "tm.e2e.ASearch.student1", + "googleId": "tm.e2e.ASearch.student", "name": "Student1 in course1", "email": "ASearch.student1@gmail.tmt" } @@ -25,7 +25,8 @@ "googleId": "unregisteredInstructor1", "name": "Unregistered Instructor 1 of Course1", "email": "unregisteredinstructor1@gmail.tmt", - "institute":"TEAMMATES Test Institute 0" + "institute":"TEAMMATES Test Institute 0", + "registeredAt": "2010-02-14T00:00:00Z" } }, "courses": { @@ -65,7 +66,7 @@ "id": "course-1" }, "name": "Instructor1 of Course1", - "email": "ASearch.instructor1@gmail.tmt", + "email": "ASearch.instructor@gmail.tmt", "role": "INSTRUCTOR_PERMISSION_ROLE_COOWNER", "isDisplayedToStudents": true, "displayName": "Instructor", diff --git a/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java b/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java index 2bd8f2bfb08..50add8e08ff 100644 --- a/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java +++ b/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java @@ -256,12 +256,10 @@ public EmailWrapper generateFeedbackSessionSummaryOfCourse( Course course = coursesLogic.getCourse(courseId); boolean isInstructor = emailType == EmailType.INSTRUCTOR_COURSE_LINKS_REGENERATED; - Student student = null; + Student student = usersLogic.getStudentForEmail(courseId, userEmail); Instructor instructor = null; if (isInstructor) { instructor = usersLogic.getInstructorForEmail(courseId, userEmail); - } else { - student = usersLogic.getStudentForEmail(courseId, userEmail); } List sessions = new ArrayList<>(); @@ -868,11 +866,11 @@ private EmailWrapper generateFeedbackSessionEmailBaseForNotifiedInstructors( } private boolean isYetToJoinCourse(Student student) { - return student.getAccount().getGoogleId() == null || student.getAccount().getGoogleId().isEmpty(); + return student.getAccount() == null || student.getAccount().getGoogleId().isEmpty(); } private boolean isYetToJoinCourse(Instructor instructor) { - return instructor.getAccount().getGoogleId() == null || instructor.getAccount().getGoogleId().isEmpty(); + return instructor.getAccount() == null || instructor.getAccount().getGoogleId().isEmpty(); } /** diff --git a/src/main/java/teammates/sqllogic/core/DataBundleLogic.java b/src/main/java/teammates/sqllogic/core/DataBundleLogic.java index 3e885387dd7..6b7376a7e9b 100644 --- a/src/main/java/teammates/sqllogic/core/DataBundleLogic.java +++ b/src/main/java/teammates/sqllogic/core/DataBundleLogic.java @@ -338,18 +338,6 @@ public void removeDataBundle(SqlDataBundle dataBundle) throws InvalidParametersE throw new InvalidParametersException("Data bundle is null"); } - dataBundle.feedbackResponseComments.values().forEach(responseComment -> { - frcLogic.deleteFeedbackResponseComment(responseComment.getId()); - }); - - dataBundle.feedbackSessions.values().forEach(session -> { - fsLogic.deleteFeedbackSessionCascade(session.getName(), session.getCourse().getId()); - }); - - dataBundle.feedbackQuestions.values().forEach(question -> { - fqLogic.deleteFeedbackQuestionCascade(question.getId()); - }); - dataBundle.courses.values().forEach(course -> { coursesLogic.deleteCourseCascade(course.getId()); }); diff --git a/src/test/java/teammates/test/BaseTestCaseWithDatabaseAccess.java b/src/test/java/teammates/test/BaseTestCaseWithDatabaseAccess.java index 68e03ebe47b..c4f1b9ea569 100644 --- a/src/test/java/teammates/test/BaseTestCaseWithDatabaseAccess.java +++ b/src/test/java/teammates/test/BaseTestCaseWithDatabaseAccess.java @@ -286,7 +286,7 @@ protected SqlDataBundle removeAndRestoreSqlDataBundle(SqlDataBundle testData) { protected abstract SqlDataBundle doRemoveAndRestoreSqlDataBundle(SqlDataBundle testData); - protected void putDocumentsSQL(SqlDataBundle testData) { + protected void putDocumentsSql(SqlDataBundle testData) { int retryLimit = OPERATION_RETRY_COUNT; boolean isOperationSuccess = doPutDocuments(testData); while (!isOperationSuccess && retryLimit > 0) {