Skip to content

Commit

Permalink
[#12588] Test coverage improvements for InstructorResponsesViewBase (#…
Browse files Browse the repository at this point in the history
…13087)

* test coverage improvements for InstructorResponsesViewBase

* Lint fixes

* Update per-question-view-responses.component.spec.ts

* Fix for component tests

---------

Co-authored-by: Wei Qing <48304907+weiquu@users.noreply.github.com>
Co-authored-by: domoberzin <74132255+domoberzin@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 67628fb commit 6b7912c
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import SpyInstance = jest.SpyInstance;
import { PerQuestionViewResponsesComponent } from './per-question-view-responses.component';
import { FeedbackResponsesService } from '../../../../services/feedback-responses.service';
import testEventEmission from '../../../../test-helpers/test-event-emitter';
import {
CommentVisibilityType, FeedbackParticipantType, FeedbackQuestionType,
NumberOfEntitiesToGiveFeedbackToSetting,
Expand Down Expand Up @@ -143,4 +144,52 @@ describe('PerQuestionViewResponsesComponent', () => {
expect(JSON.stringify(component.responsesToShow[0]))
.toBe(JSON.stringify(responseOutput));
});

it('triggerDeleteCommentEvent: should emit correct responseID and index to deleteCommentEvent', () => {
let emittedID: string | undefined;
let emittedIndex: number | undefined;
testEventEmission(component.deleteCommentEvent, (val) => { emittedID = val.responseId; emittedIndex = val.index; });

component.triggerDeleteCommentEvent('testID', 5);
expect(emittedID).toBe('testID');
expect(emittedIndex).toBe(5);
});

it('triggerUpdateCommentEvent: should emit correct responseID and index to updateCommentEvent', () => {
let emittedID: string | undefined;
let emittedIndex: number | undefined;
testEventEmission(component.updateCommentEvent, (val) => { emittedID = val.responseId; emittedIndex = val.index; });

component.triggerUpdateCommentEvent('testID2', 6);
expect(emittedID).toBe('testID2');
expect(emittedIndex).toBe(6);
});

it('triggerSaveNewCommentEvent: should emit correct responseID to saveNewCommentEvent', () => {
let emittedID: string | undefined;
testEventEmission(component.saveNewCommentEvent, (responseId) => { emittedID = responseId; });

component.triggerSaveNewCommentEvent('testID3');
expect(emittedID).toBe('testID3');
});

it('triggerModelChangeForSingleResponse: should emit correct Record to instructorCommentTableModelChange', () => {
let emittedRecord: Record<string, CommentTableModel> | undefined;
testEventEmission(component.instructorCommentTableModelChange, (record) => { emittedRecord = record; });

const testRecord: Record<string, CommentTableModel> = { responseId: commentTableModel };

component.triggerModelChangeForSingleResponse('responseId', commentTableModel);
expect(emittedRecord).toEqual(testRecord);
});

it('triggerModelChange: should emit correct instructorCommentTableModel Record to triggerModelChange', () => {
let emittedRecord: Record<string, CommentTableModel> | undefined;
testEventEmission(component.instructorCommentTableModelChange, (record) => { emittedRecord = record; });

const testRecord: Record<string, CommentTableModel> = {};

component.triggerModelChange(testRecord);
expect(emittedRecord).toEqual(testRecord);
});
});

0 comments on commit 6b7912c

Please sign in to comment.