From 6778fa8ec2a91f2a7a972c2262c281e1ac4703af Mon Sep 17 00:00:00 2001 From: Respirayson Date: Sat, 3 Aug 2024 14:47:57 +0800 Subject: [PATCH] Update snapshots and fix linting --- .../copy-session-modal.component.spec.ts.snap | 2 + .../copy-session-modal.component.spec.ts | 74 +++++++++++++------ .../copy-session-modal.component.ts | 2 +- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/web/app/components/copy-session-modal/__snapshots__/copy-session-modal.component.spec.ts.snap b/src/web/app/components/copy-session-modal/__snapshots__/copy-session-modal.component.spec.ts.snap index d20cc648230..e3ebdc37d75 100644 --- a/src/web/app/components/copy-session-modal/__snapshots__/copy-session-modal.component.spec.ts.snap +++ b/src/web/app/components/copy-session-modal/__snapshots__/copy-session-modal.component.spec.ts.snap @@ -6,6 +6,7 @@ exports[`CopySessionModalComponent should snap with default fields 1`] = ` activeModal={[Function NgbActiveModal]} copyToCourseSet={[Function Set]} courseCandidates={[Function Array]} + isNameCollision="false" newFeedbackSessionName="" originalSessionName="" sessionToCopyCourseId="" @@ -97,6 +98,7 @@ exports[`CopySessionModalComponent should snap with some session and courses can activeModal={[Function NgbActiveModal]} copyToCourseSet={[Function Set]} courseCandidates={[Function Array]} + isNameCollision="false" newFeedbackSessionName={[Function String]} originalSessionName="" sessionToCopyCourseId={[Function String]} diff --git a/src/web/app/components/copy-session-modal/copy-session-modal.component.spec.ts b/src/web/app/components/copy-session-modal/copy-session-modal.component.spec.ts index 00fb3c33d76..2ac335674d1 100644 --- a/src/web/app/components/copy-session-modal/copy-session-modal.component.spec.ts +++ b/src/web/app/components/copy-session-modal/copy-session-modal.component.spec.ts @@ -146,34 +146,66 @@ describe('CopySessionModalComponent', () => { expect(component.copyToCourseSet.has(courseId)).toBe(false); }); - it('should update session name to "Copy of ..." when the same course is selected', () => { - component.newFeedbackSessionName = feedbackSessionToCopy.feedbackSessionName; - component.originalSessionName = feedbackSessionToCopy.feedbackSessionName; - component.sessionToCopyCourseId = courseSessionIn.courseId; - component.courseCandidates = [courseSessionIn, courseCopyTo]; - fixture.detectChanges(); + it('should detect name collision correctly', () => { + component.newFeedbackSessionName = 'Test Feedback Session'; + component.originalSessionName = 'Test Feedback Session'; + component.sessionToCopyCourseId = 'TestCourseID'; + component.select('TestCourseID'); + expect(component.isNameCollision).toBe(true); + }); - const options: DebugElement[] = fixture.debugElement.queryAll(By.css('input[type="checkbox"]')); - const firstOption: any = options[0]; - firstOption.triggerEventHandler('click', { target: firstOption.nativeElement }); - fixture.detectChanges(); + it('should not detect name collision when new name is different', () => { + component.newFeedbackSessionName = 'New Feedback Session'; + component.originalSessionName = 'Test Feedback Session'; + component.sessionToCopyCourseId = 'TestCourseID'; + component.select('TestCourseID'); + expect(component.isNameCollision).toBe(false); + }); - expect(component.newFeedbackSessionName).toBe(`Copy of ${feedbackSessionToCopy.feedbackSessionName}`); + it('should not detect name collision when selected course is different', () => { + component.newFeedbackSessionName = 'Test Feedback Session'; + component.originalSessionName = 'Test Feedback Session'; + component.sessionToCopyCourseId = 'TestCourseID'; + component.select('DifferentCourseID'); + expect(component.isNameCollision).toBe(false); }); - it('should restore the original session name when the same course is deselected', () => { - component.newFeedbackSessionName = `Copy of ${feedbackSessionToCopy.feedbackSessionName}`; - component.originalSessionName = feedbackSessionToCopy.feedbackSessionName; - component.sessionToCopyCourseId = courseSessionIn.courseId; - component.courseCandidates = [courseSessionIn, courseCopyTo]; - component.copyToCourseSet.add(courseSessionIn.courseId); + it('should detect name collision when name matches original session and courseId is selected', () => { + component.newFeedbackSessionName = 'Test session'; + component.originalSessionName = 'Test session'; + component.sessionToCopyCourseId = 'Test01'; + component.select('Test01'); fixture.detectChanges(); + expect(component.isNameCollision).toBe(true); + }); - const options: DebugElement[] = fixture.debugElement.queryAll(By.css('input[type="checkbox"]')); - const firstOption: any = options[0]; - firstOption.triggerEventHandler('click', { target: firstOption.nativeElement }); + it('should not detect name collision when name matches original session but courseId is not selected', () => { + component.newFeedbackSessionName = 'Test session'; + component.originalSessionName = 'Test session'; + component.sessionToCopyCourseId = 'Test01'; + component.select('Test02'); fixture.detectChanges(); + expect(component.isNameCollision).toBe(false); + }); - expect(component.newFeedbackSessionName).toBe(feedbackSessionToCopy.feedbackSessionName); + it('should update name collision status on input change', () => { + component.newFeedbackSessionName = 'Test session'; + component.originalSessionName = 'Test session'; + component.sessionToCopyCourseId = 'Test01'; + component.select('Test01'); + component.newFeedbackSessionName = 'New session name'; + component.checkNameCollision(); + fixture.detectChanges(); + expect(component.isNameCollision).toBe(false); + }); + + it('should update name collision status on course selection change', () => { + component.newFeedbackSessionName = 'Test session'; + component.originalSessionName = 'Test session'; + component.sessionToCopyCourseId = 'Test01'; + component.select('Test01'); + component.select('Test01'); + fixture.detectChanges(); + expect(component.isNameCollision).toBe(false); }); }); diff --git a/src/web/app/components/copy-session-modal/copy-session-modal.component.ts b/src/web/app/components/copy-session-modal/copy-session-modal.component.ts index c667d3567a8..fa22c2ca7ab 100644 --- a/src/web/app/components/copy-session-modal/copy-session-modal.component.ts +++ b/src/web/app/components/copy-session-modal/copy-session-modal.component.ts @@ -64,7 +64,7 @@ export class CopySessionModalComponent implements OnInit { * Checks for name collision. */ checkNameCollision(): void { - this.isNameCollision = this.newFeedbackSessionName === this.originalSessionName + this.isNameCollision = this.newFeedbackSessionName === this.originalSessionName && this.copyToCourseSet.has(this.sessionToCopyCourseId); } }