diff --git a/src/web/app/components/comment-box/comment-table-modal/comment-table-modal.component.spec.ts b/src/web/app/components/comment-box/comment-table-modal/comment-table-modal.component.spec.ts index 6a3ba9a1fbb..24eb2612ebc 100644 --- a/src/web/app/components/comment-box/comment-table-modal/comment-table-modal.component.spec.ts +++ b/src/web/app/components/comment-box/comment-table-modal/comment-table-modal.component.spec.ts @@ -3,11 +3,12 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { FormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap'; +import SpyInstance = jest.SpyInstance; import { RichTextEditorModule } from '../../rich-text-editor/rich-text-editor.module'; import { TeammatesCommonModule } from '../../teammates-common/teammates-common.module'; import { CommentEditFormComponent } from '../comment-edit-form/comment-edit-form.component'; import { CommentRowComponent } from '../comment-row/comment-row.component'; -import { CommentTableComponent } from '../comment-table/comment-table.component'; +import { CommentTableComponent, CommentTableModel } from '../comment-table/comment-table.component'; import { CommentVisibilityControlNamePipe, CommentVisibilityTypeDescriptionPipe, CommentVisibilityTypeNamePipe, CommentVisibilityTypesJointNamePipe, @@ -17,6 +18,20 @@ import { CommentTableModalComponent } from './comment-table-modal.component'; describe('CommentTableModalComponent', () => { let component: CommentTableModalComponent; let fixture: ComponentFixture; + const testModel: CommentTableModel = { + commentRows: [], + newCommentRow: { + commentEditFormModel: { + commentText: '', + isUsingCustomVisibilities: false, + showCommentTo: [], + showGiverNameTo: [], + }, + isEditing: true, + }, + isAddingNewComment: false, + isReadOnly: false, + }; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ @@ -52,4 +67,40 @@ describe('CommentTableModalComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should set isAddingNewComment to true in the model', () => { + const ngOnChangesSpy: SpyInstance = jest.spyOn(component.modelChange, 'emit'); + component.model = testModel; + component.ngOnChanges(); + expect(ngOnChangesSpy).toHaveBeenCalledWith({ + ...testModel, + isAddingNewComment: true, + }); + }); + + it('should emit a DeleteCommentEvent with the correct index when triggerDeleteCommentEvent is called', () => { + const deleteCommentEventSpy: SpyInstance = jest.spyOn(component.deleteCommentEvent, 'emit'); + const testIndex = 1; + component.triggerDeleteCommentEvent(testIndex); + expect(deleteCommentEventSpy).toHaveBeenCalledWith(testIndex); + }); + + it('should emit an UpdateCommentEvent with the correct index when triggerUpdateCommentEvent is called', () => { + const updateCommentEventSpy: SpyInstance = jest.spyOn(component.updateCommentEvent, 'emit'); + const testIndex = 0; + component.triggerUpdateCommentEvent(testIndex); + expect(updateCommentEventSpy).toHaveBeenCalledWith(testIndex); + }); + + it('should emit a SaveNewCommentEvent when triggerSaveNewCommentEvent is called', () => { + const saveNewCommentEventSpy: SpyInstance = jest.spyOn(component.saveNewCommentEvent, 'emit'); + component.triggerSaveNewCommentEvent(); + expect(saveNewCommentEventSpy).toHaveBeenCalled(); + }); + + it('should emit a ChangeFormModelEvent when triggerChangeFormModelEvent is called', () => { + const changeFormModelEventSpy = jest.spyOn(component.modelChange, 'emit'); + component.triggerModelChange(testModel); + expect(changeFormModelEventSpy).toHaveBeenCalledWith(testModel); + }); }); diff --git a/src/web/app/components/session-edit-form/session-edit-form.component.spec.ts b/src/web/app/components/session-edit-form/session-edit-form.component.spec.ts index 3ee97b6f228..7d8acd9e033 100644 --- a/src/web/app/components/session-edit-form/session-edit-form.component.spec.ts +++ b/src/web/app/components/session-edit-form/session-edit-form.component.spec.ts @@ -52,5 +52,4 @@ describe('SessionEditFormComponent', () => { expect(time.hour).toEqual(21); expect(time.minute).toEqual(0); }); - });