Skip to content

Commit

Permalink
Update snapshots and fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Respirayson committed Aug 3, 2024
1 parent 3882c41 commit 6778fa8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down Expand Up @@ -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]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 6778fa8

Please sign in to comment.