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..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 @@ -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 +1380,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 +1397,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..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 @@ -5,11 +5,13 @@ import { TimezoneService } from '../../../services/timezone.service'; import { FeedbackSession, FeedbackSessionPublishStatus, FeedbackSessionSubmissionStatus, } from '../../../types/api-output'; -import { ResponseVisibleSetting, SessionVisibleSetting } from '../../../types/api-request'; +import { InstructorPermissionRole, ResponseVisibleSetting, SessionVisibleSetting } from '../../../types/api-request'; +import { SortBy, SortOrder } from '../../../types/sort-properties'; 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,7 +57,41 @@ 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, }; @@ -65,6 +101,12 @@ describe('ExtensionConfirmModalComponent', () => { 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,6 +132,387 @@ 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]; + 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(); + expect(setStudentTableDataSpy).not.toHaveBeenCalled(); + expect(setInstructorTableDataSpy).not.toHaveBeenCalled(); + }); + + it('test setStudentRowData', () => { + component.selectedStudents = [studentModel1, studentModel2]; + 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 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); + }); + + 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 = [ + [ + { 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); + }); + + 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', () => { + sortBy = SortBy.SECTION_NAME; + sortOrder = SortOrder.ASC; + const event = { sortBy, sortOrder }; + + const spy = jest.spyOn(component.sortStudentListEvent, 'emit'); + component.sortStudentColumnsByEventHandler(event); + expect(spy).toHaveBeenCalledTimes(1); + }); + + it('test sortBy for instructors', () => { + sortBy = SortBy.RESPONDENT_NAME; + sortOrder = SortOrder.DESC; + const event = { sortBy, sortOrder }; + + const spy = jest.spyOn(component.sortInstructorListEvent, 'emit'); + component.sortInstructorsColumnsByEventHandler(event); + expect(spy).toHaveBeenCalledTimes(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();