Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crisnicandrei committed Oct 23, 2024
1 parent 373d64d commit 79e3b8a
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/app/file-browser/components/sidebar/sidebar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,62 @@ describe('SidebarComponent', () => {

expect(locationDialogSpy).toHaveBeenCalledWith(instance.selectedItem);
});

it('should set currentTab correctly when setCurrentTab is called', async () => {
const { instance, fixture } = await shallow.render();

instance.setCurrentTab('info');
fixture.detectChanges();

expect(instance.currentTab).toBe('info');

instance.isRootFolder = false;
instance.isPublicItem = false;
instance.setCurrentTab('sharing');
fixture.detectChanges();

expect(instance.currentTab).toBe('sharing');
});

it('should call editService.openLocationDialog when onLocationClick is called if editable', async () => {
const { instance, inject } = await shallow.render();
const editService = inject(EditService);
spyOn(editService, 'openLocationDialog');

instance.canEdit = true;
instance.selectedItem = new RecordVO({});

instance.onLocationClick();

expect(editService.openLocationDialog).toHaveBeenCalledWith(instance.selectedItem);
});


it('should correctly update canEdit and canShare when checkPermissions is called', async () => {
const { instance } = await shallow.render();

instance.selectedItem = new RecordVO({
accessRole: 'access.role.editor',
});
instance.selectedItems = [instance.selectedItem];
instance.isRootFolder = false;
instance.isPublicItem = false;

instance.checkPermissions();

expect(instance.canEdit).toBe(true);
expect(instance.canShare).toBe(true);

instance.selectedItem = new RecordVO({
accessRole: 'access.role.viewer',
});
instance.selectedItems = [instance.selectedItem];
instance.isRootFolder = false;
instance.isPublicItem = false;

instance.checkPermissions();

expect(instance.canEdit).toBe(false);
expect(instance.canShare).toBe(true);
});
});

0 comments on commit 79e3b8a

Please sign in to comment.