Skip to content

Commit

Permalink
[#12048] Migrate FeedbackMcqQuestionE2ETest (#12820)
Browse files Browse the repository at this point in the history
* Migrate MCQ E2E

* Fix lint

* Fix lint

* Update xml

---------

Co-authored-by: Cedric Ong <[email protected]>
  • Loading branch information
dishenggg and cedricongjh authored Mar 26, 2024
1 parent 0cfadef commit e51132e
Show file tree
Hide file tree
Showing 6 changed files with 435 additions and 1 deletion.
140 changes: 140 additions & 0 deletions src/e2e/java/teammates/e2e/cases/sql/FeedbackMcqQuestionE2ETest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package teammates.e2e.cases.sql;

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

import org.testng.annotations.Test;

import teammates.common.datatransfer.questions.FeedbackMcqQuestionDetails;
import teammates.common.datatransfer.questions.FeedbackMcqResponseDetails;
import teammates.e2e.pageobjects.FeedbackSubmitPage;
import teammates.e2e.pageobjects.InstructorFeedbackEditPage;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackResponse;

/**
* SUT: {@link Const.WebPageURIs#INSTRUCTOR_SESSION_EDIT_PAGE},
* {@link Const.WebPageURIs#SESSION_SUBMISSION_PAGE}
* specifically for MCQ questions.
*/
public class FeedbackMcqQuestionE2ETest extends BaseFeedbackQuestionE2ETest {

@Override
protected void prepareTestData() {
testData = removeAndRestoreDataBundle(loadSqlDataBundle("/FeedbackMcqQuestionE2ESqlTest.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");
FeedbackMcqQuestionDetails questionDetails = (FeedbackMcqQuestionDetails) loadedQuestion
.getQuestionDetailsCopy();
feedbackEditPage.verifyMcqQuestionDetails(1, questionDetails);

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

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

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

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

______TS("edit question");
questionDetails = (FeedbackMcqQuestionDetails) loadedQuestion.getQuestionDetailsCopy();
questionDetails.setHasAssignedWeights(false);
questionDetails.setMcqWeights(new ArrayList<>());
questionDetails.setOtherEnabled(false);
questionDetails.setQuestionDropdownEnabled(false);
questionDetails.setMcqOtherWeight(0);
List<String> choices = questionDetails.getMcqChoices();
choices.add("Edited choice");
questionDetails.setMcqChoices(choices);
loadedQuestion = testData.feedbackQuestions.get("qn1ForFirstSession").makeDeepCopy(feedbackSession);
loadedQuestion.setQuestionDetails(questionDetails);
feedbackEditPage.editMcqQuestion(2, questionDetails);
feedbackEditPage.waitForPageToLoad();

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

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

______TS("verify loaded question");
FeedbackQuestion question = testData.feedbackQuestions.get("qn1ForFirstSession");
feedbackSubmitPage.verifyMcqQuestion(1, "",
(FeedbackMcqQuestionDetails) question.getQuestionDetailsCopy());

______TS("verify question with generated options");
feedbackSubmitPage.verifyGeneratedMcqQuestion(3, "", getGeneratedStudentOptions());

______TS("submit response");
FeedbackResponse response = getResponse(question, false, "UI");
feedbackSubmitPage.fillMcqResponse(1, "", response);
feedbackSubmitPage.clickSubmitQuestionButton(1);

// verifyPresentInDatabase(response);

// ______TS("check previous response");
// feedbackSubmitPage = getFeedbackSubmitPage();
// feedbackSubmitPage.verifyMcqResponse(1, "", response);

// ______TS("edit response");
// response = getResponse(questionId, true, "This is the edited response.");
// feedbackSubmitPage.fillMcqResponse(1, "", response);
// feedbackSubmitPage.clickSubmitQuestionButton(1);

// feedbackSubmitPage = getFeedbackSubmitPage();
// feedbackSubmitPage.verifyMcqResponse(1, "", response);
// verifyPresentInDatabase(response);
}

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

private FeedbackResponse getResponse(FeedbackQuestion feedbackQuestion, boolean isOther, String answer) {
FeedbackMcqResponseDetails details = new FeedbackMcqResponseDetails();
if (isOther) {
details.setOther(true);
details.setOtherFieldContent(answer);
} else {
details.setAnswer(answer);
}
return FeedbackResponse.makeResponse(feedbackQuestion, student.getEmail(), null, instructor.getEmail(), null,
details);
}
}
16 changes: 16 additions & 0 deletions src/e2e/java/teammates/e2e/pageobjects/FeedbackSubmitPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ public void fillMcqResponse(int qnNumber, String recipient, FeedbackResponseAttr
}
}

public void fillMcqResponse(int qnNumber, String recipient, FeedbackResponse response) {
FeedbackMcqResponseDetails responseDetails = (FeedbackMcqResponseDetails) response.getFeedbackResponseDetailsCopy();
if (responseDetails.isOther()) {
markOptionAsSelected(getMcqOtherOptionRadioBtn(qnNumber, recipient));
fillTextBox(getMcqOtherOptionTextbox(qnNumber, recipient), responseDetails.getOtherFieldContent());
} else {
List<WebElement> optionTexts = getMcqOptions(qnNumber, recipient);
for (int i = 0; i < optionTexts.size(); i++) {
if (optionTexts.get(i).getText().equals(responseDetails.getAnswer())) {
markOptionAsSelected(getMcqRadioBtns(qnNumber, recipient).get(i));
break;
}
}
}
}

public void verifyMcqResponse(int qnNumber, String recipient, FeedbackResponseAttributes response) {
FeedbackMcqResponseDetails responseDetails = (FeedbackMcqResponseDetails) response.getResponseDetailsCopy();
if (responseDetails.isOther()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,15 @@ public void addMcqQuestion(FeedbackQuestionAttributes feedbackQuestion) {
clickSaveNewQuestionButton();
}

public void addMcqQuestion(FeedbackQuestion feedbackQuestion) {
addNewQuestion(3);
int questionNum = getNumQuestions();
inputQuestionDetails(questionNum, feedbackQuestion);
FeedbackMcqQuestionDetails questionDetails = (FeedbackMcqQuestionDetails) feedbackQuestion.getQuestionDetailsCopy();
inputMcqDetails(questionNum, questionDetails);
clickSaveNewQuestionButton();
}

public void editMcqQuestion(int questionNum, FeedbackMcqQuestionDetails questionDetails) {
clickEditQuestionButton(questionNum);
inputMcqDetails(questionNum, questionDetails);
Expand Down
Loading

0 comments on commit e51132e

Please sign in to comment.