Skip to content

Commit

Permalink
[#12048] Migrate Feedback Rank Option E2E test (#12902)
Browse files Browse the repository at this point in the history
* Initial commit

* Fix lint

* Follow convention and add test

* Change file path

* Fix requested changes

* Fixed testcases

* Fix lint

* Add deepcopy

* Fixed e2e test

---------

Co-authored-by: Wei Qing <[email protected]>
Co-authored-by: Cedric Ong <[email protected]>
  • Loading branch information
3 people authored Mar 26, 2024
1 parent 11b8b81 commit 0cfadef
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package teammates.e2e.cases.sql;

import java.util.Arrays;
import java.util.List;

import org.testng.annotations.Test;

import teammates.common.datatransfer.questions.FeedbackRankOptionsQuestionDetails;
import teammates.common.datatransfer.questions.FeedbackRankOptionsResponseDetails;
import teammates.common.datatransfer.questions.FeedbackRankQuestionDetails;
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 RankOption questions.
*/
public class FeedbackRankOptionQuestionE2ETest extends BaseFeedbackQuestionE2ETest {

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

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

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

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

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

______TS("edit question");
questionDetails = (FeedbackRankOptionsQuestionDetails) loadedQuestion.getQuestionDetailsCopy();
List<String> options = questionDetails.getOptions();
options.remove(0);
options.set(1, "Edited option.");
questionDetails.setOptions(options);
questionDetails.setAreDuplicatesAllowed(true);
questionDetails.setMaxOptionsToBeRanked(Const.POINTS_NO_VALUE);
questionDetails.setMinOptionsToBeRanked(1);
loadedQuestion.setQuestionDetails(questionDetails);
feedbackEditPage.editRankQuestion(2, questionDetails);
feedbackEditPage.waitForPageToLoad();

feedbackEditPage.verifyRankQuestionDetails(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.verifyRankQuestion(1, receiver.getName(),
(FeedbackRankQuestionDetails) question.getQuestionDetailsCopy());

______TS("submit response");
FeedbackResponse response = getResponse(question, receiver, Arrays.asList(2, 1, 3,
Const.POINTS_NOT_SUBMITTED));
feedbackSubmitPage.fillRankOptionResponse(1, receiver.getName(), response);
feedbackSubmitPage.clickSubmitQuestionButton(1);

// verifyPresentInDatabase(response);

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

// ______TS("edit response");
// response = getResponse(questionId, receiver,
// Arrays.asList(Const.POINTS_NOT_SUBMITTED, 1, 3, 2));
// feedbackSubmitPage.fillRankOptionResponse(1, receiver.getName(), response);
// feedbackSubmitPage.clickSubmitQuestionButton(1);

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

private FeedbackResponse getResponse(FeedbackQuestion question, Student receiver, List<Integer> answers) {
FeedbackRankOptionsResponseDetails details = new FeedbackRankOptionsResponseDetails();
details.setAnswers(answers);
return FeedbackResponse.makeResponse(question, student.getEmail(), null, receiver.getEmail(), null, details);
}
}
14 changes: 14 additions & 0 deletions src/e2e/java/teammates/e2e/pageobjects/FeedbackSubmitPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,20 @@ public void fillRankOptionResponse(int qnNumber, String recipient, FeedbackRespo
}
}

public void fillRankOptionResponse(int qnNumber, String recipient, FeedbackResponse response) {
FeedbackRankOptionsResponseDetails responseDetails =
(FeedbackRankOptionsResponseDetails) response.getFeedbackResponseDetailsCopy();
List<Integer> answers = responseDetails.getAnswers();
for (int i = 0; i < answers.size(); i++) {
if (answers.get(i) == Const.POINTS_NOT_SUBMITTED) {
selectDropdownOptionByText(getRankOptionsDropdowns(qnNumber, recipient).get(i), "");
} else {
selectDropdownOptionByText(getRankOptionsDropdowns(qnNumber, recipient).get(i),
Integer.toString(answers.get(i)));
}
}
}

public void verifyRankOptionResponse(int qnNumber, String recipient, FeedbackResponseAttributes response) {
FeedbackRankOptionsResponseDetails responseDetails =
(FeedbackRankOptionsResponseDetails) response.getResponseDetailsCopy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,16 @@ public void addRankOptionsQuestion(FeedbackQuestionAttributes feedbackQuestion)
clickSaveNewQuestionButton();
}

public void addRankOptionsQuestion(FeedbackQuestion feedbackQuestion) {
addNewQuestion(10);
int questionNum = getNumQuestions();
inputQuestionDetails(questionNum, feedbackQuestion);
FeedbackRankOptionsQuestionDetails questionDetails =
(FeedbackRankOptionsQuestionDetails) feedbackQuestion.getQuestionDetailsCopy();
inputRankDetails(questionNum, questionDetails);
clickSaveNewQuestionButton();
}

public void addRankRecipientsQuestion(FeedbackQuestionAttributes feedbackQuestion) {
addNewQuestion(11);
int questionNum = getNumQuestions();
Expand Down
Loading

0 comments on commit 0cfadef

Please sign in to comment.