mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
#885 add more unit test
This commit is contained in:
@@ -69,4 +69,12 @@ describe('MediaViewerImageComponent', () => {
|
|||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -22,19 +22,6 @@ describe('MediaViewerComponent', () => {
|
|||||||
let comp: MediaViewerComponent;
|
let comp: MediaViewerComponent;
|
||||||
let fixture: ComponentFixture<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(), {
|
const mockBitstream: Bitstream = Object.assign(new Bitstream(), {
|
||||||
sizeBytes: 10201,
|
sizeBytes: 10201,
|
||||||
content:
|
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(
|
const mockMediaViewerItem: MediaViewerItem = Object.assign(
|
||||||
new MediaViewerItem(),
|
new MediaViewerItem(),
|
||||||
{ bitstream: mockBitstream, format: 'image', thumbnail: null }
|
{ bitstream: mockBitstream, format: 'image', thumbnail: null }
|
||||||
@@ -111,10 +111,14 @@ describe('MediaViewerComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the service to retrieve bitstreams', () => {
|
it('should call the createMediaViewerItem', () => {
|
||||||
expect(
|
const mediaItem = comp.createMediaViewerItem(
|
||||||
bitstreamDataService.findAllByItemAndBundleName
|
mockBitstream,
|
||||||
).toHaveBeenCalled();
|
MockBitstreamFormat1,
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
expect(mediaItem).toBeTruthy();
|
||||||
|
expect(mediaItem.thumbnail).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display a loading component', () => {
|
it('should display a loading component', () => {
|
||||||
@@ -122,4 +126,5 @@ describe('MediaViewerComponent', () => {
|
|||||||
expect(loading.nativeElement).toBeDefined();
|
expect(loading.nativeElement).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -5,6 +5,7 @@ import { BitstreamDataService } from '../../core/data/bitstream-data.service';
|
|||||||
import { BitstreamFormatDataService } from '../../core/data/bitstream-format-data.service';
|
import { BitstreamFormatDataService } from '../../core/data/bitstream-format-data.service';
|
||||||
import { PaginatedList } from '../../core/data/paginated-list';
|
import { PaginatedList } from '../../core/data/paginated-list';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
|
import { BitstreamFormat } from '../../core/shared/bitstream-format.model';
|
||||||
import { Bitstream } from '../../core/shared/bitstream.model';
|
import { Bitstream } from '../../core/shared/bitstream.model';
|
||||||
import { Item } from '../../core/shared/item.model';
|
import { Item } from '../../core/shared/item.model';
|
||||||
import { MediaViewerItem } from '../../core/shared/media-viewer-item.model';
|
import { MediaViewerItem } from '../../core/shared/media-viewer-item.model';
|
||||||
@@ -46,13 +47,11 @@ export class MediaViewerComponent implements OnInit {
|
|||||||
.pipe(getFirstSucceededRemoteDataPayload())
|
.pipe(getFirstSucceededRemoteDataPayload())
|
||||||
.subscribe((format) => {
|
.subscribe((format) => {
|
||||||
const current = this.mediaList$.getValue();
|
const current = this.mediaList$.getValue();
|
||||||
const mediaItem = new MediaViewerItem();
|
const mediaItem = this.createMediaViewerItem(
|
||||||
mediaItem.bitstream = bitstreamsRD.payload.page[index];
|
bitstreamsRD.payload.page[index],
|
||||||
mediaItem.format = format.mimetype.split('/')[0];
|
format,
|
||||||
mediaItem.thumbnail =
|
|
||||||
thumbnailsRD.payload && thumbnailsRD.payload.page[index]
|
thumbnailsRD.payload && thumbnailsRD.payload.page[index]
|
||||||
? thumbnailsRD.payload.page[index]._links.content.href
|
);
|
||||||
: null;
|
|
||||||
this.mediaList$.next([...current, mediaItem]);
|
this.mediaList$.next([...current, mediaItem]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -79,4 +78,17 @@ export class MediaViewerComponent implements OnInit {
|
|||||||
take(1)
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user