diff --git a/src/app/shared/mocks/translate.service.mock.ts b/src/app/shared/mocks/translate.service.mock.ts
index 0bc172b408..38b088e50f 100644
--- a/src/app/shared/mocks/translate.service.mock.ts
+++ b/src/app/shared/mocks/translate.service.mock.ts
@@ -3,6 +3,7 @@ import { TranslateService } from '@ngx-translate/core';
export function getMockTranslateService(): TranslateService {
return jasmine.createSpyObj('translateService', {
get: jasmine.createSpy('get'),
+ use: jasmine.createSpy('use'),
instant: jasmine.createSpy('instant'),
setDefaultLang: jasmine.createSpy('setDefaultLang')
});
diff --git a/src/app/thumbnail/thumbnail.component.html b/src/app/thumbnail/thumbnail.component.html
index 4789917f1c..cef88e0192 100644
--- a/src/app/thumbnail/thumbnail.component.html
+++ b/src/app/thumbnail/thumbnail.component.html
@@ -1,10 +1,8 @@
-
![]()
+
-
- {{ placeholder | translate }}
-
+
{{ placeholder | translate }}
diff --git a/src/app/thumbnail/thumbnail.component.spec.ts b/src/app/thumbnail/thumbnail.component.spec.ts
index 21678c9162..687282a373 100644
--- a/src/app/thumbnail/thumbnail.component.spec.ts
+++ b/src/app/thumbnail/thumbnail.component.spec.ts
@@ -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 { By } from '@angular/platform-browser';
import { Bitstream } from '../core/shared/bitstream.model';
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', () => {
let comp: ThumbnailComponent;
@@ -14,7 +22,7 @@ describe('ThumbnailComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
- declarations: [ThumbnailComponent, SafeUrlPipe]
+ declarations: [ThumbnailComponent, SafeUrlPipe, MockTranslatePipe],
}).compileComponents();
}));
@@ -39,6 +47,19 @@ describe('ThumbnailComponent', () => {
const image: HTMLElement = de.query(By.css('img')).nativeElement;
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('and there is a default image', () => {
@@ -48,13 +69,24 @@ describe('ThumbnailComponent', () => {
comp.errorHandler();
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', () => {
it('should display the placeholder', () => {
comp.src = 'http://default.img';
- comp.defaultImage = 'http://default.img';
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);
});
});
});