Skip to content

Commit

Permalink
fix e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
domoberzin committed Feb 25, 2024
1 parent 9be4251 commit 2e291e8
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 48 deletions.
9 changes: 4 additions & 5 deletions src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package teammates.e2e.cases;

import java.time.Instant;
import java.util.concurrent.TimeUnit;

import org.testng.annotations.Test;

import teammates.common.datatransfer.attributes.AccountRequestAttributes;
import teammates.common.datatransfer.attributes.CourseAttributes;
import teammates.common.datatransfer.attributes.FeedbackSessionAttributes;
import teammates.common.datatransfer.attributes.InstructorAttributes;
Expand All @@ -14,6 +12,7 @@
import teammates.common.util.Const;
import teammates.e2e.pageobjects.AdminSearchPage;
import teammates.e2e.util.TestProperties;
import teammates.storage.sqlentity.AccountRequest;

/**
* SUT: {@link Const.WebPageURIs#ADMIN_SEARCH_PAGE}.
Expand All @@ -28,9 +27,9 @@ protected void prepareTestData() {

testData = loadDataBundle("/AdminSearchPageE2ETest.json");
removeAndRestoreDataBundle(testData);
putDocuments(testData);
sqlTestData = loadSqlDataBundle("/AdminSearchPageE2ETest_SqlEntities.json");
removeAndRestoreSqlDataBundle(sqlTestData);
putDocuments(testData);
}

@Test
Expand All @@ -46,7 +45,7 @@ public void testAll() {
CourseAttributes course = testData.courses.get("typicalCourse1");
StudentAttributes student = testData.students.get("student1InCourse1");
InstructorAttributes instructor = testData.instructors.get("instructor1OfCourse1");
AccountRequestAttributes accountRequest = testData.accountRequests.get("instructor1OfCourse1");
AccountRequest accountRequest = sqlTestData.accountRequests.get("instructor1OfCourse1");

______TS("Typical case: Search student email");
String searchContent = student.getEmail();
Expand Down Expand Up @@ -134,7 +133,7 @@ public void testAll() {
assertNull(BACKDOOR.getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute()).getRegisteredAt());

______TS("Typical case: Delete account request successful");
accountRequest = testData.accountRequests.get("unregisteredInstructor1");
accountRequest = sqlTestData.accountRequests.get("unregisteredInstructor1");
searchContent = accountRequest.getEmail();
searchPage.clearSearchBox();
searchPage.inputSearchContent(searchContent);
Expand Down
97 changes: 97 additions & 0 deletions src/e2e/java/teammates/e2e/pageobjects/AdminSearchPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import teammates.common.datatransfer.attributes.StudentAttributes;
import teammates.common.util.Const;
import teammates.common.util.StringHelper;
import teammates.storage.sqlentity.AccountRequest;

/**
* Represents the admin home page of the website.
Expand Down Expand Up @@ -285,6 +286,22 @@ && removeSpanFromText(columns.get(ACCOUNT_REQUEST_COL_INSTITUTE - 1)
return null;
}

public WebElement getAccountRequestRow(AccountRequest accountRequest) {
String email = accountRequest.getEmail();
String institute = accountRequest.getInstitute();
List<WebElement> rows = browser.driver.findElements(By.cssSelector("#search-table-account-request tbody tr"));
for (WebElement row : rows) {
List<WebElement> columns = row.findElements(By.tagName("td"));
if (removeSpanFromText(columns.get(ACCOUNT_REQUEST_COL_EMAIL - 1)
.getAttribute("innerHTML")).contains(email)
&& removeSpanFromText(columns.get(ACCOUNT_REQUEST_COL_INSTITUTE - 1)
.getAttribute("innerHTML")).contains(institute)) {
return row;
}
}
return null;
}

public String getAccountRequestName(WebElement accountRequestRow) {
return getColumnText(accountRequestRow, ACCOUNT_REQUEST_COL_NAME);
}
Expand Down Expand Up @@ -317,6 +334,14 @@ public void clickDeleteAccountRequestButton(AccountRequestAttributes accountRequ
waitForPageToLoad();
}

public void clickDeleteAccountRequestButton(AccountRequest accountRequest) {
WebElement accountRequestRow = getAccountRequestRow(accountRequest);
WebElement deleteButton = accountRequestRow.findElement(By.cssSelector("[id^='delete-account-request-']"));
deleteButton.click();
waitForConfirmationModalAndClickOk();
waitForPageToLoad();
}

public void clickResetAccountRequestButton(AccountRequestAttributes accountRequest) {
WebElement accountRequestRow = getAccountRequestRow(accountRequest);
WebElement deleteButton = accountRequestRow.findElement(By.cssSelector("[id^='reset-account-request-']"));
Expand All @@ -325,6 +350,14 @@ public void clickResetAccountRequestButton(AccountRequestAttributes accountReque
waitForPageToLoad();
}

public void clickResetAccountRequestButton(AccountRequest accountRequest) {
WebElement accountRequestRow = getAccountRequestRow(accountRequest);
WebElement deleteButton = accountRequestRow.findElement(By.cssSelector("[id^='reset-account-request-']"));
deleteButton.click();
waitForConfirmationModalAndClickOk();
waitForPageToLoad();
}

public int getNumExpandedRows(WebElement row) {
String xpath = "following-sibling::tr[1]/td/ul/li";
return row.findElements(By.xpath(xpath)).size();
Expand Down Expand Up @@ -447,6 +480,25 @@ public void verifyAccountRequestRowContent(AccountRequestAttributes accountReque
}
}

public void verifyAccountRequestRowContent(AccountRequest accountRequest) {
WebElement accountRequestRow = getAccountRequestRow(accountRequest);
String actualName = getAccountRequestName(accountRequestRow);
String actualEmail = getAccountRequestEmail(accountRequestRow);
String actualInstitute = getAccountRequestInstitute(accountRequestRow);
String actualCreatedAt = getAccountRequestCreatedAt(accountRequestRow);
String actualRegisteredAt = getAccountRequestRegisteredAt(accountRequestRow);

assertEquals(accountRequest.getName(), actualName);
assertEquals(accountRequest.getEmail(), actualEmail);
assertEquals(accountRequest.getInstitute(), actualInstitute);
assertFalse(actualCreatedAt.isBlank());
if (accountRequest.getRegisteredAt() == null) {
assertEquals("Not Registered Yet", actualRegisteredAt);
} else {
assertFalse(actualRegisteredAt.isBlank());
}
}

public void verifyAccountRequestExpandedLinks(AccountRequestAttributes accountRequest) {
clickExpandAccountRequestLinks();
WebElement accountRequestRow = getAccountRequestRow(accountRequest);
Expand All @@ -455,6 +507,14 @@ public void verifyAccountRequestExpandedLinks(AccountRequestAttributes accountRe
assertFalse(actualRegistrationLink.isBlank());
}

public void verifyAccountRequestExpandedLinks(AccountRequest accountRequest) {
clickExpandAccountRequestLinks();
WebElement accountRequestRow = getAccountRequestRow(accountRequest);
String actualRegistrationLink = getAccountRequestRegistrationLink(accountRequestRow);

assertFalse(actualRegistrationLink.isBlank());
}

public void verifyLinkExpansionButtons(StudentAttributes student,
InstructorAttributes instructor, AccountRequestAttributes accountRequest) {
WebElement studentRow = getStudentRow(student);
Expand Down Expand Up @@ -492,6 +552,43 @@ public void verifyLinkExpansionButtons(StudentAttributes student,
assertEquals(numExpandedAccountRequestRows, 0);
}

public void verifyLinkExpansionButtons(StudentAttributes student,
InstructorAttributes instructor, AccountRequest accountRequest) {
WebElement studentRow = getStudentRow(student);
WebElement instructorRow = getInstructorRow(instructor);
WebElement accountRequestRow = getAccountRequestRow(accountRequest);

clickExpandStudentLinks();
clickExpandInstructorLinks();
clickExpandAccountRequestLinks();
int numExpandedStudentRows = getNumExpandedRows(studentRow);
int numExpandedInstructorRows = getNumExpandedRows(instructorRow);
int numExpandedAccountRequestRows = getNumExpandedRows(accountRequestRow);
assertNotEquals(numExpandedStudentRows, 0);
assertNotEquals(numExpandedInstructorRows, 0);
assertNotEquals(numExpandedAccountRequestRows, 0);

clickCollapseInstructorLinks();
numExpandedStudentRows = getNumExpandedRows(studentRow);
numExpandedInstructorRows = getNumExpandedRows(instructorRow);
numExpandedAccountRequestRows = getNumExpandedRows(accountRequestRow);
assertNotEquals(numExpandedStudentRows, 0);
assertEquals(numExpandedInstructorRows, 0);
assertNotEquals(numExpandedAccountRequestRows, 0);

clickExpandInstructorLinks();
clickCollapseStudentLinks();
clickCollapseAccountRequestLinks();
waitUntilAnimationFinish();

numExpandedStudentRows = getNumExpandedRows(studentRow);
numExpandedInstructorRows = getNumExpandedRows(instructorRow);
numExpandedAccountRequestRows = getNumExpandedRows(accountRequestRow);
assertEquals(numExpandedStudentRows, 0);
assertNotEquals(numExpandedInstructorRows, 0);
assertEquals(numExpandedAccountRequestRows, 0);
}

public void verifyRegenerateStudentKey(StudentAttributes student, String originalJoinLink) {
verifyStatusMessage("Student's key for this course has been successfully regenerated,"
+ " and the email has been sent.");
Expand Down
22 changes: 0 additions & 22 deletions src/e2e/resources/data/AdminSearchPageE2ETest.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,5 @@
"studentDeadlines": {},
"instructorDeadlines": {}
}
},
"accountRequests": {
"instructor1OfCourse1": {
"name": "Instructor1 of Course1",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"createdAt": "2011-01-01T00:00:00Z",
"registeredAt": "1970-02-14T00:00:00Z"
},
"instructor2OfCourse1": {
"name": "Instructor2 of Course1",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"createdAt": "2011-01-01T00:00:00Z",
"registeredAt": "1970-02-14T00:00:00Z"
},
"unregisteredInstructor1": {
"name": "Typical Instructor Name",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"createdAt": "2011-01-01T00:00:00Z"
}
}
}
28 changes: 25 additions & 3 deletions src/e2e/resources/data/AdminSearchPageE2ETest_SqlEntities.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"accounts": {
"accounts": {
"instructor1OfCourse1": {
"googleId": "tm.e2e.ASearch.instr1",
"name": "Instructor1 of Course1",
Expand All @@ -18,5 +18,27 @@
"email": "[email protected]",
"readNotifications": {}
}
}
}
},
"accountRequests": {
"instructor1OfCourse1": {
"name": "Instructor1 of Course1",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"createdAt": "2011-01-01T00:00:00Z",
"registeredAt": "1970-02-14T00:00:00Z"
},
"instructor2OfCourse1": {
"name": "Instructor2 of Course1",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"createdAt": "2011-01-01T00:00:00Z",
"registeredAt": "1970-02-14T00:00:00Z"
},
"unregisteredInstructor1": {
"name": "Typical Instructor Name",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"createdAt": "2011-01-01T00:00:00Z"
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/teammates/storage/search/SearchManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ List<T> convertDocumentToAttributes(List<SolrDocument> documents) {
// deleteDocuments(Collections.singletonList(id));
// continue;
// }
if (attribute == null) {
continue;
}
result.add(attribute);
}
sortResult(result);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/teammates/storage/sqlsearch/SearchManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ List<T> convertDocumentToEntities(List<SolrDocument> documents) {
if (entity == null) {
// search engine out of sync as SearchManager may fail to delete documents
// the chance is low and it is generally not a big problem
String id = (String) document.getFirstValue("id");
deleteDocuments(Collections.singletonList(id));
// String id = (String) document.getFirstValue("id");
// deleteDocuments(Collections.singletonList(id));
continue;
}
result.add(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ public JsonResult execute() {
accountRequests = sqlLogic.searchAccountRequestsInWholeSystem(searchKey);
} catch (SearchServiceException e) {
return new JsonResult(e.getMessage(), e.getStatusCode());
} catch (NullPointerException e) {
accountRequests = new ArrayList<>();
}

List<AccountRequestAttributes> requestsDatastore;
try {
requestsDatastore = logic.searchAccountRequestsInWholeSystem(searchKey);
} catch (SearchServiceException e) {
return new JsonResult(e.getMessage(), e.getStatusCode());
} catch (NullPointerException e) {
requestsDatastore = new ArrayList<>();
}

List<AccountRequestData> accountRequestDataList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public JsonResult execute() {
instructors = sqlLogic.searchInstructorsInWholeSystem(searchKey);
} catch (SearchServiceException e) {
return new JsonResult(e.getMessage(), e.getStatusCode());
} catch (NullPointerException e) {
// Solr search service is not active
instructors = new ArrayList<>();
}

// Catching of NullPointerException for both Solr searches below is necessary for running of tests.
Expand All @@ -45,9 +42,6 @@ public JsonResult execute() {
instructorsDatastore = logic.searchInstructorsInWholeSystem(searchKey);
} catch (SearchServiceException e) {
return new JsonResult(e.getMessage(), e.getStatusCode());
} catch (NullPointerException e) {
// Solr search service is not active
instructorsDatastore = new ArrayList<>();
}

List<InstructorData> instructorDataList = new ArrayList<>();
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/teammates/ui/webapi/SearchStudentsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public JsonResult execute() {
}
} catch (SearchServiceException e) {
return new JsonResult(e.getMessage(), e.getStatusCode());
} catch (NullPointerException e) {
// Solr search service is not active
students = new ArrayList<>();
}

// Search in datastore. For more information on dual db support, see this [PR](https://github.com/TEAMMATES/teammates/pull/12728/files)
Expand All @@ -67,9 +64,6 @@ public JsonResult execute() {
}
} catch (SearchServiceException e) {
return new JsonResult(e.getMessage(), e.getStatusCode());
} catch (NullPointerException e) {
// Solr search service is not active
studentsDatastore = new ArrayList<>();
}

List<StudentData> studentDataList = new ArrayList<>();
Expand Down

0 comments on commit 2e291e8

Please sign in to comment.