mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[DURACOM-288] Additional test for thumbnail component
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
DebugElement,
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
PLATFORM_ID,
|
||||
} from '@angular/core';
|
||||
import {
|
||||
ComponentFixture,
|
||||
@@ -48,7 +49,9 @@ describe('ThumbnailComponent', () => {
|
||||
let authService;
|
||||
let authorizationService;
|
||||
let fileService;
|
||||
let spy;
|
||||
|
||||
describe('when platform is browser', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
authService = jasmine.createSpyObj('AuthService', {
|
||||
isAuthenticated: observableOf(true),
|
||||
@@ -74,6 +77,7 @@ describe('ThumbnailComponent', () => {
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
{ provide: FileService, useValue: fileService },
|
||||
{ provide: ThemeService, useValue: getMockThemeService() },
|
||||
{ provide: PLATFORM_ID, useValue: 'browser' },
|
||||
],
|
||||
}).overrideComponent(ThumbnailComponent, {
|
||||
add: {
|
||||
@@ -362,3 +366,64 @@ describe('ThumbnailComponent', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when platform is server', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
|
||||
authService = jasmine.createSpyObj('AuthService', {
|
||||
isAuthenticated: observableOf(true),
|
||||
});
|
||||
authorizationService = jasmine.createSpyObj('AuthorizationService', {
|
||||
isAuthorized: observableOf(true),
|
||||
});
|
||||
fileService = jasmine.createSpyObj('FileService', {
|
||||
retrieveFileDownloadLink: null,
|
||||
});
|
||||
fileService.retrieveFileDownloadLink.and.callFake((url) => observableOf(`${url}?authentication-token=fake`));
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
ThumbnailComponent,
|
||||
SafeUrlPipe,
|
||||
MockTranslatePipe,
|
||||
VarDirective,
|
||||
],
|
||||
providers: [
|
||||
{ provide: AuthService, useValue: authService },
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
{ provide: FileService, useValue: fileService },
|
||||
{ provide: ThemeService, useValue: getMockThemeService() },
|
||||
{ provide: PLATFORM_ID, useValue: 'server' },
|
||||
],
|
||||
}).overrideComponent(ThumbnailComponent, {
|
||||
add: {
|
||||
imports: [MockTranslatePipe],
|
||||
},
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ThumbnailComponent);
|
||||
spyOn(fixture.componentInstance, 'setSrc').and.callThrough();
|
||||
fixture.detectChanges();
|
||||
|
||||
authService = TestBed.inject(AuthService);
|
||||
|
||||
comp = fixture.componentInstance; // ThumbnailComponent test instance
|
||||
de = fixture.debugElement.query(By.css('div.thumbnail'));
|
||||
el = de.nativeElement;
|
||||
});
|
||||
|
||||
it('should start out with isLoading$ true', () => {
|
||||
expect(comp.isLoading).toBeTrue();
|
||||
expect(de.query(By.css('ds-loading'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not call setSrc', () => {
|
||||
expect(comp.setSrc).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user