From 53e2206dcb00e8d387024b8315f6781fd2bc62f7 Mon Sep 17 00:00:00 2001 From: Samuel Fang Date: Sun, 3 Apr 2022 12:32:16 +0800 Subject: [PATCH] [#11693] Student submitting MCQ question: comments are not loading (#11699) --- .../comment-row/comment-row.component.ts | 3 +- .../session-submission-page.component.spec.ts | 30 +++++++++++++++++-- .../session-submission-page.component.ts | 28 ++++++++++++----- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/web/app/components/comment-box/comment-row/comment-row.component.ts b/src/web/app/components/comment-box/comment-row/comment-row.component.ts index 66c35929914..8e8b973f433 100755 --- a/src/web/app/components/comment-box/comment-row/comment-row.component.ts +++ b/src/web/app/components/comment-box/comment-row/comment-row.component.ts @@ -18,8 +18,9 @@ import { CommentRowMode } from './comment-row.mode'; * Model for a comment row. */ export interface CommentRowModel { - // original comment can be null under ADD mode + // original comment and recipient identifier can be null under ADD mode originalComment?: FeedbackResponseComment; + originalRecipientIdentifier?: string; /** * Timezone of the original comment. */ diff --git a/src/web/app/pages-session/session-submission-page/session-submission-page.component.spec.ts b/src/web/app/pages-session/session-submission-page/session-submission-page.component.spec.ts index d3db6dd8dc4..8fcb7291e02 100644 --- a/src/web/app/pages-session/session-submission-page/session-submission-page.component.spec.ts +++ b/src/web/app/pages-session/session-submission-page/session-submission-page.component.spec.ts @@ -129,6 +129,7 @@ describe('SessionSubmissionPageComponent', () => { isValid: true, commentByGiver: { originalComment: testComment, + originalRecipientIdentifier: 'barry-harris-id', commentEditFormModel: { commentText: 'comment text here', isUsingCustomVisibilities: false, @@ -149,6 +150,7 @@ describe('SessionSubmissionPageComponent', () => { isValid: true, commentByGiver: { originalComment: testComment, + originalRecipientIdentifier: 'recipient-identifier', commentEditFormModel: { commentText: '', isUsingCustomVisibilities: false, @@ -210,6 +212,7 @@ describe('SessionSubmissionPageComponent', () => { isValid: true, commentByGiver: { originalComment: testComment, + originalRecipientIdentifier: 'barry-harris-id', commentEditFormModel: { commentText: 'comment text', isUsingCustomVisibilities: false, @@ -1133,7 +1136,8 @@ describe('SessionSubmissionPageComponent', () => { .mockReturnValue(of(testComment)); component.createCommentRequest(testSubmissionForm).subscribe(() => { - expect(testSubmissionForm.commentByGiver).toEqual(component.getCommentModel(testComment)); + expect(testSubmissionForm.commentByGiver).toEqual( + component.getCommentModel(testComment, testSubmissionForm.recipientIdentifier)); }); expect(commentSpy).toHaveBeenCalledTimes(1); @@ -1145,6 +1149,27 @@ describe('SessionSubmissionPageComponent', () => { { key: testQueryParams.key, moderatedperson: '' }); }); + it('should create comment request to create new comment when submission form has original comment' + + 'with different original recipient', () => { + const testSubmissionForm: FeedbackResponseRecipientSubmissionFormModel = deepCopy(testMcqRecipientSubmissionForm); + testSubmissionForm.commentByGiver!.originalRecipientIdentifier = 'other-recipient-identifier'; + const commentSpy: SpyInstance = jest.spyOn(feedbackResponseCommentService, 'createComment') + .mockReturnValue(of(testComment)); + + component.createCommentRequest(testSubmissionForm).subscribe(() => { + expect(testSubmissionForm.commentByGiver).toEqual( + component.getCommentModel(testComment, testSubmissionForm.recipientIdentifier)); + }); + + expect(commentSpy).toHaveBeenCalledTimes(1); + expect(commentSpy).toHaveBeenLastCalledWith({ + commentText: 'comment text here', + showCommentTo: [], + showGiverNameTo: [], + }, testMcqRecipientSubmissionForm.responseId, Intent.STUDENT_SUBMISSION, + { key: testQueryParams.key, moderatedperson: '' }); + }); + it('should create comment request to update existing comment when submission form has original comment', () => { const testSubmissionForm: FeedbackResponseRecipientSubmissionFormModel = deepCopy(testMcqRecipientSubmissionForm); const expectedId: any = testMcqRecipientSubmissionForm.commentByGiver?.originalComment?.feedbackResponseCommentId; @@ -1152,7 +1177,8 @@ describe('SessionSubmissionPageComponent', () => { .mockReturnValue(of(testComment)); component.createCommentRequest(testSubmissionForm).subscribe(() => { - expect(testSubmissionForm.commentByGiver).toEqual(component.getCommentModel(testComment)); + expect(testSubmissionForm.commentByGiver).toEqual( + component.getCommentModel(testComment, testSubmissionForm.recipientIdentifier)); }); expect(commentSpy).toHaveBeenCalledTimes(1); diff --git a/src/web/app/pages-session/session-submission-page/session-submission-page.component.ts b/src/web/app/pages-session/session-submission-page/session-submission-page.component.ts index 7e1732101d2..7db4b668736 100644 --- a/src/web/app/pages-session/session-submission-page/session-submission-page.component.ts +++ b/src/web/app/pages-session/session-submission-page/session-submission-page.component.ts @@ -545,7 +545,8 @@ export class SessionSubmissionPageComponent implements OnInit, AfterViewInit { isValid: true, }; if (matchedExistingResponse && matchedExistingResponse.giverComment) { - submissionForm.commentByGiver = this.getCommentModel(matchedExistingResponse.giverComment); + submissionForm.commentByGiver = this.getCommentModel( + matchedExistingResponse.giverComment, recipient.recipientIdentifier); } model.recipientSubmissionForms.push(submissionForm); }); @@ -557,12 +558,17 @@ export class SessionSubmissionPageComponent implements OnInit, AfterViewInit { model.customNumberOfEntitiesToGiveFeedbackTo - existingResponses.responses.length; existingResponses.responses.forEach((response: FeedbackResponse) => { - model.recipientSubmissionForms.push({ + const submissionForm: FeedbackResponseRecipientSubmissionFormModel = { recipientIdentifier: response.recipientIdentifier, responseDetails: response.responseDetails, responseId: response.feedbackResponseId, isValid: true, - }); + }; + if (response.giverComment) { + submissionForm.commentByGiver = this.getCommentModel( + response.giverComment, response.recipientIdentifier); + } + model.recipientSubmissionForms.push(submissionForm); }); // generate empty submission forms @@ -582,9 +588,10 @@ export class SessionSubmissionPageComponent implements OnInit, AfterViewInit { /** * Gets the comment model for a given comment. */ - getCommentModel(comment: FeedbackResponseComment): CommentRowModel { + getCommentModel(comment: FeedbackResponseComment, recipientIdentifier: string): CommentRowModel { return { originalComment: comment, + originalRecipientIdentifier: recipientIdentifier, commentEditFormModel: { commentText: comment.commentText, // the participant comment shall not use custom visibilities @@ -737,8 +744,11 @@ export class SessionSubmissionPageComponent implements OnInit, AfterViewInit { return of({}); } - if (!recipientSubmissionFormModel.commentByGiver.originalComment) { - // comment is new + const isSameRecipient = recipientSubmissionFormModel.recipientIdentifier + === recipientSubmissionFormModel.commentByGiver.originalRecipientIdentifier; + + if (!recipientSubmissionFormModel.commentByGiver.originalComment || !isSameRecipient) { + // comment is new or original comment deleted because recipient has changed if (recipientSubmissionFormModel.commentByGiver.commentEditFormModel.commentText === '') { // new comment is empty @@ -758,7 +768,8 @@ export class SessionSubmissionPageComponent implements OnInit, AfterViewInit { moderatedperson: this.moderatedPerson, }).pipe( tap((comment: FeedbackResponseComment) => { - recipientSubmissionFormModel.commentByGiver = this.getCommentModel(comment); + recipientSubmissionFormModel.commentByGiver = this.getCommentModel( + comment, recipientSubmissionFormModel.recipientIdentifier); }), ); } @@ -790,7 +801,8 @@ export class SessionSubmissionPageComponent implements OnInit, AfterViewInit { moderatedperson: this.moderatedPerson, }).pipe( tap((comment: FeedbackResponseComment) => { - recipientSubmissionFormModel.commentByGiver = this.getCommentModel(comment); + recipientSubmissionFormModel.commentByGiver = this.getCommentModel( + comment, recipientSubmissionFormModel.recipientIdentifier); }), ); }