mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-4499] Version history - Tests WIP
This commit is contained in:
@@ -10,10 +10,13 @@ import { VersionHistoryDataService } from '../../../../core/data/version-history
|
|||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
|
import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
|
||||||
import { createPaginatedList } from '../../../testing/utils.test';
|
import { createPaginatedList } from '../../../testing/utils.test';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
import { take } from 'rxjs/operators';
|
||||||
|
|
||||||
describe('ItemVersionsNoticeComponent', () => {
|
describe('ItemVersionsNoticeComponent', () => {
|
||||||
let component: ItemVersionsNoticeComponent;
|
let component: ItemVersionsNoticeComponent;
|
||||||
let fixture: ComponentFixture<ItemVersionsNoticeComponent>;
|
let fixture: ComponentFixture<ItemVersionsNoticeComponent>;
|
||||||
|
let versionHistoryService: VersionHistoryDataService;
|
||||||
|
|
||||||
const versionHistory = Object.assign(new VersionHistory(), {
|
const versionHistory = Object.assign(new VersionHistory(), {
|
||||||
id: '1'
|
id: '1'
|
||||||
@@ -48,19 +51,37 @@ describe('ItemVersionsNoticeComponent', () => {
|
|||||||
});
|
});
|
||||||
firstVersion.item = createSuccessfulRemoteDataObject$(firstItem);
|
firstVersion.item = createSuccessfulRemoteDataObject$(firstItem);
|
||||||
latestVersion.item = createSuccessfulRemoteDataObject$(latestItem);
|
latestVersion.item = createSuccessfulRemoteDataObject$(latestItem);
|
||||||
const versionHistoryService = jasmine.createSpyObj('versionHistoryService', {
|
|
||||||
getVersions: createSuccessfulRemoteDataObject$(createPaginatedList(versions))
|
// versionHistoryService.getLatestVersionFromHistory$.createSpy('getLatestVersionFromHistory$').and.callFake((id) => {
|
||||||
});
|
// return of(latestVersion);
|
||||||
|
// });
|
||||||
|
// versionHistoryService.isLatest$.createSpy('isLatest$').and.callFake((id) => {
|
||||||
|
// return of(true);
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
|
|
||||||
|
const versionHistoryServiceSpy = jasmine.createSpyObj('versionHistoryService',
|
||||||
|
['getVersions', 'getLatestVersionFromHistory$', 'isLatest$', ]
|
||||||
|
);
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ItemVersionsNoticeComponent],
|
declarations: [ItemVersionsNoticeComponent],
|
||||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: VersionHistoryDataService, useValue: versionHistoryService }
|
{ provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
|
||||||
|
versionHistoryService = TestBed.inject(VersionHistoryDataService);
|
||||||
|
|
||||||
|
const isLatestFcn = (version: Version) => of((version.version === latestVersion.version));
|
||||||
|
|
||||||
|
versionHistoryServiceSpy.getVersions.and.returnValue(createSuccessfulRemoteDataObject$(createPaginatedList(versions)));
|
||||||
|
versionHistoryServiceSpy.getLatestVersionFromHistory$.and.returnValue(of(latestVersion));
|
||||||
|
versionHistoryServiceSpy.isLatest$.and.callFake(isLatestFcn);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('when the item is the latest version', () => {
|
describe('when the item is the latest version', () => {
|
||||||
@@ -85,6 +106,19 @@ describe('ItemVersionsNoticeComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isLatest', () => {
|
||||||
|
it('firstVersion should not be the latest', () => {
|
||||||
|
versionHistoryService.isLatest$(firstVersion).pipe(take(1)).subscribe((res) => {
|
||||||
|
expect(res).toBeFalse();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('latestVersion should be the latest', () => {
|
||||||
|
versionHistoryService.isLatest$(latestVersion).pipe(take(1)).subscribe((res) => {
|
||||||
|
expect(res).toBeTrue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function initComponentWithItem(item: Item) {
|
function initComponentWithItem(item: Item) {
|
||||||
fixture = TestBed.createComponent(ItemVersionsNoticeComponent);
|
fixture = TestBed.createComponent(ItemVersionsNoticeComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
Reference in New Issue
Block a user