[CST-4499] Version history - Tests WIP

This commit is contained in:
Davide Negretti
2021-09-20 20:34:34 +02:00
parent fbc69832d8
commit 3255a29b30

View File

@@ -10,10 +10,13 @@ import { VersionHistoryDataService } from '../../../../core/data/version-history
import { By } from '@angular/platform-browser';
import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
import { createPaginatedList } from '../../../testing/utils.test';
import { of } from 'rxjs';
import { take } from 'rxjs/operators';
describe('ItemVersionsNoticeComponent', () => {
let component: ItemVersionsNoticeComponent;
let fixture: ComponentFixture<ItemVersionsNoticeComponent>;
let versionHistoryService: VersionHistoryDataService;
const versionHistory = Object.assign(new VersionHistory(), {
id: '1'
@@ -48,19 +51,37 @@ describe('ItemVersionsNoticeComponent', () => {
});
firstVersion.item = createSuccessfulRemoteDataObject$(firstItem);
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(() => {
const versionHistoryServiceSpy = jasmine.createSpyObj('versionHistoryService',
['getVersions', 'getLatestVersionFromHistory$', 'isLatest$', ]
);
TestBed.configureTestingModule({
declarations: [ItemVersionsNoticeComponent],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [
{ provide: VersionHistoryDataService, useValue: versionHistoryService }
{ provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy }
],
schemas: [NO_ERRORS_SCHEMA]
}).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', () => {
@@ -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) {
fixture = TestBed.createComponent(ItemVersionsNoticeComponent);
component = fixture.componentInstance;