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 { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { Bitstream } from '../core/shared/bitstream.model';
|
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 { FileService } from '../core/shared/file.service';
|
||||||
import { VarDirective } from '../shared/utils/var.directive';
|
import { VarDirective } from '../shared/utils/var.directive';
|
||||||
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
|
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
|
// eslint-disable-next-line @angular-eslint/pipe-prefix
|
||||||
@Pipe({ name: 'translate' })
|
@Pipe({ name: 'translate' })
|
||||||
@@ -31,7 +34,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),
|
||||||
@@ -49,7 +54,8 @@ describe('ThumbnailComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
{ provide: AuthService, useValue: authService },
|
{ provide: AuthService, useValue: authService },
|
||||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||||
{ provide: FileService, useValue: fileService }
|
{ provide: FileService, useValue: fileService },
|
||||||
|
{ provide: PLATFORM_ID, useValue: 'browser' },
|
||||||
]
|
]
|
||||||
}).compileComponents();
|
}).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