From 8b25ef17c8aedc28fe4227d76c89e71c76027c5d Mon Sep 17 00:00:00 2001 From: Respirayson Date: Sat, 20 Jul 2024 02:08:42 +0800 Subject: [PATCH 1/5] Add logic to prepend Copy of when copying to same course id --- .../copy-session-modal.component.spec.ts.snap | 2 ++ .../copy-session-modal.component.ts | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 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 c1f6c2edfbc..d20cc648230 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 @@ -7,6 +7,7 @@ exports[`CopySessionModalComponent should snap with default fields 1`] = ` copyToCourseSet={[Function Set]} courseCandidates={[Function Array]} newFeedbackSessionName="" + originalSessionName="" sessionToCopyCourseId="" >
= new Set(); + originalSessionName: string = ''; constructor(public activeModal: NgbActiveModal) {} + ngOnInit(): void { + this.originalSessionName = this.newFeedbackSessionName; + } + /** * Fires the copy event. */ @@ -44,8 +49,14 @@ export class CopySessionModalComponent { select(courseId: string): void { if (this.copyToCourseSet.has(courseId)) { this.copyToCourseSet.delete(courseId); + if (courseId === this.sessionToCopyCourseId) { + this.newFeedbackSessionName = this.originalSessionName; + } } else { this.copyToCourseSet.add(courseId); + if (courseId === this.sessionToCopyCourseId) { + this.newFeedbackSessionName = `Copy of ${this.originalSessionName}`; + } } } } From c21e4345e9e9edeb53a5cdcd72cba2852c07eb22 Mon Sep 17 00:00:00 2001 From: Respirayson Date: Sat, 20 Jul 2024 02:08:59 +0800 Subject: [PATCH 2/5] Add unit tests --- .../copy-session-modal.component.spec.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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 55ff79cf730..00fb3c33d76 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,4 +146,34 @@ 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(); + + const options: DebugElement[] = fixture.debugElement.queryAll(By.css('input[type="checkbox"]')); + const firstOption: any = options[0]; + firstOption.triggerEventHandler('click', { target: firstOption.nativeElement }); + fixture.detectChanges(); + + expect(component.newFeedbackSessionName).toBe(`Copy of ${feedbackSessionToCopy.feedbackSessionName}`); + }); + + 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); + fixture.detectChanges(); + + const options: DebugElement[] = fixture.debugElement.queryAll(By.css('input[type="checkbox"]')); + const firstOption: any = options[0]; + firstOption.triggerEventHandler('click', { target: firstOption.nativeElement }); + fixture.detectChanges(); + + expect(component.newFeedbackSessionName).toBe(feedbackSessionToCopy.feedbackSessionName); + }); }); From aa8906e5e2743035eda7bcbb5b69340065fa9c20 Mon Sep 17 00:00:00 2001 From: Respirayson Date: Sat, 20 Jul 2024 03:17:14 +0800 Subject: [PATCH 3/5] Add check so it doesnt override changed names --- .../copy-session-modal/copy-session-modal.component.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 652dacc8869..3a3dacc218c 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 @@ -49,12 +49,13 @@ export class CopySessionModalComponent implements OnInit { select(courseId: string): void { if (this.copyToCourseSet.has(courseId)) { this.copyToCourseSet.delete(courseId); - if (courseId === this.sessionToCopyCourseId) { - this.newFeedbackSessionName = this.originalSessionName; + if (courseId === this.sessionToCopyCourseId + && this.newFeedbackSessionName === `Copy of ${this.originalSessionName}`) { + this.newFeedbackSessionName = this.originalSessionName; } } else { this.copyToCourseSet.add(courseId); - if (courseId === this.sessionToCopyCourseId) { + if (courseId === this.sessionToCopyCourseId && this.newFeedbackSessionName === this.originalSessionName) { this.newFeedbackSessionName = `Copy of ${this.originalSessionName}`; } } From 3882c41405cbb50bb1eccbfe30ab03964d79fdb5 Mon Sep 17 00:00:00 2001 From: Respirayson Date: Sat, 3 Aug 2024 14:27:03 +0800 Subject: [PATCH 4/5] Replace copy of functionality with alert --- .../copy-session-modal.component.html | 7 +++++-- .../copy-session-modal.component.ts | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/web/app/components/copy-session-modal/copy-session-modal.component.html b/src/web/app/components/copy-session-modal/copy-session-modal.component.html index 79ac691daef..9600c3420f6 100644 --- a/src/web/app/components/copy-session-modal/copy-session-modal.component.html +++ b/src/web/app/components/copy-session-modal/copy-session-modal.component.html @@ -11,13 +11,16 @@