Skip to content

Commit

Permalink
[DSC-1601] - Added test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone-Ramundi committed Apr 29, 2024
1 parent 0aae329 commit de85023
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { APP_CONFIG } from 'src/config/app-config.interface';
import { environment } from 'src/environments/environment';
import { UUIDService } from '../../../../core/shared/uuid.service';
import { getMockUUIDService } from '../../../../shared/mocks/uuid.service.mock';
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';

describe('FullFileSectionComponent', () => {
let comp: FullFileSectionComponent;
Expand Down Expand Up @@ -58,6 +59,10 @@ describe('FullFileSectionComponent', () => {
findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(createPaginatedList([mockBitstream, mockBitstream, mockBitstream]))
});

const authorizedDataService = jasmine.createSpyObj('authorizedDataService',{
isAuthorized: observableOf(false),
});

const paginationService = new PaginationServiceStub();

beforeEach(waitForAsync(() => {
Expand All @@ -75,7 +80,8 @@ describe('FullFileSectionComponent', () => {
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: PaginationService, useValue: paginationService },
{ provide: APP_CONFIG, useValue: environment },
{ provide: UUIDService, useValue: getMockUUIDService() }
{ provide: UUIDService, useValue: getMockUUIDService() },
{ provide: AuthorizationDataService, useValue: authorizedDataService },
],

schemas: [NO_ERRORS_SCHEMA]
Expand All @@ -98,5 +104,14 @@ describe('FullFileSectionComponent', () => {
const fileNameElement = fixture.debugElement.query(By.css('[data-test="file-name"]')).nativeElement;
expect(fileNameElement.classList).toContain('text-break');
});

it('canDownload should return an observable with false value, if user is not authorized to download bitstream', waitForAsync(() => {
authorizedDataService.isAuthorized.and.returnValue(observableOf(false));
comp.canDownload(mockBitstream).subscribe(canDownload => expect(canDownload).toBeFalse());
}));
it('canDownload should return an observable with true value, if user is authorized to download bitstream', waitForAsync(() => {
authorizedDataService.isAuthorized.and.returnValue(observableOf(true));
comp.canDownload(mockBitstream).subscribe(canDownload => expect(canDownload).toBeTrue());
}));
});
});

0 comments on commit de85023

Please sign in to comment.