Skip to content

Commit

Permalink
[#12048] Migrate FeedbackNumScaleQuestionE2ETest (#12940)
Browse files Browse the repository at this point in the history
* Migrate num scale e2e

* Fix team id

* Fix bugs
  • Loading branch information
marquestye authored Apr 9, 2024
1 parent 8f43cc8 commit b9ccd4f
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package teammates.e2e.cases.sql;

import org.testng.annotations.Test;

import teammates.common.datatransfer.questions.FeedbackNumericalScaleQuestionDetails;
import teammates.common.datatransfer.questions.FeedbackNumericalScaleResponseDetails;
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 NumScale questions.
*/
public class FeedbackNumScaleQuestionE2ETest extends BaseFeedbackQuestionE2ETest {

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

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

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

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

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

______TS("edit question");
questionDetails = (FeedbackNumericalScaleQuestionDetails) loadedQuestion.getQuestionDetailsCopy();
FeedbackNumericalScaleQuestionDetails newQuestionDetails =
(FeedbackNumericalScaleQuestionDetails) questionDetails.getDeepCopy();
newQuestionDetails.setMinScale(0);
newQuestionDetails.setStep(1);
newQuestionDetails.setMaxScale(100);
loadedQuestion.setQuestionDetails(newQuestionDetails);
feedbackEditPage.editNumScaleQuestion(2, newQuestionDetails);
feedbackEditPage.waitForPageToLoad();

feedbackEditPage.verifyNumScaleQuestionDetails(2, newQuestionDetails);
verifyPresentInDatabase(loadedQuestion);

// reset question details to original
loadedQuestion.setQuestionDetails(questionDetails);
}

@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.verifyNumScaleQuestion(1, receiver.getTeamName(),
(FeedbackNumericalScaleQuestionDetails) question.getQuestionDetailsCopy());

______TS("submit response");
FeedbackResponse response = getResponse(question, receiver, 5.4);
feedbackSubmitPage.fillNumScaleResponse(1, receiver.getTeamName(), response);
feedbackSubmitPage.clickSubmitQuestionButton(1);

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

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

// ______TS("edit response");
// response = getResponse(question, receiver, 10.0);
// feedbackSubmitPage.fillNumScaleResponse(1, receiver.getTeamName(), response);
// feedbackSubmitPage.clickSubmitQuestionButton(1);

// feedbackSubmitPage = getFeedbackSubmitPage();
// feedbackSubmitPage.verifyNumScaleResponse(1, receiver.getTeamName(), response);
// verifyPresentInDatabase(response);
}

private FeedbackResponse getResponse(FeedbackQuestion feedbackQuestion, Student receiver, Double answer) {
FeedbackNumericalScaleResponseDetails details = new FeedbackNumericalScaleResponseDetails();
details.setAnswer(answer);
return FeedbackResponse.makeResponse(
feedbackQuestion, student.getEmail(), null, receiver.getTeamName(), null, details);
}

}
13 changes: 13 additions & 0 deletions src/e2e/java/teammates/e2e/pageobjects/FeedbackSubmitPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,26 @@ public void fillNumScaleResponse(int qnNumber, String recipient, FeedbackRespons
fillTextBox(getNumScaleInput(qnNumber, recipient), Double.toString(responseDetails.getAnswer()));
}

public void fillNumScaleResponse(int qnNumber, String recipient, FeedbackResponse response) {
FeedbackNumericalScaleResponseDetails responseDetails =
(FeedbackNumericalScaleResponseDetails) response.getFeedbackResponseDetailsCopy();
fillTextBox(getNumScaleInput(qnNumber, recipient), Double.toString(responseDetails.getAnswer()));
}

public void verifyNumScaleResponse(int qnNumber, String recipient, FeedbackResponseAttributes response) {
FeedbackNumericalScaleResponseDetails responseDetails =
(FeedbackNumericalScaleResponseDetails) response.getResponseDetailsCopy();
assertEquals(getNumScaleInput(qnNumber, recipient).getAttribute("value"),
getDoubleString(responseDetails.getAnswer()));
}

public void verifyNumScaleResponse(int qnNumber, String recipient, FeedbackResponse response) {
FeedbackNumericalScaleResponseDetails responseDetails =
(FeedbackNumericalScaleResponseDetails) response.getFeedbackResponseDetailsCopy();
assertEquals(getNumScaleInput(qnNumber, recipient).getAttribute("value"),
getDoubleString(responseDetails.getAnswer()));
}

public void verifyConstSumQuestion(int qnNumber, String recipient,
FeedbackConstantSumQuestionDetails questionDetails) {
if (!questionDetails.isDistributeToRecipients()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,16 @@ public void addNumScaleQuestion(FeedbackQuestionAttributes feedbackQuestion) {
clickSaveNewQuestionButton();
}

public void addNumScaleQuestion(FeedbackQuestion feedbackQuestion) {
addNewQuestion(5);
int questionNum = getNumQuestions();
inputQuestionDetails(questionNum, feedbackQuestion);
FeedbackNumericalScaleQuestionDetails questionDetails =
(FeedbackNumericalScaleQuestionDetails) feedbackQuestion.getQuestionDetailsCopy();
inputNumScaleDetails(questionNum, questionDetails);
clickSaveNewQuestionButton();
}

public void editNumScaleQuestion(int questionNum, FeedbackNumericalScaleQuestionDetails questionDetails) {
clickEditQuestionButton(questionNum);
inputNumScaleDetails(questionNum, questionDetails);
Expand Down
Loading

0 comments on commit b9ccd4f

Please sign in to comment.