mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
79597: Update unit tests
This commit is contained in:
@@ -3,6 +3,7 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
export function getMockTranslateService(): TranslateService {
|
export function getMockTranslateService(): TranslateService {
|
||||||
return jasmine.createSpyObj('translateService', {
|
return jasmine.createSpyObj('translateService', {
|
||||||
get: jasmine.createSpy('get'),
|
get: jasmine.createSpy('get'),
|
||||||
|
use: jasmine.createSpy('use'),
|
||||||
instant: jasmine.createSpy('instant'),
|
instant: jasmine.createSpy('instant'),
|
||||||
setDefaultLang: jasmine.createSpy('setDefaultLang')
|
setDefaultLang: jasmine.createSpy('setDefaultLang')
|
||||||
});
|
});
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
<div class="thumbnail">
|
<div class="thumbnail">
|
||||||
<img *ngIf="src !== null" [src]="src | dsSafeUrl" [alt]="alt" (error)="errorHandler()" class="img-fluid"/>
|
<img *ngIf="src !== null" [src]="src | dsSafeUrl" [alt]="alt | translate" (error)="errorHandler()" class="img-fluid"/>
|
||||||
<div *ngIf="src === null" class="outer">
|
<div *ngIf="src === null" class="outer">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<div class="thumbnail-placeholder w-100 h-100 p-3">
|
<div class="thumbnail-placeholder w-100 h-100 p-3">{{ placeholder | translate }}</div>
|
||||||
{{ placeholder | translate }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,10 +1,18 @@
|
|||||||
import { DebugElement } from '@angular/core';
|
import { DebugElement, Pipe, PipeTransform } 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';
|
||||||
import { SafeUrlPipe } from '../shared/utils/safe-url-pipe';
|
import { SafeUrlPipe } from '../shared/utils/safe-url-pipe';
|
||||||
|
|
||||||
import { THUMBNAIL_PLACEHOLDER, ThumbnailComponent } from './thumbnail.component';
|
import { ThumbnailComponent } from './thumbnail.component';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
@Pipe({ name: 'translate' })
|
||||||
|
class MockTranslatePipe implements PipeTransform {
|
||||||
|
transform(key: string): string {
|
||||||
|
return 'TRANSLATED ' + key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe('ThumbnailComponent', () => {
|
describe('ThumbnailComponent', () => {
|
||||||
let comp: ThumbnailComponent;
|
let comp: ThumbnailComponent;
|
||||||
@@ -14,7 +22,7 @@ describe('ThumbnailComponent', () => {
|
|||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ThumbnailComponent, SafeUrlPipe]
|
declarations: [ThumbnailComponent, SafeUrlPipe, MockTranslatePipe],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -39,6 +47,19 @@ describe('ThumbnailComponent', () => {
|
|||||||
const image: HTMLElement = de.query(By.css('img')).nativeElement;
|
const image: HTMLElement = de.query(By.css('img')).nativeElement;
|
||||||
expect(image.getAttribute('src')).toBe(comp.thumbnail._links.content.href);
|
expect(image.getAttribute('src')).toBe(comp.thumbnail._links.content.href);
|
||||||
});
|
});
|
||||||
|
it('should include the alt text', () => {
|
||||||
|
const thumbnail = new Bitstream();
|
||||||
|
thumbnail._links = {
|
||||||
|
self: { href: 'self.url' },
|
||||||
|
bundle: { href: 'bundle.url' },
|
||||||
|
format: { href: 'format.url' },
|
||||||
|
content: { href: 'content.url' },
|
||||||
|
};
|
||||||
|
comp.thumbnail = thumbnail;
|
||||||
|
fixture.detectChanges();
|
||||||
|
const image: HTMLElement = de.query(By.css('img')).nativeElement;
|
||||||
|
expect(image.getAttribute('alt')).toBe('TRANSLATED ' + comp.alt);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe(`when the thumbnail doesn't exist`, () => {
|
describe(`when the thumbnail doesn't exist`, () => {
|
||||||
describe('and there is a default image', () => {
|
describe('and there is a default image', () => {
|
||||||
@@ -48,13 +69,24 @@ describe('ThumbnailComponent', () => {
|
|||||||
comp.errorHandler();
|
comp.errorHandler();
|
||||||
expect(comp.src).toBe(comp.defaultImage);
|
expect(comp.src).toBe(comp.defaultImage);
|
||||||
});
|
});
|
||||||
|
it('should include the alt text', () => {
|
||||||
|
comp.src = 'http://bit.stream';
|
||||||
|
comp.defaultImage = 'http://default.img';
|
||||||
|
comp.errorHandler();
|
||||||
|
fixture.detectChanges();
|
||||||
|
const image: HTMLElement = de.query(By.css('img')).nativeElement;
|
||||||
|
expect(image.getAttribute('alt')).toBe('TRANSLATED ' + comp.alt);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('and there is no default image', () => {
|
describe('and there is no default image', () => {
|
||||||
it('should display the placeholder', () => {
|
it('should display the placeholder', () => {
|
||||||
comp.src = 'http://default.img';
|
comp.src = 'http://default.img';
|
||||||
comp.defaultImage = 'http://default.img';
|
|
||||||
comp.errorHandler();
|
comp.errorHandler();
|
||||||
expect(comp.src).toBe(THUMBNAIL_PLACEHOLDER);
|
expect(comp.src).toBe(null);
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
const placeholder = fixture.debugElement.query(By.css('div.thumbnail-placeholder')).nativeElement;
|
||||||
|
expect(placeholder.innerHTML).toBe('TRANSLATED ' + comp.placeholder);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user