From 4f5d8c21bc1a83d85e5f881db47cbca6bcf0195d Mon Sep 17 00:00:00 2001 From: Zixun Ma Date: Wed, 25 Oct 2023 13:16:17 +1100 Subject: [PATCH 1/6] All coverages are 100%, except branch, 94% --- ...nsion-confirm-modal.component.spec.ts.snap | 1335 ++++++++++++++++- .../extension-confirm-modal.component.spec.ts | 304 +++- 2 files changed, 1605 insertions(+), 34 deletions(-) diff --git a/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap b/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap index 13d30c3cc91..cd174149d0a 100644 --- a/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap +++ b/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap @@ -1,5 +1,743 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`ExtensionConfirmModalComponent Test ExtentionModalType.DELETE branch 1`] = ` + +
+ + +
+ +
+
+`; + +exports[`ExtensionConfirmModalComponent Test ExtentionModalType.SESSION_DELETE branch 1`] = ` + +
+ + +
+ +
+
+`; + exports[`ExtensionConfirmModalComponent should snap with the extended students and instructors 1`] = ` +
+ + +
+ +
+
+`; + +exports[`ExtensionConfirmModalComponent use ngOnInit to initialise 1`] = ` + will be applied to the following - 3 + 1 student(s) and - 0 + 1 instructor(s): @@ -192,16 +1378,16 @@ exports[`ExtensionConfirmModalComponent should snap with the extended students a - Test Section 1 + Test Section 3 - Test Section 1 + Test Section 3 - Test Student 1 + Test Student 3 - testStudent1@gmail.com + testStudent3@gmail.com @@ -209,37 +1395,126 @@ exports[`ExtensionConfirmModalComponent should snap with the extended students a + + + + +
+

+ Instructors +

+ + + - - - - - + + + + + + -
- Test Section 2 - - Test Section 2 - - Test Student 2 - - testStudent2@gmail.com - - - 5 Apr 2000 2:00:00 - - + + + + + + + +
- Test Section 3 - - Test Section 3 + Test InstructorManager 3 - Test Student 3 + testInstructorManager3@gmail.com - testStudent3@gmail.com + + Manager + diff --git a/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts b/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts index 9f859d63cd3..7580d2545c8 100644 --- a/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts +++ b/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts @@ -2,14 +2,16 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { TimezoneService } from '../../../services/timezone.service'; +import { SortBy, SortOrder } from '../../../types/sort-properties'; import { FeedbackSession, FeedbackSessionPublishStatus, FeedbackSessionSubmissionStatus, } from '../../../types/api-output'; -import { ResponseVisibleSetting, SessionVisibleSetting } from '../../../types/api-request'; +import { InstructorPermissionRole, ResponseVisibleSetting, SessionVisibleSetting } from '../../../types/api-request'; import { + InstructorExtensionTableColumnModel, StudentExtensionTableColumnModel, } from '../../pages-instructor/instructor-session-individual-extension-page/extension-table-column-model'; -import { ExtensionConfirmModalComponent } from './extension-confirm-modal.component'; +import { ExtensionConfirmModalComponent, ExtensionModalType } from './extension-confirm-modal.component'; import { ExtensionConfirmModalModule } from './extension-confirm-modal.module'; describe('ExtensionConfirmModalComponent', () => { @@ -55,16 +57,56 @@ describe('ExtensionConfirmModalComponent', () => { teamName: 'Test Section 3', name: 'Test Student 3', email: 'testStudent3@gmail.com', - extensionDeadline: 1510000000000, + extensionDeadline: 1520000000000, hasExtension: true, isSelected: true, }; + const instructorModel1: InstructorExtensionTableColumnModel = { + name: 'Test InstructorTutor 1', + email: 'testInstructorTutor1@gmail.com', + role: InstructorPermissionRole.INSTRUCTOR_PERMISSION_ROLE_TUTOR, + extensionDeadline: 1000000000, + hasExtension: true, + isSelected: false, + } + + const instructorModel2: InstructorExtensionTableColumnModel = { + name: 'Test Instructor 2', + email: 'testInstructor2@gmail.com', + extensionDeadline: 1100000000, + hasExtension: true, + isSelected: false, + } + + const instructorModel3: InstructorExtensionTableColumnModel = { + name: 'Test InstructorManager 3', + email: 'testInstructorManager3@gmail.com', + role: InstructorPermissionRole.INSTRUCTOR_PERMISSION_ROLE_MANAGER, + extensionDeadline: 1200000000, + hasExtension: true, + isSelected: true, + } + + const instructorModel4: InstructorExtensionTableColumnModel = { + name: 'Test Instructor 4', + email: 'testInstructor4@gmail.com', + extensionDeadline: 1300000000, + hasExtension: true, + isSelected: true, + } + const testTimeString = '5 Apr 2000 2:00:00'; let component: ExtensionConfirmModalComponent; let fixture: ComponentFixture; let timeZoneService: TimezoneService; + let sortBy: SortBy; + let sortOrder: SortOrder; + let students: StudentExtensionTableColumnModel[]; + let instructors: InstructorExtensionTableColumnModel[]; + let sortedStudents: StudentExtensionTableColumnModel[]; + let sortedInstructors: InstructorExtensionTableColumnModel[]; beforeEach( waitForAsync(() => { @@ -90,8 +132,262 @@ describe('ExtensionConfirmModalComponent', () => { it('should snap with the extended students and instructors', () => { component.studentData = [studentModel1, studentModel2, studentModel3]; + component.instructorData = [instructorModel2, instructorModel1, instructorModel3]; + component.extensionTimestamp = testFeedbackSession.submissionEndTimestamp; + fixture.detectChanges(); + expect(fixture).toMatchSnapshot(); + }); + + it('use ngOnInit to initialise', () => { + component.selectedStudents = [studentModel3]; + component.selectedInstructors = [instructorModel3]; + component.ngOnInit(); + component.extensionTimestamp = testFeedbackSession.submissionEndTimestamp; + fixture.detectChanges(); + expect(fixture).toMatchSnapshot(); + }); + + it('test emit from onConfirm()', () => { + const spy = jest.spyOn(component.confirmExtensionCallbackEvent, 'emit'); + component.onConfirm(); + expect(spy).toBeCalledTimes(1); + }); + + it('test sortBy for students', () => { + sortBy = SortBy.SECTION_NAME; + sortOrder = SortOrder.ASC; + const event = {sortBy, sortOrder}; + + const spy = jest.spyOn(component.sortStudentListEvent, 'emit'); + component.sortStudentColumnsByEventHandler(event); + expect(spy).toBeCalledTimes(1); + }); + + it('test sortBy for students only', () => { + sortBy = SortBy.RESPONDENT_NAME; + sortOrder = SortOrder.DESC; + const event = {sortBy, sortOrder}; + + const spy = jest.spyOn(component.sortInstructorListEvent, 'emit'); + component.sortInstructorsColumnsByEventHandler(event); + expect(spy).toBeCalledTimes(1); + }); + + + /** + * Tests for getAriaSortStudent + */ + it('test getAriaSortStudent return none', () => { + sortBy = SortBy.TEAM_NAME; + const value = component.getAriaSortStudent(sortBy); + expect(value).toEqual('none'); + }); + + it('test getAriaSortStudent return ascending', () => { + sortBy = SortBy.SESSION_END_DATE; + component.sortStudentOrder = SortOrder.ASC; + const value = component.getAriaSortStudent(sortBy); + expect(value).toEqual('ascending'); + }); + + it('test getAriaSortStudent return descending', () => { + sortBy = SortBy.SESSION_END_DATE; + component.sortStudentOrder = SortOrder.DESC; + const value = component.getAriaSortStudent(sortBy); + expect(value).toEqual('descending'); + }); + + + /** + * Tests for getAriaSortInstructor + */ + it('test getAriaSortInstructor return none', () => { + sortBy = SortBy.RESPONDENT_NAME; + const value = component.getAriaSortInstructor(sortBy); + expect(value).toEqual('none'); + }); + + it('test getAriaSortInstructor return ascending', () => { + sortBy = SortBy.SESSION_END_DATE; + component.sortInstructorOrder = SortOrder.ASC; + const value = component.getAriaSortInstructor(sortBy); + expect(value).toEqual('ascending'); + }); + + it('test getAriaSortInstructor return descending', () => { + sortBy = SortBy.SESSION_END_DATE; + component.sortInstructorOrder = SortOrder.DESC; + const value = component.getAriaSortInstructor(sortBy); + expect(value).toEqual('descending'); + }); + + + /** + * Tests for sortStudentPanelBy + */ + beforeEach(() => { + students = [studentModel2, studentModel1, studentModel3]; + component.sortStudentOrder = SortOrder.ASC; + }) + + it('test sortStudentPanelsBy section_name', () => { + sortBy = SortBy.SECTION_NAME; + sortedStudents = students.sort(component.sortStudentPanelsBy(sortBy)); + expect(sortedStudents[0]).toEqual(studentModel1); + expect(sortedStudents[1]).toEqual(studentModel2); + expect(sortedStudents[2]).toEqual(studentModel3); + }); + + it('test sortStudentPanelsBy team_name', () => { + sortBy = SortBy.TEAM_NAME; + component.sortStudentOrder = SortOrder.DESC; + sortedStudents = students.sort(component.sortStudentPanelsBy(sortBy)); + expect(sortedStudents[0]).toEqual(studentModel3); + expect(sortedStudents[1]).toEqual(studentModel2); + expect(sortedStudents[2]).toEqual(studentModel1); + }); + + it('test sortStudentPanelsBy respondent_name', () => { + sortBy = SortBy.RESPONDENT_NAME; + sortedStudents = students.sort(component.sortStudentPanelsBy(sortBy)); + expect(sortedStudents[0]).toEqual(studentModel1); + expect(sortedStudents[1]).toEqual(studentModel2); + expect(sortedStudents[2]).toEqual(studentModel3); + }); + + it('test sortStudentPanelsBy respondent_email', () => { + sortBy = SortBy.RESPONDENT_EMAIL; + component.sortStudentOrder = SortOrder.DESC; + sortedStudents = students.sort(component.sortStudentPanelsBy(sortBy)); + expect(sortedStudents[0]).toEqual(studentModel3); + expect(sortedStudents[1]).toEqual(studentModel2); + expect(sortedStudents[2]).toEqual(studentModel1); + }); + + it('test sortStudentPanelsBy session_end_date', () => { + sortBy = SortBy.SESSION_END_DATE; + sortedStudents = students.sort(component.sortStudentPanelsBy(sortBy)); + expect(sortedStudents[0]).toEqual(studentModel1); + expect(sortedStudents[1]).toEqual(studentModel2); + expect(sortedStudents[2]).toEqual(studentModel3); + }); + + it('test sortStudentPanelsBy invalid sortBy', () => { + sortBy = SortBy.SESSION_COMPLETION_STATUS; + sortedStudents = students.sort(component.sortStudentPanelsBy(sortBy)); + expect(sortedStudents[0]).toEqual(studentModel2); + expect(sortedStudents[1]).toEqual(studentModel1); + expect(sortedStudents[2]).toEqual(studentModel3); + }); + + + /** + * Tests for sortInstructorPanelBy + */ + beforeEach(() => { + instructors = [instructorModel2, instructorModel4, instructorModel1, instructorModel3]; + component.sortInstructorOrder = SortOrder.DESC; + }) + + it('test sortInstructorPanelsBy respondent_name', () => { + sortBy = SortBy.RESPONDENT_NAME; + sortedInstructors = instructors.sort(component.sortInstructorPanelsBy(sortBy)); + expect(sortedInstructors[0]).toEqual(instructorModel1); + expect(sortedInstructors[1]).toEqual(instructorModel3); + expect(sortedInstructors[2]).toEqual(instructorModel4); + expect(sortedInstructors[3]).toEqual(instructorModel2); + }); + + it('test sortInstructorPanelsBy respondent_email', () => { + sortBy = SortBy.RESPONDENT_EMAIL; + component.sortInstructorOrder = SortOrder.ASC; + sortedInstructors = instructors.sort(component.sortInstructorPanelsBy(sortBy)); + expect(sortedInstructors[0]).toEqual(instructorModel2); + expect(sortedInstructors[1]).toEqual(instructorModel4); + expect(sortedInstructors[2]).toEqual(instructorModel3); + expect(sortedInstructors[3]).toEqual(instructorModel1); + }); + + it('test sortInstructorPanelsBy instructor_permission_role', () => { + sortBy = SortBy.INSTRUCTOR_PERMISSION_ROLE; + sortedInstructors = instructors.sort(component.sortInstructorPanelsBy(sortBy)); + expect(sortedInstructors[0]).toEqual(instructorModel2); + expect(sortedInstructors[1]).toEqual(instructorModel4); + expect(sortedInstructors[2]).toEqual(instructorModel3); + expect(sortedInstructors[3]).toEqual(instructorModel1); + }); + + it('test sortInstructorPanelsBy session_end_date', () => { + sortBy = SortBy.SESSION_END_DATE; + component.sortInstructorOrder = SortOrder.ASC; + sortedInstructors = instructors.sort(component.sortInstructorPanelsBy(sortBy)); + expect(sortedInstructors[0]).toEqual(instructorModel1); + expect(sortedInstructors[1]).toEqual(instructorModel2); + expect(sortedInstructors[2]).toEqual(instructorModel3); + expect(sortedInstructors[3]).toEqual(instructorModel4); + }); + + it('test sortInstructorPanelsBy invalid sortBy', () => { + sortBy = SortBy.SESSION_COMPLETION_STATUS; + sortedInstructors = instructors.sort(component.sortInstructorPanelsBy(sortBy)); + expect(sortedInstructors[0]).toEqual(instructorModel2); + expect(sortedInstructors[1]).toEqual(instructorModel4); + expect(sortedInstructors[2]).toEqual(instructorModel1); + expect(sortedInstructors[3]).toEqual(instructorModel3); + }); + + + /** + * Test ExtentionModalType.DELETE branch + */ + const studentModel4: StudentExtensionTableColumnModel = { + sectionName: 'Test Section 4', + teamName: 'Test Section 4', + name: 'Test Student 4', + email: 'testStudent4@gmail.com', + extensionDeadline: 1530000000000, + hasExtension: false, + isSelected: true, + }; + + it('Test ExtentionModalType.DELETE branch', () => { + component.modalType = ExtensionModalType.DELETE; + component.studentData = [studentModel4]; + component.instructorData = [instructorModel4]; + component.extensionTimestamp = testFeedbackSession.submissionEndTimestamp; + fixture.detectChanges(); + expect(fixture).toMatchSnapshot(); + }); + + + /** + * Test ExtentionModalType.SESSION_DELETE branch + */ + const instructorModel5: InstructorExtensionTableColumnModel = { + name: 'Test InstructorCustom 5', + email: 'testInstructorCustom5@gmail.com', + role: InstructorPermissionRole.INSTRUCTOR_PERMISSION_ROLE_CUSTOM, + extensionDeadline: 1250000000, + hasExtension: true, + isSelected: true, + } + + const studentModel5: StudentExtensionTableColumnModel = { + sectionName: 'Test Section 5', + teamName: 'Test Section 5', + name: 'Test Student 5', + email: 'testStudent5@gmail.com', + extensionDeadline: 1550000000000, + hasExtension: true, + isSelected: true, + } + + it('Test ExtentionModalType.SESSION_DELETE branch', () => { + component.modalType = ExtensionModalType.SESSION_DELETE; + component.studentData = [studentModel5]; + component.instructorData = [instructorModel5]; component.extensionTimestamp = testFeedbackSession.submissionEndTimestamp; fixture.detectChanges(); expect(fixture).toMatchSnapshot(); }); -}); +}); \ No newline at end of file From a18bc7cd5f9ab8e345c683e64a73b124168c325c Mon Sep 17 00:00:00 2001 From: Zixun Ma Date: Wed, 25 Oct 2023 14:14:45 +1100 Subject: [PATCH 2/6] lint format passed --- .../extension-confirm-modal.component.spec.ts | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts b/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts index 7580d2545c8..051b67011c9 100644 --- a/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts +++ b/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts @@ -2,11 +2,11 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { TimezoneService } from '../../../services/timezone.service'; -import { SortBy, SortOrder } from '../../../types/sort-properties'; import { FeedbackSession, FeedbackSessionPublishStatus, FeedbackSessionSubmissionStatus, } from '../../../types/api-output'; import { InstructorPermissionRole, ResponseVisibleSetting, SessionVisibleSetting } from '../../../types/api-request'; +import { SortBy, SortOrder } from '../../../types/sort-properties'; import { InstructorExtensionTableColumnModel, StudentExtensionTableColumnModel, @@ -69,7 +69,7 @@ describe('ExtensionConfirmModalComponent', () => { extensionDeadline: 1000000000, hasExtension: true, isSelected: false, - } + }; const instructorModel2: InstructorExtensionTableColumnModel = { name: 'Test Instructor 2', @@ -77,7 +77,7 @@ describe('ExtensionConfirmModalComponent', () => { extensionDeadline: 1100000000, hasExtension: true, isSelected: false, - } + }; const instructorModel3: InstructorExtensionTableColumnModel = { name: 'Test InstructorManager 3', @@ -86,7 +86,7 @@ describe('ExtensionConfirmModalComponent', () => { extensionDeadline: 1200000000, hasExtension: true, isSelected: true, - } + }; const instructorModel4: InstructorExtensionTableColumnModel = { name: 'Test Instructor 4', @@ -94,7 +94,7 @@ describe('ExtensionConfirmModalComponent', () => { extensionDeadline: 1300000000, hasExtension: true, isSelected: true, - } + }; const testTimeString = '5 Apr 2000 2:00:00'; @@ -150,30 +150,29 @@ describe('ExtensionConfirmModalComponent', () => { it('test emit from onConfirm()', () => { const spy = jest.spyOn(component.confirmExtensionCallbackEvent, 'emit'); component.onConfirm(); - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); }); it('test sortBy for students', () => { sortBy = SortBy.SECTION_NAME; sortOrder = SortOrder.ASC; - const event = {sortBy, sortOrder}; + const event = { sortBy, sortOrder }; const spy = jest.spyOn(component.sortStudentListEvent, 'emit'); component.sortStudentColumnsByEventHandler(event); - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); }); it('test sortBy for students only', () => { sortBy = SortBy.RESPONDENT_NAME; sortOrder = SortOrder.DESC; - const event = {sortBy, sortOrder}; + const event = { sortBy, sortOrder }; const spy = jest.spyOn(component.sortInstructorListEvent, 'emit'); component.sortInstructorsColumnsByEventHandler(event); - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); }); - /** * Tests for getAriaSortStudent */ @@ -189,7 +188,7 @@ describe('ExtensionConfirmModalComponent', () => { const value = component.getAriaSortStudent(sortBy); expect(value).toEqual('ascending'); }); - + it('test getAriaSortStudent return descending', () => { sortBy = SortBy.SESSION_END_DATE; component.sortStudentOrder = SortOrder.DESC; @@ -197,7 +196,6 @@ describe('ExtensionConfirmModalComponent', () => { expect(value).toEqual('descending'); }); - /** * Tests for getAriaSortInstructor */ @@ -221,15 +219,14 @@ describe('ExtensionConfirmModalComponent', () => { expect(value).toEqual('descending'); }); - /** * Tests for sortStudentPanelBy - */ + */ beforeEach(() => { students = [studentModel2, studentModel1, studentModel3]; component.sortStudentOrder = SortOrder.ASC; - }) - + }); + it('test sortStudentPanelsBy section_name', () => { sortBy = SortBy.SECTION_NAME; sortedStudents = students.sort(component.sortStudentPanelsBy(sortBy)); @@ -280,14 +277,13 @@ describe('ExtensionConfirmModalComponent', () => { expect(sortedStudents[2]).toEqual(studentModel3); }); - /** * Tests for sortInstructorPanelBy - */ + */ beforeEach(() => { instructors = [instructorModel2, instructorModel4, instructorModel1, instructorModel3]; component.sortInstructorOrder = SortOrder.DESC; - }) + }); it('test sortInstructorPanelsBy respondent_name', () => { sortBy = SortBy.RESPONDENT_NAME; @@ -336,7 +332,6 @@ describe('ExtensionConfirmModalComponent', () => { expect(sortedInstructors[3]).toEqual(instructorModel3); }); - /** * Test ExtentionModalType.DELETE branch */ @@ -359,7 +354,6 @@ describe('ExtensionConfirmModalComponent', () => { expect(fixture).toMatchSnapshot(); }); - /** * Test ExtentionModalType.SESSION_DELETE branch */ @@ -370,7 +364,7 @@ describe('ExtensionConfirmModalComponent', () => { extensionDeadline: 1250000000, hasExtension: true, isSelected: true, - } + }; const studentModel5: StudentExtensionTableColumnModel = { sectionName: 'Test Section 5', @@ -380,7 +374,7 @@ describe('ExtensionConfirmModalComponent', () => { extensionDeadline: 1550000000000, hasExtension: true, isSelected: true, - } + }; it('Test ExtentionModalType.SESSION_DELETE branch', () => { component.modalType = ExtensionModalType.SESSION_DELETE; @@ -390,4 +384,4 @@ describe('ExtensionConfirmModalComponent', () => { fixture.detectChanges(); expect(fixture).toMatchSnapshot(); }); -}); \ No newline at end of file +}); From cdc1768a58b932854f55c265aa2dee0259456d40 Mon Sep 17 00:00:00 2001 From: MatheuMa <139031917+MatheuMa@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:56:13 +1100 Subject: [PATCH 3/6] Update src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts Thank you for fixing this! Co-authored-by: Cedric Ong <67156011+cedricongjh@users.noreply.github.com> --- .../extension-confirm-modal.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts b/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts index 051b67011c9..ef7cb71bf35 100644 --- a/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts +++ b/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts @@ -163,7 +163,7 @@ describe('ExtensionConfirmModalComponent', () => { expect(spy).toHaveBeenCalledTimes(1); }); - it('test sortBy for students only', () => { + it('test sortBy for instructors', () => { sortBy = SortBy.RESPONDENT_NAME; sortOrder = SortOrder.DESC; const event = { sortBy, sortOrder }; From 8bdee539304942fb1375004fa639a02fd71ee7ab Mon Sep 17 00:00:00 2001 From: Zixun Ma Date: Thu, 26 Oct 2023 00:50:54 +1100 Subject: [PATCH 4/6] Added tests for every advice (and more --- ...nsion-confirm-modal.component.spec.ts.snap | 103 ++++++++++++ .../extension-confirm-modal.component.spec.ts | 153 ++++++++++++++++++ 2 files changed, 256 insertions(+) diff --git a/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap b/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap index cd174149d0a..85c7428162c 100644 --- a/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap +++ b/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap @@ -738,6 +738,107 @@ exports[`ExtensionConfirmModalComponent Test ExtentionModalType.SESSION_DELETE b `; +exports[`ExtensionConfirmModalComponent ngOnInit to initialise with empty arrays 1`] = ` + +
+ + +
+ +
+
+`; + exports[`ExtensionConfirmModalComponent should snap with the extended students and instructors 1`] = ` { it('use ngOnInit to initialise', () => { component.selectedStudents = [studentModel3]; component.selectedInstructors = [instructorModel3]; + const setStudentTableDataSpy = jest.spyOn(component, 'setStudentTableData'); + const setInstructorTableDataSpy = jest.spyOn(component, 'setInstructorTableData'); component.ngOnInit(); component.extensionTimestamp = testFeedbackSession.submissionEndTimestamp; fixture.detectChanges(); expect(fixture).toMatchSnapshot(); + expect(setStudentTableDataSpy).toHaveBeenCalled(); + expect(setInstructorTableDataSpy).toHaveBeenCalled(); + }); + + it('ngOnInit to initialise with empty arrays', () => { + component.selectedStudents = []; + component.selectedInstructors = []; + const setStudentTableDataSpy = jest.spyOn(component, 'setStudentTableData'); + const setInstructorTableDataSpy = jest.spyOn(component, 'setInstructorTableData'); + component.ngOnInit(); + component.extensionTimestamp = testFeedbackSession.submissionEndTimestamp; + fixture.detectChanges(); + expect(fixture).toMatchSnapshot(); + expect(setStudentTableDataSpy).not.toHaveBeenCalled(); + expect(setInstructorTableDataSpy).not.toHaveBeenCalled(); + }); + + it('test setStudentRowData', () => { + component.selectedStudents = [studentModel1, studentModel2]; + component.setStudentRowData(); + const expectedData = component.selectedStudents.map((studentData: StudentExtensionTableColumnModel) => { + const rowData: SortableTableCellData[] = [ + { + value: studentData.sectionName, + }, + { + value: studentData.teamName, + }, + { + value: studentData.name, + }, + { + value: studentData.email, + }, + { + value: studentData.extensionDeadline, + displayValue: component.dateDetailPipe.transform( + studentData.extensionDeadline, + component.feedbackSessionTimeZone), + }, + ]; + return rowData; + }); + expect(component.studentRowsData).toEqual(expectedData); + }); + + it('test setStudentColumnData', () => { + component.setStudentColumnData(); + const expectedData = [ + { + header: 'Section', + sortBy: SortBy.SECTION_NAME, + headerClass: 'student-sort-by-section', + }, + { + header: 'Team', + sortBy: SortBy.TEAM_NAME, + headerClass: 'student-sort-by-team', + }, + { + header: 'Name', + sortBy: SortBy.RESPONDENT_NAME, + headerClass: 'student-sort-by-name', + }, + { + header: 'Email', + sortBy: SortBy.RESPONDENT_EMAIL, + headerClass: 'student-sort-by-email', + }, + { + header: component.isDeleteModal() || component.isSessionDeleteModal() + ? 'Current Deadline' : 'Original Deadline', + sortBy: SortBy.SESSION_END_DATE, + headerClass: 'student-sort-by-deadline', + }, + ]; + expect(component.studentColumnsData).toEqual(expectedData); + }); + + it('test setStudentTableData', () => { + const setStudentColumnDataSpy = jest.spyOn(component, 'setStudentColumnData'); + const setStudentRowDataSpy = jest.spyOn(component, 'setStudentRowData'); + component.setStudentTableData(); + expect(setStudentColumnDataSpy).toHaveBeenCalled(); + expect(setStudentRowDataSpy).toHaveBeenCalled(); + }); + + it('test setInstructorRowData', () => { + component.selectedInstructors = [instructorModel1, instructorModel2]; + component.setInstructorRowData(); + const expectedData = component.selectedInstructors.map((instructorData: InstructorExtensionTableColumnModel) => { + const rowData: SortableTableCellData[] = [ + { + value: instructorData.name, + }, + { + value: instructorData.email, + }, + { + value: instructorData.role, + displayValue: instructorData.role + ? component.instructorRoleNamePipe.transform(instructorData.role) + : instructorData.role, + }, + { + value: instructorData.extensionDeadline, + displayValue: component.dateDetailPipe.transform( + instructorData.extensionDeadline, + component.feedbackSessionTimeZone), + }, + ]; + return rowData; + }); + expect(component.instructorRowsData).toEqual(expectedData); + }); + + it('test setInstructorColumnData', () => { + component.setInstructorColumnData(); + const expectedData = [ + { + header: 'Name', + sortBy: SortBy.RESPONDENT_NAME, + headerClass: 'instructor-sort-by-name', + }, + { + header: 'Email', + sortBy: SortBy.RESPONDENT_EMAIL, + headerClass: 'instructor-sort-by-email', + }, + { + header: 'Role', + sortBy: SortBy.INSTRUCTOR_PERMISSION_ROLE, + headerClass: 'instructor-sort-by-role', + }, + { + header: 'Original Deadline', // Adjust this based on your logic + sortBy: SortBy.SESSION_END_DATE, + headerClass: 'instructor-sort-by-deadline', + }, + ]; + expect(component.instructorColumnsData).toEqual(expectedData); + }); + + it('test setInstructorTableData', () => { + const setInstructorColumnDataSpy = jest.spyOn(component, 'setInstructorColumnData'); + const setInstructorRowDataSpy = jest.spyOn(component, 'setInstructorRowData'); + component.setInstructorTableData(); + expect(setInstructorColumnDataSpy).toHaveBeenCalled(); + expect(setInstructorRowDataSpy).toHaveBeenCalled(); }); it('test emit from onConfirm()', () => { const spy = jest.spyOn(component.confirmExtensionCallbackEvent, 'emit'); component.onConfirm(); expect(spy).toHaveBeenCalledTimes(1); + expect(component.isSubmitting).toBe(true); }); it('test sortBy for students', () => { From 047268ff62f41591e308ea98be7d5301048a53c2 Mon Sep 17 00:00:00 2001 From: Zixun Ma Date: Fri, 27 Oct 2023 16:29:51 +1100 Subject: [PATCH 5/6] StudentRow and InstructorRow optimised --- ...nsion-confirm-modal.component.spec.ts.snap | 101 ------------------ .../extension-confirm-modal.component.spec.ts | 80 ++++++-------- 2 files changed, 30 insertions(+), 151 deletions(-) diff --git a/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap b/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap index 85c7428162c..65c830436c0 100644 --- a/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap +++ b/src/web/app/components/extension-confirm-modal/__snapshots__/extension-confirm-modal.component.spec.ts.snap @@ -738,107 +738,6 @@ exports[`ExtensionConfirmModalComponent Test ExtentionModalType.SESSION_DELETE b `; -exports[`ExtensionConfirmModalComponent ngOnInit to initialise with empty arrays 1`] = ` - -
- - -
- -
-
-`; - exports[`ExtensionConfirmModalComponent should snap with the extended students and instructors 1`] = ` { const setStudentTableDataSpy = jest.spyOn(component, 'setStudentTableData'); const setInstructorTableDataSpy = jest.spyOn(component, 'setInstructorTableData'); component.ngOnInit(); - component.extensionTimestamp = testFeedbackSession.submissionEndTimestamp; - fixture.detectChanges(); - expect(fixture).toMatchSnapshot(); expect(setStudentTableDataSpy).not.toHaveBeenCalled(); expect(setInstructorTableDataSpy).not.toHaveBeenCalled(); }); @@ -168,29 +164,22 @@ describe('ExtensionConfirmModalComponent', () => { it('test setStudentRowData', () => { component.selectedStudents = [studentModel1, studentModel2]; component.setStudentRowData(); - const expectedData = component.selectedStudents.map((studentData: StudentExtensionTableColumnModel) => { - const rowData: SortableTableCellData[] = [ - { - value: studentData.sectionName, - }, - { - value: studentData.teamName, - }, - { - value: studentData.name, - }, - { - value: studentData.email, - }, - { - value: studentData.extensionDeadline, - displayValue: component.dateDetailPipe.transform( - studentData.extensionDeadline, - component.feedbackSessionTimeZone), - }, - ]; - return rowData; - }); + const expectedData = [ + [ + {"value": "Test Section 1"}, + {"value": "Test Section 1"}, + {"value": "Test Student 1"}, + {"value": "testStudent1@gmail.com"}, + {"displayValue": "5 Apr 2000 2:00:00", "value": 1500000000000} + ], + [ + {"value": "Test Section 2"}, + {"value": "Test Section 2"}, + {"value": "Test Student 2"}, + {"value": "testStudent2@gmail.com"}, + {"displayValue": "5 Apr 2000 2:00:00", "value": 1510000000000} + ] + ] expect(component.studentRowsData).toEqual(expectedData); }); @@ -238,29 +227,20 @@ describe('ExtensionConfirmModalComponent', () => { it('test setInstructorRowData', () => { component.selectedInstructors = [instructorModel1, instructorModel2]; component.setInstructorRowData(); - const expectedData = component.selectedInstructors.map((instructorData: InstructorExtensionTableColumnModel) => { - const rowData: SortableTableCellData[] = [ - { - value: instructorData.name, - }, - { - value: instructorData.email, - }, - { - value: instructorData.role, - displayValue: instructorData.role - ? component.instructorRoleNamePipe.transform(instructorData.role) - : instructorData.role, - }, - { - value: instructorData.extensionDeadline, - displayValue: component.dateDetailPipe.transform( - instructorData.extensionDeadline, - component.feedbackSessionTimeZone), - }, - ]; - return rowData; - }); + const expectedData = [ + [ + {"value": "Test InstructorTutor 1"}, + {"value": "testInstructorTutor1@gmail.com"}, + {"displayValue": "Tutor", "value": "INSTRUCTOR_PERMISSION_ROLE_TUTOR"}, + {"displayValue": "5 Apr 2000 2:00:00", "value": 1000000000} + ], + [ + {"value": "Test Instructor 2"}, + {"value": "testInstructor2@gmail.com"}, + {"displayValue": undefined, "value": undefined}, + {"displayValue": "5 Apr 2000 2:00:00", "value": 1100000000} + ] + ] expect(component.instructorRowsData).toEqual(expectedData); }); From 3ed638a077e5a46fcf9aa0e818a8fd039178ce07 Mon Sep 17 00:00:00 2001 From: Zixun Ma Date: Fri, 27 Oct 2023 16:43:01 +1100 Subject: [PATCH 6/6] changes according to lint --- .../extension-confirm-modal.component.spec.ts | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts b/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts index 7d9b853149f..8d0d764a238 100644 --- a/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts +++ b/src/web/app/components/extension-confirm-modal/extension-confirm-modal.component.spec.ts @@ -166,20 +166,20 @@ describe('ExtensionConfirmModalComponent', () => { component.setStudentRowData(); const expectedData = [ [ - {"value": "Test Section 1"}, - {"value": "Test Section 1"}, - {"value": "Test Student 1"}, - {"value": "testStudent1@gmail.com"}, - {"displayValue": "5 Apr 2000 2:00:00", "value": 1500000000000} + { value: 'Test Section 1' }, + { value: 'Test Section 1' }, + { value: 'Test Student 1' }, + { value: 'testStudent1@gmail.com' }, + { displayValue: '5 Apr 2000 2:00:00', value: 1500000000000 }, ], [ - {"value": "Test Section 2"}, - {"value": "Test Section 2"}, - {"value": "Test Student 2"}, - {"value": "testStudent2@gmail.com"}, - {"displayValue": "5 Apr 2000 2:00:00", "value": 1510000000000} - ] - ] + { value: 'Test Section 2' }, + { value: 'Test Section 2' }, + { value: 'Test Student 2' }, + { value: 'testStudent2@gmail.com' }, + { displayValue: '5 Apr 2000 2:00:00', value: 1510000000000 }, + ], + ]; expect(component.studentRowsData).toEqual(expectedData); }); @@ -229,18 +229,18 @@ describe('ExtensionConfirmModalComponent', () => { component.setInstructorRowData(); const expectedData = [ [ - {"value": "Test InstructorTutor 1"}, - {"value": "testInstructorTutor1@gmail.com"}, - {"displayValue": "Tutor", "value": "INSTRUCTOR_PERMISSION_ROLE_TUTOR"}, - {"displayValue": "5 Apr 2000 2:00:00", "value": 1000000000} + { value: 'Test InstructorTutor 1' }, + { value: 'testInstructorTutor1@gmail.com' }, + { displayValue: 'Tutor', value: 'INSTRUCTOR_PERMISSION_ROLE_TUTOR' }, + { displayValue: '5 Apr 2000 2:00:00', value: 1000000000 }, ], [ - {"value": "Test Instructor 2"}, - {"value": "testInstructor2@gmail.com"}, - {"displayValue": undefined, "value": undefined}, - {"displayValue": "5 Apr 2000 2:00:00", "value": 1100000000} - ] - ] + { value: 'Test Instructor 2' }, + { value: 'testInstructor2@gmail.com' }, + { displayValue: undefined, value: undefined }, + { displayValue: '5 Apr 2000 2:00:00', value: 1100000000 }, + ], + ]; expect(component.instructorRowsData).toEqual(expectedData); });