Skip to content

Commit

Permalink
[#12048] Migrate FeedbackMsqQuestionE2ETest (#12904)
Browse files Browse the repository at this point in the history
* Migrate test

* Update test

* Update sql json

* fix lint

* Fix lint

* Update json and add test to xml

* Revert "Fix lint"

This reverts commit f767b52.

* Revert "Update sql json"

This reverts commit 4574475.

* Fix xml

* Change to use makeDeepCopy

* sort questions

* fix verifyEquals method

---------

Co-authored-by: Cedric Ong <[email protected]>
Co-authored-by: Cedric Ong <[email protected]>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent a34c3c5 commit 4dc0c6d
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 4 deletions.
150 changes: 150 additions & 0 deletions src/e2e/java/teammates/e2e/cases/sql/FeedbackMsqQuestionE2ETest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package teammates.e2e.cases.sql;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.testng.annotations.Test;

import teammates.common.datatransfer.questions.FeedbackMsqQuestionDetails;
import teammates.common.datatransfer.questions.FeedbackMsqResponseDetails;
import teammates.common.util.Const;
import teammates.e2e.pageobjects.FeedbackSubmitPage;
import teammates.e2e.pageobjects.InstructorFeedbackEditPage;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Student;

/**
* SUT: {@link Const.WebPageURIs#INSTRUCTOR_SESSION_EDIT_PAGE},
* {@link Const.WebPageURIs#SESSION_SUBMISSION_PAGE}
* specifically for msq questions.
*/
public class FeedbackMsqQuestionE2ETest extends BaseFeedbackQuestionE2ETest {
@Override
protected void prepareTestData() {
testData = removeAndRestoreDataBundle(loadSqlDataBundle("/FeedbackMsqQuestionE2ESqlTest.json"));

instructor = testData.instructors.get("instructor");
course = testData.courses.get("course");
feedbackSession = testData.feedbackSessions.get("openSession");
student = testData.students.get("[email protected]");
}

@Test
@Override
public void testAll() {
testEditPage();
logout();
testSubmitPage();
}

@Override
protected void testEditPage() {
InstructorFeedbackEditPage feedbackEditPage = loginToFeedbackEditPage();

______TS("verify loaded question");
FeedbackQuestion loadedQuestion = testData.feedbackQuestions.get("qn1ForFirstSession")
.makeDeepCopy(feedbackSession);
FeedbackMsqQuestionDetails questionDetails = (FeedbackMsqQuestionDetails) loadedQuestion
.getQuestionDetailsCopy();
feedbackEditPage.verifyMsqQuestionDetails(1, questionDetails);

______TS("add new question");
// add new question exactly like loaded question
loadedQuestion.setQuestionNumber(2);
feedbackEditPage.addMsqQuestion(loadedQuestion);

feedbackEditPage.verifyMsqQuestionDetails(2, questionDetails);
verifyPresentInDatabase(loadedQuestion);

______TS("copy question");
FeedbackQuestion copiedQuestion = testData.feedbackQuestions.get("qn1ForSecondSession");
questionDetails = (FeedbackMsqQuestionDetails) copiedQuestion.getQuestionDetailsCopy();
feedbackEditPage.copyQuestion(copiedQuestion.getCourseId(),
copiedQuestion.getQuestionDetailsCopy().getQuestionText());
copiedQuestion.setFeedbackSession(feedbackSession);
copiedQuestion.setQuestionNumber(3);

feedbackEditPage.verifyMsqQuestionDetails(3, questionDetails);
verifyPresentInDatabase(copiedQuestion);

______TS("edit question");
questionDetails = (FeedbackMsqQuestionDetails) loadedQuestion.getQuestionDetailsCopy();
questionDetails.setHasAssignedWeights(false);
questionDetails.setMsqWeights(new ArrayList<>());
questionDetails.setOtherEnabled(false);
questionDetails.setMsqOtherWeight(0);
questionDetails.setMaxSelectableChoices(Const.POINTS_NO_VALUE);
List<String> choices = questionDetails.getMsqChoices();
choices.add("Edited choice");
questionDetails.setMsqChoices(choices);
loadedQuestion.setQuestionDetails(questionDetails);
feedbackEditPage.editMsqQuestion(2, questionDetails);
feedbackEditPage.waitForPageToLoad();

feedbackEditPage.verifyMsqQuestionDetails(2, questionDetails);
verifyPresentInDatabase(loadedQuestion);
}

@Override
protected void testSubmitPage() {
FeedbackSubmitPage feedbackSubmitPage = loginToFeedbackSubmitPage();

______TS("verify loaded question");
FeedbackQuestion question = testData.feedbackQuestions.get("qn1ForFirstSession");
Student receiver = testData.students.get("[email protected]");
feedbackSubmitPage.verifyMsqQuestion(1, receiver.getName(),
(FeedbackMsqQuestionDetails) question.getQuestionDetailsCopy());

______TS("verify loaded question with generated options");
FeedbackQuestion generatedQn = testData.feedbackQuestions.get("qn1ForSecondSession");
feedbackSubmitPage.verifyGeneratedMsqQuestion(3, "",
(FeedbackMsqQuestionDetails) generatedQn.getQuestionDetailsCopy(), getGeneratedTeams());

______TS("submit response");
List<String> answers = Arrays.asList("Leadership", "This is the other response.");
FeedbackResponse response = getResponse(question, receiver, answers.get(answers.size() - 1), answers);
feedbackSubmitPage.fillMsqResponse(1, receiver.getName(), response);
feedbackSubmitPage.clickSubmitQuestionButton(1);

// TODO: uncomment when SubmitFeedbackResponse is working
// verifyPresentInDatabase(response);

// ______TS("check previous response");
// feedbackSubmitPage = getFeedbackSubmitPage();
// feedbackSubmitPage.verifyMsqResponse(1, receiver.getName(), response);

// ______TS("edit response");
// answers = Arrays.asList("");
// response = getResponse(question, receiver, "", answers);
// feedbackSubmitPage.fillMsqResponse(1, receiver.getName(), response);
// feedbackSubmitPage.clickSubmitQuestionButton(1);

// feedbackSubmitPage = getFeedbackSubmitPage();
// feedbackSubmitPage.verifyMsqResponse(1, receiver.getName(), response);
// verifyPresentInDatabase(response);
}

private List<String> getGeneratedTeams() {
return testData.students.values().stream()
.filter(s -> s.getCourse().equals(student.getCourse()))
.map(s -> s.getTeam().getName())
.distinct()
.collect(Collectors.toList());
}

private FeedbackResponse getResponse(FeedbackQuestion feedbackQuestion, Student receiver, String other,
List<String> answers) {
FeedbackMsqResponseDetails details = new FeedbackMsqResponseDetails();
if (!other.isEmpty()) {
details.setOther(true);
details.setOtherFieldContent(other);
}
details.setAnswers(answers);

return FeedbackResponse.makeResponse(feedbackQuestion, student.getEmail(), student.getSection(),
receiver.getEmail(), receiver.getSection(), details);
}
}
44 changes: 44 additions & 0 deletions src/e2e/java/teammates/e2e/pageobjects/FeedbackSubmitPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,27 @@ public void fillMsqResponse(int qnNumber, String recipient, FeedbackResponseAttr
}
}

public void fillMsqResponse(int qnNumber, String recipient, FeedbackResponse response) {
FeedbackMsqResponseDetails responseDetails = (FeedbackMsqResponseDetails) response.getFeedbackResponseDetailsCopy();
List<String> answers = responseDetails.getAnswers();
if (answers.get(0).isEmpty()) {
answers.add("None of the above");
}
List<WebElement> optionTexts = getMsqOptions(qnNumber, recipient);
List<WebElement> checkboxes = getMsqCheckboxes(qnNumber, recipient);
for (int i = 0; i < optionTexts.size(); i++) {
if (answers.contains(optionTexts.get(i).getText())) {
markOptionAsSelected(checkboxes.get(i));
} else {
markOptionAsUnselected(checkboxes.get(i));
}
}
if (responseDetails.isOther()) {
markOptionAsSelected(getMsqOtherOptionCheckbox(qnNumber, recipient));
fillTextBox(getMsqOtherOptionTextbox(qnNumber, recipient), responseDetails.getOtherFieldContent());
}
}

public void verifyMsqResponse(int qnNumber, String recipient, FeedbackResponseAttributes response) {
FeedbackMsqResponseDetails responseDetails = (FeedbackMsqResponseDetails) response.getResponseDetailsCopy();
List<String> answers = responseDetails.getAnswers();
Expand All @@ -313,6 +334,29 @@ public void verifyMsqResponse(int qnNumber, String recipient, FeedbackResponseAt
}
}

public void verifyMsqResponse(int qnNumber, String recipient, FeedbackResponse response) {
FeedbackMsqResponseDetails responseDetails = (FeedbackMsqResponseDetails) response.getFeedbackResponseDetailsCopy();
List<String> answers = responseDetails.getAnswers();
if (answers.get(0).isEmpty()) {
answers.add("None of the above");
}
List<WebElement> optionTexts = getMsqOptions(qnNumber, recipient);
List<WebElement> checkboxes = getMsqCheckboxes(qnNumber, recipient);
for (int i = 0; i < optionTexts.size(); i++) {
if (answers.contains(optionTexts.get(i).getText())) {
assertTrue(checkboxes.get(i).isSelected());
} else if ("Other".equals(optionTexts.get(i).getText())) {
assertEquals(checkboxes.get(i).isSelected(), responseDetails.isOther());
} else {
assertFalse(checkboxes.get(i).isSelected());
}
}
if (responseDetails.isOther()) {
assertEquals(getMsqOtherOptionTextbox(qnNumber, recipient).getAttribute("value"),
responseDetails.getOtherFieldContent());
}
}

public void verifyNumScaleQuestion(int qnNumber, String recipient,
FeedbackNumericalScaleQuestionDetails questionDetails) {
double step = questionDetails.getStep();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,15 @@ public void addMsqQuestion(FeedbackQuestionAttributes feedbackQuestion) {
clickSaveNewQuestionButton();
}

public void addMsqQuestion(FeedbackQuestion feedbackQuestion) {
addNewQuestion(4);
int questionNum = getNumQuestions();
inputQuestionDetails(questionNum, feedbackQuestion);
FeedbackMsqQuestionDetails questionDetails = (FeedbackMsqQuestionDetails) feedbackQuestion.getQuestionDetailsCopy();
inputMsqDetails(questionNum, questionDetails);
clickSaveNewQuestionButton();
}

public void editMsqQuestion(int questionNum, FeedbackMsqQuestionDetails msqQuestionDetails) {
clickEditQuestionButton(questionNum);
inputMsqDetails(questionNum, msqQuestionDetails);
Expand Down
Loading

0 comments on commit 4dc0c6d

Please sign in to comment.