Skip to content

Commit

Permalink
[#12588] Improve test code coverage of CopySessionModalComponent (#12616
Browse files Browse the repository at this point in the history
)

* commit to checkout

* Add test for the 'copy' method and improve the test for 'select' method from partial covered to all covered for CopySessionModalComponent.

* remove blank line

* add new line at the end of file

* removed the old test which running error in CI test

* revert the change of  spec.ts.snap

---------

Co-authored-by: Wei Qing <[email protected]>
  • Loading branch information
Astrid641 and weiquu authored Nov 30, 2023
1 parent 6d0084e commit 968ff77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ exports[`CopySessionModalComponent should snap with some session and courses can
</button>
</div>
</tm-copy-session-modal>
`;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CopySessionModalComponent } from './copy-session-modal.component';
describe('CopySessionModalComponent', () => {
let component: CopySessionModalComponent;
let fixture: ComponentFixture<CopySessionModalComponent>;
let activeModal: NgbActiveModal;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand All @@ -34,6 +35,7 @@ describe('CopySessionModalComponent', () => {
fixture = TestBed.createComponent(CopySessionModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
activeModal = TestBed.inject(NgbActiveModal);
});

it('should create', () => {
Expand Down Expand Up @@ -105,4 +107,43 @@ describe('CopySessionModalComponent', () => {
expect(copyButton.nativeElement.disabled).toBeFalsy();
});

it('should close the modal with the correct data', () => {
component.newFeedbackSessionName = 'Test Feedback Session';
component.sessionToCopyCourseId = 'TestCourseID';
component.copyToCourseSet.add('Course1');
component.copyToCourseSet.add('Course2');

const closeSpy = jest.spyOn(activeModal, 'close');
component.copy();
expect(closeSpy).toHaveBeenCalledWith({
newFeedbackSessionName: 'Test Feedback Session',
sessionToCopyCourseId: 'TestCourseID',
copyToCourseList: ['Course1', 'Course2'],
});
});

it('should add a courseId to copyToCourseSet when it is not already present', () => {
const courseId = 'Course1';
expect(component.copyToCourseSet.has(courseId)).toBe(false);
component.select(courseId);
expect(component.copyToCourseSet.has(courseId)).toBe(true);
});

it('should remove a courseId from copyToCourseSet when it is already present', () => {
const courseId = 'Course1';
component.copyToCourseSet.add(courseId);
expect(component.copyToCourseSet.has(courseId)).toBe(true);
component.select(courseId);
expect(component.copyToCourseSet.has(courseId)).toBe(false);
});

it('should toggle courseId in copyToCourseSet', () => {
const courseId = 'Course1';
expect(component.copyToCourseSet.has(courseId)).toBe(false);
component.select(courseId);
expect(component.copyToCourseSet.has(courseId)).toBe(true);
component.select(courseId);
expect(component.copyToCourseSet.has(courseId)).toBe(false);
});

});

0 comments on commit 968ff77

Please sign in to comment.