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:
@@ -1,4 +1,4 @@
|
||||
import { DebugElement, Pipe, PipeTransform } from '@angular/core';
|
||||
import { DebugElement, Pipe, PipeTransform, PLATFORM_ID } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Bitstream } from '../core/shared/bitstream.model';
|
||||
@@ -12,6 +12,9 @@ import { AuthService } from '../core/auth/auth.service';
|
||||
import { FileService } from '../core/shared/file.service';
|
||||
import { VarDirective } from '../shared/utils/var.directive';
|
||||
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { ThemeService } from '../shared/theme-support/theme.service';
|
||||
import { getMockThemeService } from '../shared/mocks/theme-service.mock';
|
||||
|
||||
// eslint-disable-next-line @angular-eslint/pipe-prefix
|
||||
@Pipe({ name: 'translate' })
|
||||
@@ -31,7 +34,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),
|
||||
@@ -49,7 +54,8 @@ describe('ThumbnailComponent', () => {
|
||||
providers: [
|
||||
{ provide: AuthService, useValue: authService },
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
{ provide: FileService, useValue: fileService }
|
||||
{ provide: FileService, useValue: fileService },
|
||||
{ provide: PLATFORM_ID, useValue: 'browser' },
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
@@ -333,3 +339,59 @@ 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' },
|
||||
],
|
||||
}).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