mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[DURACOM-288] Additional test for thumbnail component
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
|||||||
DebugElement,
|
DebugElement,
|
||||||
Pipe,
|
Pipe,
|
||||||
PipeTransform,
|
PipeTransform,
|
||||||
|
PLATFORM_ID,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import {
|
import {
|
||||||
ComponentFixture,
|
ComponentFixture,
|
||||||
@@ -48,7 +49,9 @@ describe('ThumbnailComponent', () => {
|
|||||||
let authService;
|
let authService;
|
||||||
let authorizationService;
|
let authorizationService;
|
||||||
let fileService;
|
let fileService;
|
||||||
|
let spy;
|
||||||
|
|
||||||
|
describe('when platform is browser', () => {
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
authService = jasmine.createSpyObj('AuthService', {
|
authService = jasmine.createSpyObj('AuthService', {
|
||||||
isAuthenticated: observableOf(true),
|
isAuthenticated: observableOf(true),
|
||||||
@@ -74,6 +77,7 @@ describe('ThumbnailComponent', () => {
|
|||||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||||
{ provide: FileService, useValue: fileService },
|
{ provide: FileService, useValue: fileService },
|
||||||
{ provide: ThemeService, useValue: getMockThemeService() },
|
{ provide: ThemeService, useValue: getMockThemeService() },
|
||||||
|
{ provide: PLATFORM_ID, useValue: 'browser' },
|
||||||
],
|
],
|
||||||
}).overrideComponent(ThumbnailComponent, {
|
}).overrideComponent(ThumbnailComponent, {
|
||||||
add: {
|
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