#885 add more unit test

This commit is contained in:
Dániel Péter Sipos
2020-10-13 10:32:56 +02:00
parent 681904639b
commit 6642cbb088
3 changed files with 48 additions and 23 deletions

View File

@@ -69,4 +69,12 @@ describe('MediaViewerImageComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should contain a gallery options', () => {
expect(component.galleryOptions.length).toBeGreaterThan(0);
});
it('should contain an image array', () => {
expect(component.galleryImages.length).toBeGreaterThan(0);
});
});

View File

@@ -22,19 +22,6 @@ describe('MediaViewerComponent', () => {
let comp: MediaViewerComponent;
let fixture: ComponentFixture<MediaViewerComponent>;
const bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(
createPaginatedList([])
),
});
const bitstreamFormatDataService = jasmine.createSpyObj(
'bitstreamFormatDataService',
{
findByBitstream: createSuccessfulRemoteDataObject$(new BitstreamFormat()),
}
);
const mockBitstream: Bitstream = Object.assign(new Bitstream(), {
sizeBytes: 10201,
content:
@@ -64,6 +51,19 @@ describe('MediaViewerComponent', () => {
},
});
const bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(
createPaginatedList([])
),
});
const bitstreamFormatDataService = jasmine.createSpyObj(
'bitstreamFormatDataService',
{
findByBitstream: createSuccessfulRemoteDataObject$(new BitstreamFormat()),
}
);
const mockMediaViewerItem: MediaViewerItem = Object.assign(
new MediaViewerItem(),
{ bitstream: mockBitstream, format: 'image', thumbnail: null }
@@ -111,10 +111,14 @@ describe('MediaViewerComponent', () => {
fixture.detectChanges();
});
it('should call the service to retrieve bitstreams', () => {
expect(
bitstreamDataService.findAllByItemAndBundleName
).toHaveBeenCalled();
it('should call the createMediaViewerItem', () => {
const mediaItem = comp.createMediaViewerItem(
mockBitstream,
MockBitstreamFormat1,
undefined
);
expect(mediaItem).toBeTruthy();
expect(mediaItem.thumbnail).toBe(null);
});
it('should display a loading component', () => {
@@ -122,4 +126,5 @@ describe('MediaViewerComponent', () => {
expect(loading.nativeElement).toBeDefined();
});
});
});

View File

@@ -5,6 +5,7 @@ import { BitstreamDataService } from '../../core/data/bitstream-data.service';
import { BitstreamFormatDataService } from '../../core/data/bitstream-format-data.service';
import { PaginatedList } from '../../core/data/paginated-list';
import { RemoteData } from '../../core/data/remote-data';
import { BitstreamFormat } from '../../core/shared/bitstream-format.model';
import { Bitstream } from '../../core/shared/bitstream.model';
import { Item } from '../../core/shared/item.model';
import { MediaViewerItem } from '../../core/shared/media-viewer-item.model';
@@ -46,13 +47,11 @@ export class MediaViewerComponent implements OnInit {
.pipe(getFirstSucceededRemoteDataPayload())
.subscribe((format) => {
const current = this.mediaList$.getValue();
const mediaItem = new MediaViewerItem();
mediaItem.bitstream = bitstreamsRD.payload.page[index];
mediaItem.format = format.mimetype.split('/')[0];
mediaItem.thumbnail =
const mediaItem = this.createMediaViewerItem(
bitstreamsRD.payload.page[index],
format,
thumbnailsRD.payload && thumbnailsRD.payload.page[index]
? thumbnailsRD.payload.page[index]._links.content.href
: null;
);
this.mediaList$.next([...current, mediaItem]);
});
}
@@ -79,4 +78,17 @@ export class MediaViewerComponent implements OnInit {
take(1)
);
}
createMediaViewerItem(
original: Bitstream,
format: BitstreamFormat,
thumbnail: Bitstream
): MediaViewerItem {
console.log(original, format, thumbnail);
const mediaItem = new MediaViewerItem();
mediaItem.bitstream = original;
mediaItem.format = format.mimetype.split('/')[0];
mediaItem.thumbnail = thumbnail ? thumbnail._links.content.href : null;
return mediaItem;
}
}