From f08782849b76818fb9b5fc0d3ba96641f587803e Mon Sep 17 00:00:00 2001 From: crisnicandrei <62384997+crisnicandrei@users.noreply.github.com> Date: Tue, 17 Sep 2024 22:26:01 +0300 Subject: [PATCH] added tests --- .../glam-pending-archives.component.spec.ts | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/app/onboarding/components/glam-pending-archives/glam-pending-archives.component.spec.ts b/src/app/onboarding/components/glam-pending-archives/glam-pending-archives.component.spec.ts index 9ef68f300..65666541d 100644 --- a/src/app/onboarding/components/glam-pending-archives/glam-pending-archives.component.spec.ts +++ b/src/app/onboarding/components/glam-pending-archives/glam-pending-archives.component.spec.ts @@ -73,4 +73,62 @@ describe('GlamPendingArchivesComponent', () => { expect(outputs.nextOutput.emit).toHaveBeenCalledWith(selectedArchive); }); + it('should call api.archive.accept when selectArchive is called', async () => { + const { instance, inject } = await shallow.render(); + const apiService = inject(ApiService); + spyOn(apiService.archive, 'accept').and.callThrough(); + + const archive: ArchiveVO = new ArchiveVO({ + archiveId: 1, + fullName: 'Test Archive', + }); + + await instance.selectArchive(archive); + expect(apiService.archive.accept).toHaveBeenCalledWith(archive); + }); + + it('should add archive to acceptedArchives when selectArchive is called', async () => { + const { instance } = await shallow.render(); + const archive: ArchiveVO = new ArchiveVO({ + archiveId: 1, + fullName: 'Test Archive', + }); + + await instance.selectArchive(archive); + expect(instance.acceptedArchives.length).toBe(1); + expect(instance.acceptedArchives[0].archiveId).toBe(1); + }); + + it('should set selectedArchive if no archive was previously selected', async () => { + const { instance } = await shallow.render(); + const archive: ArchiveVO = new ArchiveVO({ + archiveId: 1, + fullName: 'Test Archive', + }); + + expect(instance.selectedArchive).toBeNull(); + await instance.selectArchive(archive); + expect(instance.selectedArchive.archiveId).toBe(archive.archiveId); + }); + + it('should return true when isSelected is called for an accepted archive', async () => { + const { instance } = await shallow.render(); + const archive: ArchiveVO = new ArchiveVO({ + archiveId: 1, + fullName: 'Test Archive', + }); + + await instance.selectArchive(archive); + expect(instance.isSelected(1)).toBeTrue(); + }); + + it('should return false when isSelected is called for a non-accepted archive', async () => { + const { instance } = await shallow.render(); + const archive: ArchiveVO = new ArchiveVO({ + archiveId: 1, + fullName: 'Test Archive', + }); + + expect(instance.isSelected(1)).toBeFalse(); + }); });