"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/app/shared/item/item-versions/notice/item-versions-notice.component.spec.ts" between
dspace-angular-dspace-7.0.tar.gz and dspace-angular-dspace-7.1.tar.gz

About: dspace-angular is the Angular-based frontend of DSpace, a digital repository system to capture, store, index, preserve and redistribute an organization’s research material in digital formats.

item-versions-notice.component.spec.ts  (dspace-angular-dspace-7.0):item-versions-notice.component.spec.ts  (dspace-angular-dspace-7.1)
skipping to change at line 13 skipping to change at line 13
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { VersionHistory } from '../../../../core/shared/version-history.model'; import { VersionHistory } from '../../../../core/shared/version-history.model';
import { Version } from '../../../../core/shared/version.model'; import { Version } from '../../../../core/shared/version.model';
import { Item } from '../../../../core/shared/item.model'; import { Item } from '../../../../core/shared/item.model';
import { VersionHistoryDataService } from '../../../../core/data/version-history -data.service'; import { VersionHistoryDataService } from '../../../../core/data/version-history -data.service';
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'
}); });
const firstVersion = Object.assign(new Version(), { const firstVersion = Object.assign(new Version(), {
id: '1', id: '1',
version: 1, version: 1,
created: new Date(2020, 1, 1), created: new Date(2020, 1, 1),
summary: 'first version', summary: 'first version',
versionhistory: createSuccessfulRemoteDataObject$(versionHistory) versionhistory: createSuccessfulRemoteDataObject$(versionHistory)
skipping to change at line 51 skipping to change at line 54
version: createSuccessfulRemoteDataObject$(firstVersion) version: createSuccessfulRemoteDataObject$(firstVersion)
}); });
const latestItem = Object.assign(new Item(), { const latestItem = Object.assign(new Item(), {
id: 'latest_item_id', id: 'latest_item_id',
uuid: 'latest_item_id', uuid: 'latest_item_id',
handle: '123456789/2', handle: '123456789/2',
version: createSuccessfulRemoteDataObject$(latestVersion) version: createSuccessfulRemoteDataObject$(latestVersion)
}); });
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) const versionHistoryServiceSpy = jasmine.createSpyObj('versionHistoryService',
) ['getVersions', 'getLatestVersionFromHistory$', 'isLatest$', ]
}); );
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
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 === latestVers
ion.version));
versionHistoryServiceSpy.getVersions.and.returnValue(createSuccessfulRemoteD
ataObject$(createPaginatedList(versions)));
versionHistoryServiceSpy.getLatestVersionFromHistory$.and.returnValue(of(lat
estVersion));
versionHistoryServiceSpy.isLatest$.and.callFake(isLatestFcn);
})); }));
describe('when the item is the latest version', () => { describe('when the item is the latest version', () => {
beforeEach(() => { beforeEach(() => {
initComponentWithItem(latestItem); initComponentWithItem(latestItem);
}); });
it('should not display a notice', () => { it('should not display a notice', () => {
const alert = fixture.debugElement.query(By.css('ds-alert')); const alert = fixture.debugElement.query(By.css('ds-alert'));
expect(alert).toBeNull(); expect(alert).toBeNull();
skipping to change at line 88 skipping to change at line 101
beforeEach(() => { beforeEach(() => {
initComponentWithItem(firstItem); initComponentWithItem(firstItem);
}); });
it('should display a notice', () => { it('should display a notice', () => {
const alert = fixture.debugElement.query(By.css('ds-alert')); const alert = fixture.debugElement.query(By.css('ds-alert'));
expect(alert).not.toBeNull(); expect(alert).not.toBeNull();
}); });
}); });
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((re
s) => {
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;
component.item = item; component.item = item;
fixture.detectChanges(); fixture.detectChanges();
} }
}); });
 End of changes. 7 change blocks. 
5 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)