From 383cadffd51b5674bb40e6fad08bf6449a114310 Mon Sep 17 00:00:00 2001 From: Kenney Date: Sun, 8 Oct 2023 18:36:19 +1100 Subject: [PATCH 01/11] Added unit tests to CommentTableModal Component --- .../comment-table-modal.component.spec.ts | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) 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..5c271671749 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 @@ -7,7 +7,8 @@ import { RichTextEditorModule } from '../../rich-text-editor/rich-text-editor.mo 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 SpyInstance = jest.SpyInstance; import { CommentVisibilityControlNamePipe, CommentVisibilityTypeDescriptionPipe, CommentVisibilityTypeNamePipe, CommentVisibilityTypesJointNamePipe, @@ -52,4 +53,62 @@ describe('CommentTableModalComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should set isAddingNewComment to true in the model', () => { + component.model = { + commentRows: [], + newCommentRow: { + commentEditFormModel: { + commentText: '', + isUsingCustomVisibilities: false, + showCommentTo: [], + showGiverNameTo: [], + }, + isEditing: true, + }, + isAddingNewComment: false, + isReadOnly: false, + }; + fixture.detectChanges(); + component.ngOnChanges(); + expect(component.model.isAddingNewComment).toBe(true); + }); + + it('should trigger an event to delete comment from comments table', () => { + const triggerDeleteCommentSpy: SpyInstance = jest.spyOn(component.deleteCommentEvent, 'emit'); + component.triggerDeleteCommentEvent(1); + expect(triggerDeleteCommentSpy).toHaveBeenCalledWith(1); + }); + + it('should trigger an event to update comment from comments table', () => { + const triggerUpdateCommentSpy: SpyInstance = jest.spyOn(component.updateCommentEvent, 'emit'); + component.triggerUpdateCommentEvent(0); + expect(triggerUpdateCommentSpy).toHaveBeenCalledWith(0); + }); + + it('Should trigger an event to add a new comment to the comments table', () => { + const triggerSaveNewCommentEventSpy: SpyInstance = jest.spyOn(component.saveNewCommentEvent, 'emit'); + component.triggerSaveNewCommentEvent(); + expect(triggerSaveNewCommentEventSpy).toHaveBeenCalled(); + }); + + it('Should trigger an event to change the model of the form' , () => { + const testModel:CommentTableModel = { + commentRows: [], + newCommentRow: { + commentEditFormModel: { + commentText: '', + isUsingCustomVisibilities: false, + showCommentTo: [], + showGiverNameTo: [], + }, + isEditing: true, + }, + isAddingNewComment: false, + isReadOnly: false, + }; + const triggerModelChangeSpy: SpyInstance = jest.spyOn(component.modelChange, 'emit'); + component.triggerModelChange(testModel); + expect(triggerModelChangeSpy).toBeCalledWith(testModel); + }); }); From 2aec9303023973219eda1948fa3ffd21552d54a7 Mon Sep 17 00:00:00 2001 From: Kenney Date: Sun, 8 Oct 2023 19:43:16 +1100 Subject: [PATCH 02/11] Fixed test for CommentTableModalComponent --- .../comment-table-modal.component.spec.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 5c271671749..71167f1831e 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 @@ -50,12 +50,12 @@ describe('CommentTableModalComponent', () => { fixture.detectChanges(); }); - it('should create', () => { + it('should create a new instance', () => { expect(component).toBeTruthy(); }); it('should set isAddingNewComment to true in the model', () => { - component.model = { + const testModel: CommentTableModel = { commentRows: [], newCommentRow: { commentEditFormModel: { @@ -69,9 +69,10 @@ describe('CommentTableModalComponent', () => { isAddingNewComment: false, isReadOnly: false, }; - fixture.detectChanges(); + const ngOnChangesSpy: SpyInstance = jest.spyOn(component.modelChange,'emit') + component.model = testModel; component.ngOnChanges(); - expect(component.model.isAddingNewComment).toBe(true); + expect(ngOnChangesSpy).toHaveBeenCalledWith({...testModel,isAddingNewComment: true,}); }); it('should trigger an event to delete comment from comments table', () => { From a15172b53a20e882155d1df414c1327004a3a81c Mon Sep 17 00:00:00 2001 From: Kenney Date: Sun, 8 Oct 2023 19:43:16 +1100 Subject: [PATCH 03/11] Fixed test for CommentTableModalComponent --- .../comment-table-modal.component.spec.ts | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) 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 5c271671749..7c189a78082 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 @@ -50,12 +50,13 @@ describe('CommentTableModalComponent', () => { fixture.detectChanges(); }); - it('should create', () => { + it('should create a new instance', () => { expect(component).toBeTruthy(); }); it('should set isAddingNewComment to true in the model', () => { - component.model = { + const ngOnChangesSpy: SpyInstance = jest.spyOn(component.modelChange, 'emit'); + const testModel: CommentTableModel = { commentRows: [], newCommentRow: { commentEditFormModel: { @@ -69,31 +70,37 @@ describe('CommentTableModalComponent', () => { isAddingNewComment: false, isReadOnly: false, }; - fixture.detectChanges(); + component.model = testModel; component.ngOnChanges(); - expect(component.model.isAddingNewComment).toBe(true); + expect(ngOnChangesSpy).toHaveBeenCalledWith({ + ...testModel, + isAddingNewComment: true, + }); }); it('should trigger an event to delete comment from comments table', () => { - const triggerDeleteCommentSpy: SpyInstance = jest.spyOn(component.deleteCommentEvent, 'emit'); - component.triggerDeleteCommentEvent(1); - expect(triggerDeleteCommentSpy).toHaveBeenCalledWith(1); + const deleteCommentEventSpy: SpyInstance = jest.spyOn(component.deleteCommentEvent, 'emit'); + const testIndex = 1; + component.triggerDeleteCommentEvent(testIndex); + expect(deleteCommentEventSpy).toHaveBeenCalledWith(testIndex); }); it('should trigger an event to update comment from comments table', () => { - const triggerUpdateCommentSpy: SpyInstance = jest.spyOn(component.updateCommentEvent, 'emit'); - component.triggerUpdateCommentEvent(0); - expect(triggerUpdateCommentSpy).toHaveBeenCalledWith(0); + const updateCommentEventSpy: SpyInstance = jest.spyOn(component.updateCommentEvent, 'emit'); + const testIndex = 0; + component.triggerUpdateCommentEvent(testIndex); + expect(updateCommentEventSpy).toHaveBeenCalledWith(testIndex); }); - it('Should trigger an event to add a new comment to the comments table', () => { - const triggerSaveNewCommentEventSpy: SpyInstance = jest.spyOn(component.saveNewCommentEvent, 'emit'); + it('should trigger an event to add a new comment to the comments table', () => { + const saveNewCommentEventSpy: SpyInstance = jest.spyOn(component.saveNewCommentEvent, 'emit'); component.triggerSaveNewCommentEvent(); - expect(triggerSaveNewCommentEventSpy).toHaveBeenCalled(); + expect(saveNewCommentEventSpy).toHaveBeenCalled(); }); - it('Should trigger an event to change the model of the form' , () => { - const testModel:CommentTableModel = { + it('should trigger an event to change the model of the form', () => { + const changeFormModelEventSpy = jest.spyOn(component.modelChange, 'emit'); + const testModel: CommentTableModel = { commentRows: [], newCommentRow: { commentEditFormModel: { @@ -107,8 +114,7 @@ describe('CommentTableModalComponent', () => { isAddingNewComment: false, isReadOnly: false, }; - const triggerModelChangeSpy: SpyInstance = jest.spyOn(component.modelChange, 'emit'); component.triggerModelChange(testModel); - expect(triggerModelChangeSpy).toBeCalledWith(testModel); + expect(changeFormModelEventSpy).toHaveBeenCalledWith(testModel); }); }); From b40a72f743a70c1c530235ae5ffa31420c22414e Mon Sep 17 00:00:00 2001 From: Kenney Date: Wed, 18 Oct 2023 11:55:53 +1100 Subject: [PATCH 04/11] fix import on comment-table-modal-compenent tests --- .../comment-table-modal/comment-table-modal.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7c189a78082..dfce2c778a5 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,12 +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, CommentTableModel } from '../comment-table/comment-table.component'; -import SpyInstance = jest.SpyInstance; import { CommentVisibilityControlNamePipe, CommentVisibilityTypeDescriptionPipe, CommentVisibilityTypeNamePipe, CommentVisibilityTypesJointNamePipe, From e2e5233e67efd5e82507563099fb2ce8353f07ab Mon Sep 17 00:00:00 2001 From: Kenney Date: Thu, 19 Oct 2023 19:18:36 +1100 Subject: [PATCH 05/11] Made changes to CommentTableModalComponent tests --- .../comment-table-modal.component.spec.ts | 51 +++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) 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 94fbd1ff3be..925c2f93705 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 @@ -20,6 +20,21 @@ 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({ declarations: [ @@ -57,20 +72,6 @@ describe('CommentTableModalComponent', () => { it('should set isAddingNewComment to true in the model', () => { const ngOnChangesSpy: SpyInstance = jest.spyOn(component.modelChange, 'emit'); - const testModel: CommentTableModel = { - commentRows: [], - newCommentRow: { - commentEditFormModel: { - commentText: '', - isUsingCustomVisibilities: false, - showCommentTo: [], - showGiverNameTo: [], - }, - isEditing: true, - }, - isAddingNewComment: false, - isReadOnly: false, - }; component.model = testModel; component.ngOnChanges(); expect(ngOnChangesSpy).toHaveBeenCalledWith({ @@ -79,42 +80,28 @@ describe('CommentTableModalComponent', () => { }); }); - it('should trigger an event to delete comment from comments table', () => { + 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 trigger an event to update comment from comments table', () => { + 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 trigger an event to add a new comment to the comments table', () => { + it('should emit a SaveNewCommentEvent when triggerSaveNewCommentEvent is called', () => { const saveNewCommentEventSpy: SpyInstance = jest.spyOn(component.saveNewCommentEvent, 'emit'); component.triggerSaveNewCommentEvent(); expect(saveNewCommentEventSpy).toHaveBeenCalled(); }); - it('should trigger an event to change the model of the form', () => { + it('should emit a ChangeFormModelEvent when triggerChangeFormModelEvent is called', () => { const changeFormModelEventSpy = jest.spyOn(component.modelChange, 'emit'); - const testModel: CommentTableModel = { - commentRows: [], - newCommentRow: { - commentEditFormModel: { - commentText: '', - isUsingCustomVisibilities: false, - showCommentTo: [], - showGiverNameTo: [], - }, - isEditing: true, - }, - isAddingNewComment: false, - isReadOnly: false, - }; component.triggerModelChange(testModel); expect(changeFormModelEventSpy).toHaveBeenCalledWith(testModel); }); From c348c143b7fc5783ae559f88155519f76268c8b2 Mon Sep 17 00:00:00 2001 From: Kenney Date: Thu, 19 Oct 2023 19:24:07 +1100 Subject: [PATCH 06/11] Delete space on comment-table-modal.component tests --- .../comment-table-modal/comment-table-modal.component.spec.ts | 2 -- 1 file changed, 2 deletions(-) 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 925c2f93705..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 @@ -9,7 +9,6 @@ import { TeammatesCommonModule } from '../../teammates-common/teammates-common.m import { CommentEditFormComponent } from '../comment-edit-form/comment-edit-form.component'; import { CommentRowComponent } from '../comment-row/comment-row.component'; import { CommentTableComponent, CommentTableModel } from '../comment-table/comment-table.component'; - import { CommentVisibilityControlNamePipe, CommentVisibilityTypeDescriptionPipe, CommentVisibilityTypeNamePipe, CommentVisibilityTypesJointNamePipe, @@ -19,7 +18,6 @@ import { CommentTableModalComponent } from './comment-table-modal.component'; describe('CommentTableModalComponent', () => { let component: CommentTableModalComponent; let fixture: ComponentFixture; - const testModel: CommentTableModel = { commentRows: [], newCommentRow: { From 65917b317d0c32479987d5c67577ba43503385ba Mon Sep 17 00:00:00 2001 From: Kenney Date: Fri, 27 Oct 2023 17:39:05 +1100 Subject: [PATCH 07/11] Added Unit test for sessionEditFormComponent --- .../session-edit-form.component.spec.ts | 109 +++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) 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..13209598568 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 @@ -1,14 +1,17 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; -import { TimeFormat } from 'src/web/types/datetime-const'; +import { TimeFormat, DateFormat } from 'src/web/types/datetime-const'; import { TeammatesRouterModule } from '../teammates-router/teammates-router.module'; import { SessionEditFormComponent } from './session-edit-form.component'; import { SessionEditFormModule } from './session-edit-form.module'; +import { Course } from 'src/web/types/api-output'; +import { SessionEditFormMode } from './session-edit-form-model'; describe('SessionEditFormComponent', () => { let component: SessionEditFormComponent; let fixture: ComponentFixture; + const mockModalRef = { result: Promise.resolve(true) }; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ @@ -53,4 +56,108 @@ describe('SessionEditFormComponent', () => { expect(time.minute).toEqual(0); }); + it('should emit a model change event with the updated field when triggerModelChange is called', () => { + const field = 'courseId'; + const data = 'testId'; + const modelChangeSpy = jest.spyOn(component.modelChange, 'emit'); + component.triggerModelChange(field, data); + expect(modelChangeSpy).toHaveBeenCalledWith({ + ...component.model, + [field]: data, + }); + }); + + it('should configure submissionStartTime with minTimeForSubmissionStart when date is' + + 'earliest date and time is earlier than earliest possible time', () => { + + }); + + it('should trigger modelChange with field and date', () => { + + }); + + + it('should emit modelChange event when a valid course ID is provided', () => { + const newCourseId = 'testId1'; + const courseCandidates: Course[] = [ + { + courseId: 'testId1', + courseName: 'testCourse1', + timeZone: 'Asia/Singapore', + institute: 'Institute 1', + creationTimestamp: 1000000000000, + deletionTimestamp: 1500000000000, + }, + ]; + component.courseCandidates = courseCandidates; + const modelChangeSpy = jest.spyOn(component.modelChange, 'emit'); + component.courseIdChangeHandler(newCourseId); + expect(modelChangeSpy).toHaveBeenCalledWith({ + ...component.model, + courseId: newCourseId, + courseName: 'testCourse1', + timeZone: 'Asia/Singapore', + }); + }); + + it('should not emit modelChange event when no candidates are found', () => { + const newCourseId = 'testId1'; + const courseCandidates: Course[] = []; + component.courseCandidates = courseCandidates; + const modelChangeSpy = jest.spyOn(component.modelChange, 'emit'); + component.courseIdChangeHandler(newCourseId); + expect(modelChangeSpy).not.toHaveBeenCalled(); + }); + + it('should emit addNewSessionEvent when session edit form mode is ADD', () => { + component.formMode = SessionEditFormMode.ADD; + const addNewSessionSpy = jest.spyOn(component.addNewSessionEvent, 'emit'); + component.submitFormHandler(); + expect(addNewSessionSpy).toHaveBeenCalled(); + }); + + + + it('should emit a cancelEditingSession event after modal confimation', async () => { + const openConfirmationModalSpy = jest.spyOn((component as any).simpleModalService, 'openConfirmationModal').mockReturnValue(mockModalRef); + const cancelEditingSessionSpy = jest.spyOn(component.cancelEditingSessionEvent, 'emit'); + component.cancelHandler(); + await mockModalRef.result; + expect(openConfirmationModalSpy).toHaveBeenCalled(); + expect(cancelEditingSessionSpy).toHaveBeenCalled(); + }); + + it('should emit a deleteExistingSession event after modal confimation', async () => { + const openConfirmationModalSpy = jest.spyOn((component as any).simpleModalService, 'openConfirmationModal').mockReturnValue(mockModalRef); + const deleteExistingSessionSpy = jest.spyOn(component.deleteExistingSessionEvent, 'emit'); + component.deleteHandler(); + await mockModalRef.result; + expect(openConfirmationModalSpy).toHaveBeenCalled(); + expect(deleteExistingSessionSpy).toHaveBeenCalled(); + }); + + it('should emit editExistingSessionEvent when session edit form Mode is EDIT', () => { + component.formMode = SessionEditFormMode.EDIT; + const editExistingSessionSpy = jest.spyOn(component.editExistingSessionEvent, 'emit'); + component.submitFormHandler(); + expect(editExistingSessionSpy).toHaveBeenCalled(); + }); + + it('should emit copyCurrentSessionEvent when copyHandler is called', () => { + const copyCurrentSessionSpy = jest.spyOn(component.copyCurrentSessionEvent, 'emit'); + component.copyHandler(); + expect(copyCurrentSessionSpy).toHaveBeenCalled(); + }); + + it('should emit copyOtherSessionsEvent when copyOthersHandler is called', () => { + const copyOtherSessionsSpy = jest.spyOn(component.copyOtherSessionsEvent, 'emit'); + component.copyOthersHandler(); + expect(copyOtherSessionsSpy).toHaveBeenCalled(); + }); + + it('should emit closeEditFormEvent when closeEditFormHandler is called', () => { + const closeEditFormSpy = jest.spyOn(component.closeEditFormEvent, 'emit'); + component.closeEditFormHandler(); + expect(closeEditFormSpy).toHaveBeenCalled(); + }); }); From a4fab4f514e7cf049a20f73206f255ba5bbe307a Mon Sep 17 00:00:00 2001 From: Kenney Date: Fri, 27 Oct 2023 18:34:56 +1100 Subject: [PATCH 08/11] reverted sessionEditFormComponent tests --- .../session-edit-form.component.spec.ts | 111 +----------------- 1 file changed, 2 insertions(+), 109 deletions(-) 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 13209598568..6a8820ac394 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 @@ -1,17 +1,14 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; -import { TimeFormat, DateFormat } from 'src/web/types/datetime-const'; +import { TimeFormat } from 'src/web/types/datetime-const'; import { TeammatesRouterModule } from '../teammates-router/teammates-router.module'; import { SessionEditFormComponent } from './session-edit-form.component'; import { SessionEditFormModule } from './session-edit-form.module'; -import { Course } from 'src/web/types/api-output'; -import { SessionEditFormMode } from './session-edit-form-model'; describe('SessionEditFormComponent', () => { let component: SessionEditFormComponent; let fixture: ComponentFixture; - const mockModalRef = { result: Promise.resolve(true) }; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ @@ -56,108 +53,4 @@ describe('SessionEditFormComponent', () => { expect(time.minute).toEqual(0); }); - it('should emit a model change event with the updated field when triggerModelChange is called', () => { - const field = 'courseId'; - const data = 'testId'; - const modelChangeSpy = jest.spyOn(component.modelChange, 'emit'); - component.triggerModelChange(field, data); - expect(modelChangeSpy).toHaveBeenCalledWith({ - ...component.model, - [field]: data, - }); - }); - - it('should configure submissionStartTime with minTimeForSubmissionStart when date is' - + 'earliest date and time is earlier than earliest possible time', () => { - - }); - - it('should trigger modelChange with field and date', () => { - - }); - - - it('should emit modelChange event when a valid course ID is provided', () => { - const newCourseId = 'testId1'; - const courseCandidates: Course[] = [ - { - courseId: 'testId1', - courseName: 'testCourse1', - timeZone: 'Asia/Singapore', - institute: 'Institute 1', - creationTimestamp: 1000000000000, - deletionTimestamp: 1500000000000, - }, - ]; - component.courseCandidates = courseCandidates; - const modelChangeSpy = jest.spyOn(component.modelChange, 'emit'); - component.courseIdChangeHandler(newCourseId); - expect(modelChangeSpy).toHaveBeenCalledWith({ - ...component.model, - courseId: newCourseId, - courseName: 'testCourse1', - timeZone: 'Asia/Singapore', - }); - }); - - it('should not emit modelChange event when no candidates are found', () => { - const newCourseId = 'testId1'; - const courseCandidates: Course[] = []; - component.courseCandidates = courseCandidates; - const modelChangeSpy = jest.spyOn(component.modelChange, 'emit'); - component.courseIdChangeHandler(newCourseId); - expect(modelChangeSpy).not.toHaveBeenCalled(); - }); - - it('should emit addNewSessionEvent when session edit form mode is ADD', () => { - component.formMode = SessionEditFormMode.ADD; - const addNewSessionSpy = jest.spyOn(component.addNewSessionEvent, 'emit'); - component.submitFormHandler(); - expect(addNewSessionSpy).toHaveBeenCalled(); - }); - - - - it('should emit a cancelEditingSession event after modal confimation', async () => { - const openConfirmationModalSpy = jest.spyOn((component as any).simpleModalService, 'openConfirmationModal').mockReturnValue(mockModalRef); - const cancelEditingSessionSpy = jest.spyOn(component.cancelEditingSessionEvent, 'emit'); - component.cancelHandler(); - await mockModalRef.result; - expect(openConfirmationModalSpy).toHaveBeenCalled(); - expect(cancelEditingSessionSpy).toHaveBeenCalled(); - }); - - it('should emit a deleteExistingSession event after modal confimation', async () => { - const openConfirmationModalSpy = jest.spyOn((component as any).simpleModalService, 'openConfirmationModal').mockReturnValue(mockModalRef); - const deleteExistingSessionSpy = jest.spyOn(component.deleteExistingSessionEvent, 'emit'); - component.deleteHandler(); - await mockModalRef.result; - expect(openConfirmationModalSpy).toHaveBeenCalled(); - expect(deleteExistingSessionSpy).toHaveBeenCalled(); - }); - - it('should emit editExistingSessionEvent when session edit form Mode is EDIT', () => { - component.formMode = SessionEditFormMode.EDIT; - const editExistingSessionSpy = jest.spyOn(component.editExistingSessionEvent, 'emit'); - component.submitFormHandler(); - expect(editExistingSessionSpy).toHaveBeenCalled(); - }); - - it('should emit copyCurrentSessionEvent when copyHandler is called', () => { - const copyCurrentSessionSpy = jest.spyOn(component.copyCurrentSessionEvent, 'emit'); - component.copyHandler(); - expect(copyCurrentSessionSpy).toHaveBeenCalled(); - }); - - it('should emit copyOtherSessionsEvent when copyOthersHandler is called', () => { - const copyOtherSessionsSpy = jest.spyOn(component.copyOtherSessionsEvent, 'emit'); - component.copyOthersHandler(); - expect(copyOtherSessionsSpy).toHaveBeenCalled(); - }); - - it('should emit closeEditFormEvent when closeEditFormHandler is called', () => { - const closeEditFormSpy = jest.spyOn(component.closeEditFormEvent, 'emit'); - component.closeEditFormHandler(); - expect(closeEditFormSpy).toHaveBeenCalled(); - }); -}); +}); \ No newline at end of file From 1c2478c7974058d27561f13009f9fb1fe9bd25ed Mon Sep 17 00:00:00 2001 From: Kenney Date: Fri, 27 Oct 2023 18:49:35 +1100 Subject: [PATCH 09/11] fixed issues on session-edit-form-component tests --- .../session-edit-form/session-edit-form.component.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 6a8820ac394..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); }); - -}); \ No newline at end of file +}); From 9849a51853467ce6e0e2e450700a51a23d2706a6 Mon Sep 17 00:00:00 2001 From: Kenney Date: Sat, 28 Oct 2023 19:21:33 +1100 Subject: [PATCH 10/11] fixed spacing on sessioneditformcomponent tests --- .../session-edit-form/session-edit-form.component.spec.ts | 1 + 1 file changed, 1 insertion(+) 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 7d8acd9e033..076b0e406ba 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,4 +52,5 @@ describe('SessionEditFormComponent', () => { expect(time.hour).toEqual(21); expect(time.minute).toEqual(0); }); + }); From 25bb6832937ff27ad2ae5a62acd85da2bb904857 Mon Sep 17 00:00:00 2001 From: Kenney Date: Sat, 28 Oct 2023 19:24:02 +1100 Subject: [PATCH 11/11] fixed spacing on sessioneditformcomponent tests --- .../session-edit-form/session-edit-form.component.spec.ts | 1 - 1 file changed, 1 deletion(-) 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 076b0e406ba..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); }); - });