Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crisnicandrei committed Sep 17, 2024
1 parent 550b3d4 commit f087828
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit f087828

Please sign in to comment.