Skip to content

Commit

Permalink
Repurpose student feedback results E2E test case to general and add i…
Browse files Browse the repository at this point in the history
…nstructor test case
  • Loading branch information
wkurniawan07 committed Sep 19, 2021
1 parent 32b1f8b commit bc1c308
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
import teammates.common.datatransfer.questions.FeedbackRubricQuestionDetails;
import teammates.common.util.AppUrl;
import teammates.common.util.Const;
import teammates.e2e.pageobjects.StudentFeedbackResultsPage;
import teammates.e2e.pageobjects.FeedbackResultsPage;

/**
* SUT: {@link Const.WebPageURIs#STUDENT_SESSION_RESULTS_PAGE}.
* SUT: {@link Const.WebPageURIs#SESSION_RESULTS_PAGE}.
*/
public class StudentFeedbackResultsPageE2ETest extends BaseE2ETestCase {
private StudentFeedbackResultsPage resultsPage;
public class FeedbackResultsPageE2ETest extends BaseE2ETestCase {
private FeedbackResultsPage resultsPage;
private FeedbackSessionAttributes openSession;
private List<FeedbackQuestionAttributes> questions = new ArrayList<>();

@Override
protected void prepareTestData() {
testData = loadDataBundle("/StudentFeedbackResultsPageE2ETest.json");
testData = loadDataBundle("/FeedbackResultsPageE2ETest.json");
removeAndRestoreDataBundle(testData);

openSession = testData.feedbackSessions.get("Open Session");
Expand All @@ -50,7 +50,7 @@ public void testAll() {
.withStudentEmail(unregistered.getEmail())
.withSessionName(openSession.getFeedbackSessionName())
.withRegistrationKey(getKeyForStudent(unregistered));
resultsPage = getNewPageInstance(url, StudentFeedbackResultsPage.class);
resultsPage = getNewPageInstance(url, FeedbackResultsPage.class);

resultsPage.verifyFeedbackSessionDetails(openSession);

Expand All @@ -62,7 +62,7 @@ public void testAll() {
url = createUrl(Const.WebPageURIs.STUDENT_SESSION_RESULTS_PAGE)
.withCourseId(openSession.getCourseId())
.withSessionName(openSession.getFeedbackSessionName());
resultsPage = loginToPage(url, StudentFeedbackResultsPage.class, student.getGoogleId());
resultsPage = loginToPage(url, FeedbackResultsPage.class, student.getGoogleId());

resultsPage.verifyFeedbackSessionDetails(openSession);

Expand Down Expand Up @@ -95,6 +95,23 @@ public void testAll() {
verifyCommentDetails(2, testData.feedbackResponseComments.get("qn2Comment2"), student);
verifyCommentDetails(3, testData.feedbackResponseComments.get("qn3Comment1"), student);
verifyCommentDetails(3, testData.feedbackResponseComments.get("qn3Comment2"), student);

______TS("registered instructor: can access results");
logout();
InstructorAttributes instructor = testData.instructors.get("FRes.instr");
url = createUrl(Const.WebPageURIs.INSTRUCTOR_SESSION_RESULTS_PAGE)
.withCourseId(openSession.getCourseId())
.withSessionName(openSession.getFeedbackSessionName());
resultsPage = loginToPage(url, FeedbackResultsPage.class, instructor.getGoogleId());

resultsPage.verifyFeedbackSessionDetails(openSession);

______TS("registered instructor: questions with responses loaded");
verifyLoadedQuestions(instructor);

______TS("verify responses");
questions.forEach(question -> verifyResponseDetails(instructor, question));

}

private void verifyLoadedQuestions(StudentAttributes currentStudent) {
Expand All @@ -108,6 +125,17 @@ private void verifyLoadedQuestions(StudentAttributes currentStudent) {
});
}

private void verifyLoadedQuestions(InstructorAttributes currentInstructor) {
Set<FeedbackQuestionAttributes> qnsWithResponse = getQnsWithResponses(currentInstructor);
questions.forEach(qn -> {
if (qnsWithResponse.contains(qn)) {
resultsPage.verifyQuestionDetails(qn.getQuestionNumber(), qn);
} else {
resultsPage.verifyQuestionNotPresent(qn.getQuestionNumber());
}
});
}

private void verifyResponseDetails(StudentAttributes currentStudent, FeedbackQuestionAttributes question) {
List<FeedbackResponseAttributes> givenResponses = getGivenResponses(currentStudent, question);
List<FeedbackResponseAttributes> otherResponses = getOtherResponses(currentStudent, question);
Expand All @@ -116,6 +144,14 @@ private void verifyResponseDetails(StudentAttributes currentStudent, FeedbackQue
resultsPage.verifyResponseDetails(question, givenResponses, otherResponses, visibleGivers, visibleRecipients);
}

private void verifyResponseDetails(InstructorAttributes currentInstructor, FeedbackQuestionAttributes question) {
List<FeedbackResponseAttributes> givenResponses = getGivenResponses(currentInstructor, question);
List<FeedbackResponseAttributes> otherResponses = getOtherResponses(currentInstructor, question);
Set<String> visibleGivers = getVisibleGivers(currentInstructor, question);
Set<String> visibleRecipients = getVisibleRecipients(currentInstructor, question);
resultsPage.verifyResponseDetails(question, givenResponses, otherResponses, visibleGivers, visibleRecipients);
}

private void verifyCommentDetails(int questionNum, FeedbackResponseCommentAttributes comment,
StudentAttributes currentStudent) {
String editor = "";
Expand All @@ -136,6 +172,13 @@ private Set<FeedbackQuestionAttributes> getQnsWithResponses(StudentAttributes cu
.collect(Collectors.toSet());
}

private Set<FeedbackQuestionAttributes> getQnsWithResponses(InstructorAttributes currentInstructor) {
return questions.stream()
.filter(qn -> getGivenResponses(currentInstructor, qn).size() > 0
|| getOtherResponses(currentInstructor, qn).size() > 0)
.collect(Collectors.toSet());
}

private List<FeedbackResponseAttributes> getGivenResponses(StudentAttributes currentStudent,
FeedbackQuestionAttributes question) {
List<FeedbackResponseAttributes> givenResponses = testData.feedbackResponses.values().stream()
Expand All @@ -145,6 +188,15 @@ private List<FeedbackResponseAttributes> getGivenResponses(StudentAttributes cur
return editIdentifiers(currentStudent, givenResponses);
}

private List<FeedbackResponseAttributes> getGivenResponses(InstructorAttributes currentInstructor,
FeedbackQuestionAttributes question) {
List<FeedbackResponseAttributes> givenResponses = testData.feedbackResponses.values().stream()
.filter(f -> f.getFeedbackQuestionId().equals(Integer.toString(question.getQuestionNumber()))
&& f.getGiver().equals(currentInstructor.getEmail()))
.collect(Collectors.toList());
return editIdentifiers(currentInstructor, givenResponses);
}

private List<FeedbackResponseAttributes> getOtherResponses(StudentAttributes currentStudent,
FeedbackQuestionAttributes question) {
Set<String> visibleResponseGivers = getRelevantUsers(currentStudent, question.getShowResponsesTo());
Expand Down Expand Up @@ -180,18 +232,65 @@ private List<FeedbackResponseAttributes> getOtherResponses(StudentAttributes cur
return editIdentifiers(currentStudent, otherResponses);
}

private List<FeedbackResponseAttributes> getOtherResponses(InstructorAttributes currentInstructor,
FeedbackQuestionAttributes question) {
Set<String> visibleResponseGivers = getRelevantUsersForInstructors(question.getShowResponsesTo());
visibleResponseGivers.add(currentInstructor.getEmail());

List<FeedbackResponseAttributes> questionResponses = testData.feedbackResponses.values().stream()
.filter(fr -> fr.getFeedbackQuestionId().equals(Integer.toString(question.getQuestionNumber())))
.collect(Collectors.toList());

List<FeedbackResponseAttributes> selfEvaluationResponses = questionResponses.stream()
.filter(fr -> fr.getGiver().equals(currentInstructor.getEmail())
&& fr.getRecipient().equals(currentInstructor.getEmail()))
.collect(Collectors.toList());

List<FeedbackResponseAttributes> responsesByOthers = questionResponses.stream()
.filter(fr -> !fr.getGiver().equals(currentInstructor.getEmail())
&& visibleResponseGivers.contains(fr.getGiver()))
.collect(Collectors.toList());

List<FeedbackResponseAttributes> responsesToSelf = new ArrayList<>();
if (visibleResponseGivers.contains("RECEIVER") || visibleResponseGivers.contains("INSTRUCTORS")) {
responsesToSelf = questionResponses.stream()
.filter(fr -> !fr.getGiver().equals(currentInstructor.getEmail())
&& fr.getRecipient().equals(currentInstructor.getEmail()))
.collect(Collectors.toList());
}

List<FeedbackResponseAttributes> otherResponses = new ArrayList<>();
otherResponses.addAll(selfEvaluationResponses);
otherResponses.addAll(responsesByOthers);
otherResponses.addAll(responsesToSelf);

return editIdentifiers(currentInstructor, otherResponses);
}

private Set<String> getVisibleGivers(StudentAttributes currentStudent, FeedbackQuestionAttributes question) {
return getRelevantUsers(currentStudent, question.getShowGiverNameTo()).stream()
.map(user -> getIdentifier(currentStudent, user))
.collect(Collectors.toSet());
}

private Set<String> getVisibleGivers(InstructorAttributes currentInstructor, FeedbackQuestionAttributes question) {
return getRelevantUsersForInstructors(question.getShowGiverNameTo()).stream()
.map(user -> getIdentifier(currentInstructor, user))
.collect(Collectors.toSet());
}

private Set<String> getVisibleRecipients(StudentAttributes currentStudent, FeedbackQuestionAttributes question) {
return getRelevantUsers(currentStudent, question.getShowRecipientNameTo()).stream()
.map(user -> getIdentifier(currentStudent, user))
.collect(Collectors.toSet());
}

private Set<String> getVisibleRecipients(InstructorAttributes currentInstructor, FeedbackQuestionAttributes question) {
return getRelevantUsersForInstructors(question.getShowRecipientNameTo()).stream()
.map(user -> getIdentifier(currentInstructor, user))
.collect(Collectors.toSet());
}

private Set<String> getRelevantUsers(StudentAttributes giver, List<FeedbackParticipantType> relevantParticipants) {
Set<String> relevantUsers = new HashSet<>();
List<StudentAttributes> students = new ArrayList<>();
Expand All @@ -210,6 +309,17 @@ private Set<String> getRelevantUsers(StudentAttributes giver, List<FeedbackParti
return relevantUsers;
}

private Set<String> getRelevantUsersForInstructors(List<FeedbackParticipantType> relevantParticipants) {
Set<String> relevantUsers = new HashSet<>();
if (relevantParticipants.contains(FeedbackParticipantType.RECEIVER)) {
relevantUsers.add("RECEIVER");
}
if (relevantParticipants.contains(FeedbackParticipantType.INSTRUCTORS)) {
relevantUsers.add("INSTRUCTORS");
}
return relevantUsers;
}

private Set<StudentAttributes> getOtherTeammates(StudentAttributes currentStudent) {
return testData.students.values().stream()
.filter(s -> s.getTeam().equals(currentStudent.getTeam())
Expand All @@ -234,6 +344,16 @@ private List<FeedbackResponseAttributes> editIdentifiers(StudentAttributes curre
return editedResponses;
}

private List<FeedbackResponseAttributes> editIdentifiers(InstructorAttributes currentInstructor,
List<FeedbackResponseAttributes> responses) {
List<FeedbackResponseAttributes> editedResponses = deepCopyResponses(responses);
editedResponses.forEach(fr -> {
fr.setGiver(getIdentifier(currentInstructor, fr.getGiver()));
fr.setRecipient(getIdentifier(currentInstructor, fr.getRecipient()));
});
return editedResponses;
}

private String getIdentifier(StudentAttributes currentStudent, String user) {
if (currentStudent.getEmail().equals(user)) {
return "You";
Expand All @@ -254,6 +374,23 @@ private String getIdentifier(StudentAttributes currentStudent, String user) {
return identifier;
}

private String getIdentifier(InstructorAttributes currentInstructor, String user) {
if (currentInstructor.getEmail().equals(user)) {
return "You";
}
if (Const.GENERAL_QUESTION.equals(user)) {
return Const.USER_NOBODY_TEXT;
}
String identifier = getInstructorName(user);
if (identifier == null) {
identifier = getStudentName(user);
}
if (identifier == null) {
identifier = user;
}
return identifier;
}

private String getStudentName(String studentEmail) {
return testData.students.values().stream()
.filter(s -> s.getEmail().equals(studentEmail))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
import teammates.common.util.Const;

/**
* Page Object Model for student feedback results page.
* Page Object Model for feedback results page.
*/
public class StudentFeedbackResultsPage extends AppPage {
public class FeedbackResultsPage extends AppPage {
private static final String CURRENT_STUDENT_IDENTIFIER = "You";

@FindBy(id = "course-id")
Expand All @@ -53,7 +53,7 @@ public class StudentFeedbackResultsPage extends AppPage {
@FindBy(id = "closing-time")
private WebElement sessionClosingTime;

public StudentFeedbackResultsPage(Browser browser) {
public FeedbackResultsPage(Browser browser) {
super(browser);
}

Expand Down Expand Up @@ -176,11 +176,13 @@ private void verifyResponseForRecipient(FeedbackQuestionAttributes question, Str
boolean isGiverVisible = visibleGivers.contains(response.getGiver())
|| (visibleGivers.contains("RECEIVER") && response.getRecipient().equals(CURRENT_STUDENT_IDENTIFIER))
|| response.getGiver().equals(CURRENT_STUDENT_IDENTIFIER);
boolean isGiverVisibleToInstructor = question.getRecipientType() == FeedbackParticipantType.INSTRUCTORS
&& visibleGivers.contains("INSTRUCTORS");
if (isRecipientVisible) {
int recipientIndex = getRecipientIndex(question.getQuestionNumber(), recipient);
WebElement responseView = responseViews.get(recipientIndex);
List<WebElement> responsesFields = getAllResponseFields(responseView);
if (isGiverVisible) {
if (isGiverVisible || isGiverVisibleToInstructor) {
int giverIndex = getGiverIndex(responseView, response.getGiver());
assertTrue(isResponseEqual(question, responsesFields.get(giverIndex), response));
} else {
Expand Down
Loading

0 comments on commit bc1c308

Please sign in to comment.