Skip to content

Commit

Permalink
Merge branch 'master' into Add-unit-test-to-comment-edit-form-component
Browse files Browse the repository at this point in the history
  • Loading branch information
weiquu authored Nov 30, 2023
2 parents 2634b65 + e0c2032 commit 1bcd96b
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 65 deletions.
32 changes: 14 additions & 18 deletions src/e2e/java/teammates/e2e/pageobjects/FeedbackResultsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void verifyAnonymousResponseView(FeedbackQuestionAttributes question,
List<FeedbackResponseAttributes> expectedResponses,
boolean isGiverVisible) {
List<WebElement> anonymousViews = getAllResponseViews(question.getQuestionNumber()).stream()
.filter(v -> isAnonymous(v.findElement(By.id("response-recipient")).getText()))
.filter(v -> isAnonymous(v.findElement(By.className("response-recipient")).getText()))
.collect(Collectors.toList());
if (anonymousViews.isEmpty()) {
fail("No anonymous views found");
Expand Down Expand Up @@ -293,7 +293,8 @@ private boolean isRubricResponseEqual(WebElement responseField, FeedbackResponse
FeedbackRubricResponseDetails responseDetails = (FeedbackRubricResponseDetails) response.getResponseDetailsCopy();
List<Integer> answers = responseDetails.getAnswer();
for (int i = 0; i < answers.size(); i++) {
WebElement rubricRow = responseField.findElements(By.cssSelector("#rubric-answers tr")).get(i);
WebElement rubricTableBody = responseField.findElement(By.className("rubric-answers"));
WebElement rubricRow = rubricTableBody.findElements(By.cssSelector("tr")).get(i);
WebElement rubricCell = rubricRow.findElements(By.tagName("td")).get(answers.get(i) + 1);
if (rubricCell.findElements(By.className("fa-check")).size() == 0) {
return false;
Expand All @@ -308,7 +309,7 @@ private boolean isAnonymous(String identifier) {

private boolean isAnyAnonymousResponseEqual(FeedbackQuestionAttributes question, WebElement responseView,
FeedbackResponseAttributes response) {
List<WebElement> giverNames = responseView.findElements(By.id("response-giver"));
List<WebElement> giverNames = responseView.findElements(By.className("response-giver"));
List<WebElement> responseFields = getAllResponseFields(responseView);
for (int i = 0; i < giverNames.size(); i++) {
if (isAnonymous(giverNames.get(i).getText()) && isResponseEqual(question, responseFields.get(i), response)) {
Expand Down Expand Up @@ -465,21 +466,15 @@ private String getAdditionalInfo(int questionNum) {
}

private WebElement getGivenResponseField(int questionNum, String receiver) {
int recipientIndex = getGivenRecipientIndex(questionNum, receiver);
return getQuestionResponsesSection(questionNum)
.findElements(By.cssSelector("#given-responses tm-single-response"))
.get(recipientIndex);
}

private int getGivenRecipientIndex(int questionNum, String recipient) {
List<WebElement> recipients = getQuestionResponsesSection(questionNum)
.findElements(By.cssSelector("#given-responses #response-recipient"));
WebElement questionResponsesSection = getQuestionResponsesSection(questionNum);
WebElement givenResponses = questionResponsesSection.findElement(By.className("given-responses"));
List<WebElement> recipients = givenResponses.findElements(By.className("response-recipient"));
for (int i = 0; i < recipients.size(); i++) {
if (recipients.get(i).getText().split("To: ")[1].equals(recipient)) {
return i;
if (recipients.get(i).getText().split("To: ")[1].equals(receiver)) {
return givenResponses.findElements(By.tagName("tm-single-response")).get(i);
}
}
throw new AssertionError("Recipient not found: " + recipient);
throw new AssertionError("Recipient not found: " + receiver);
}

private String getAdditionalInfoString(FeedbackQuestionAttributes question) {
Expand Down Expand Up @@ -583,7 +578,7 @@ private boolean isCommentByResponseGiver(WebElement commentField) {
}

private String getCommentGiver(WebElement commentField) {
String commentGiverDescription = commentField.findElement(By.id("comment-giver-name")).getText();
String commentGiverDescription = commentField.findElement(By.className("comment-giver-name")).getText();
return commentGiverDescription.split(" commented")[0];
}

Expand All @@ -607,7 +602,7 @@ private WebElement getCommentField(int questionNum, String commentString) {
}

private int getGiverIndex(WebElement response, String giver) {
List<WebElement> givers = response.findElements(By.id("response-giver"));
List<WebElement> givers = response.findElements(By.className("response-giver"));
for (int i = 0; i < givers.size(); i++) {
if (givers.get(i).getText().contains(giver)) {
return i;
Expand All @@ -617,7 +612,8 @@ private int getGiverIndex(WebElement response, String giver) {
}

private int getRecipientIndex(int questionNum, String recipient) {
List<WebElement> recipients = getQuestionResponsesSection(questionNum).findElements(By.id("response-recipient"));
List<WebElement> recipients =
getQuestionResponsesSection(questionNum).findElements(By.className("response-recipient"));
for (int i = 0; i < recipients.size(); i++) {
if (recipients.get(i).getText().split("To: ")[1].equals(recipient)) {
return i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ private WebElement getTeamStats(WebElement parentPanel, int qnNum) {
}

private String getCommentGiver(WebElement commentField) {
String commentGiverDescription = commentField.findElement(By.id("comment-giver-name")).getText();
String commentGiverDescription = commentField.findElement(By.className("comment-giver-name")).getText();
return commentGiverDescription.split(" commented")[0];
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/teammates/logic/core/FeedbackSessionsLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -632,15 +633,17 @@ private void updateFeedbackSessionsDeadlinesForUser(String courseId, String emai
if (!instructorDeadlines.containsKey(emailAddress)) {
return;
}
deadlinesUpdater.accept(instructorDeadlines);
updateOptionsBuilder.withInstructorDeadlines(instructorDeadlines);
Map<String, Instant> newInstructorDeadlines = new HashMap<>(instructorDeadlines);
deadlinesUpdater.accept(newInstructorDeadlines);
updateOptionsBuilder.withInstructorDeadlines(newInstructorDeadlines);
} else {
Map<String, Instant> studentDeadlines = feedbackSession.getStudentDeadlines();
if (!studentDeadlines.containsKey(emailAddress)) {
return;
}
deadlinesUpdater.accept(studentDeadlines);
updateOptionsBuilder.withStudentDeadlines(studentDeadlines);
Map<String, Instant> newStudentDeadlines = new HashMap<>(studentDeadlines);
deadlinesUpdater.accept(newStudentDeadlines);
updateOptionsBuilder.withStudentDeadlines(newStudentDeadlines);
}
try {
fsDb.updateFeedbackSession(updateOptionsBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,9 @@ public void testUpdateFeedbackSessionsStudentDeadlinesWithNewEmail() {

fsLogic.updateFeedbackSessionsStudentDeadlinesWithNewEmail(courseId, oldEmailAddress, newEmailAddress);

// Clear the Objectify cache to fetch the latest FeedbackSessions from the db
clearObjectifyCache();

assertTrue(fsLogic.getFeedbackSessionsForCourse(courseId)
.stream()
.noneMatch(feedbackSessionAttributes -> feedbackSessionAttributes.getStudentDeadlines()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,8 @@ protected boolean doPutDocuments(DataBundle dataBundle) {
}
}

protected void clearObjectifyCache() {
ObjectifyService.ofy().clear();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Comment by response giver.
</span>
<span class="text-secondary" *ngIf="!isFeedbackParticipantComment">
<span id="comment-giver-name">{{ model.commentGiverName ? model.commentGiverName : model.originalComment.commentGiver }} commented at </span>
<span class="comment-giver-name">{{ model.commentGiverName ? model.commentGiverName : model.originalComment.commentGiver }} commented at </span>
<span class="ngb-tooltip-class" style="margin-right: .25rem;" [ngbTooltip]="model.originalComment.createdAt | formatDateDetail: model.timezone!">
{{ model.originalComment.createdAt | formatDateBrief: model.timezone! }}</span>
<ng-container *ngIf="model.originalComment.lastEditedAt && model.originalComment.lastEditedAt !== model.originalComment.createdAt">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ describe('ErrorReportComponent', () => {
expect(fixture).toMatchSnapshot();
});

it('should disable error reporting if CSRF error message is detected', () => {
component.errorMessage = 'Missing CSRF token.';
component.ngOnInit();
expect(component.errorReportEnabled).toBe(false);
});

});
Loading

0 comments on commit 1bcd96b

Please sign in to comment.