Skip to content

Commit

Permalink
[#11693] Student submitting MCQ question: comments are not loading (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelfangjw authored Apr 3, 2022
1 parent 5759349 commit 53e2206
Showing 3 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*/
Original file line number Diff line number Diff line change
@@ -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,14 +1149,36 @@ 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;
const commentSpy: SpyInstance = jest.spyOn(feedbackResponseCommentService, 'updateComment')
.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);
Original file line number Diff line number Diff line change
@@ -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);
}),
);
}

0 comments on commit 53e2206

Please sign in to comment.