mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-11 12:03:03 +00:00
68729: Version test cases
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { ItemVersionHistoryComponent } from './item-version-history.component';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { VarDirective } from '../../../shared/utils/var.directive';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { createSuccessfulRemoteDataObject } from '../../../shared/testing/utils';
|
||||
|
||||
describe('ItemVersionHistoryComponent', () => {
|
||||
let component: ItemVersionHistoryComponent;
|
||||
let fixture: ComponentFixture<ItemVersionHistoryComponent>;
|
||||
|
||||
const item = Object.assign(new Item(), {
|
||||
uuid: 'item-identifier-1',
|
||||
handle: '123456789/1',
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ItemVersionHistoryComponent, VarDirective],
|
||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ item: createSuccessfulRemoteDataObject(item) }) } }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ItemVersionHistoryComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should initialize the itemRD$ from the route\'s data', (done) => {
|
||||
component.itemRD$.subscribe((itemRD) => {
|
||||
expect(itemRD.payload).toBe(item);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
@@ -10,6 +10,9 @@ import { ActivatedRoute } from '@angular/router';
|
||||
selector: 'ds-item-version-history',
|
||||
templateUrl: './item-version-history.component.html'
|
||||
})
|
||||
/**
|
||||
* Component for listing and managing an item's version history
|
||||
*/
|
||||
export class ItemVersionHistoryComponent {
|
||||
/**
|
||||
* The item to display the version history for
|
||||
|
54
src/app/core/data/version-history-data.service.spec.ts
Normal file
54
src/app/core/data/version-history-data.service.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { RequestService } from './request.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { VersionHistoryDataService } from './version-history-data.service';
|
||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service-stub';
|
||||
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub';
|
||||
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
||||
import { GetRequest } from './request.models';
|
||||
|
||||
const url = 'fake-url';
|
||||
|
||||
describe('VersionHistoryDataService', () => {
|
||||
let service: VersionHistoryDataService;
|
||||
|
||||
let requestService: RequestService;
|
||||
let notificationsService: any;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let objectCache: ObjectCacheService;
|
||||
let halService: any;
|
||||
|
||||
beforeEach(() => {
|
||||
createService();
|
||||
});
|
||||
|
||||
describe('getVersions', () => {
|
||||
let result;
|
||||
|
||||
beforeEach(() => {
|
||||
result = service.getVersions(1);
|
||||
});
|
||||
|
||||
it('should configure a GET request', () => {
|
||||
expect(requestService.configure).toHaveBeenCalledWith(jasmine.any(GetRequest));
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Create a VersionHistoryDataService used for testing
|
||||
* @param requestEntry$ Supply a requestEntry to be returned by the REST API (optional)
|
||||
*/
|
||||
function createService(requestEntry$?) {
|
||||
requestService = getMockRequestService(requestEntry$);
|
||||
rdbService = jasmine.createSpyObj('rdbService', {
|
||||
buildList: jasmine.createSpy('buildList')
|
||||
});
|
||||
objectCache = jasmine.createSpyObj('objectCache', {
|
||||
remove: jasmine.createSpy('remove')
|
||||
});
|
||||
halService = new HALEndpointServiceStub(url);
|
||||
notificationsService = new NotificationsServiceStub();
|
||||
|
||||
service = new VersionHistoryDataService(requestService, rdbService, null, null, objectCache, halService, notificationsService, null, null);
|
||||
}
|
||||
});
|
@@ -0,0 +1,66 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { MetadataValue } from '../../../../core/shared/metadata.models';
|
||||
import { RouterStub } from '../../../testing/router-stub';
|
||||
import { createSuccessfulRemoteDataObject } from '../../../testing/utils';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||
import * as itemRouter from '../../../../+item-page/item-page-routing.module';
|
||||
import { EditItemVersionHistorySelectorComponent } from './edit-item-version-history-selector.component';
|
||||
|
||||
describe('EditItemVersionHistorySelectorComponent', () => {
|
||||
let component: EditItemVersionHistorySelectorComponent;
|
||||
let fixture: ComponentFixture<EditItemVersionHistorySelectorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const item = new Item();
|
||||
item.uuid = '1234-1234-1234-1234';
|
||||
item.metadata = { 'dc.title': [Object.assign(new MetadataValue(), { value: 'Item title', language: undefined })] };
|
||||
const router = new RouterStub();
|
||||
const itemRD = createSuccessfulRemoteDataObject(item);
|
||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||
const editPath = 'testEditVersionHistoryPath';
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [EditItemVersionHistorySelectorComponent],
|
||||
providers: [
|
||||
{ provide: NgbActiveModal, useValue: modalStub },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { root: { firstChild: { firstChild: { data: observableOf({ item: itemRD }) } } } }
|
||||
},
|
||||
{
|
||||
provide: Router, useValue: router
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOnProperty(itemRouter, 'getFullItemEditVersionHistoryPath').and.callFake(() => {
|
||||
return () => editPath;
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(EditItemVersionHistorySelectorComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call navigate on the router with the correct edit path when navigate is called', () => {
|
||||
component.navigate(item);
|
||||
expect(router.navigate).toHaveBeenCalledWith([editPath]);
|
||||
});
|
||||
|
||||
});
|
@@ -21,21 +21,21 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let version of versions?.page">
|
||||
<td>{{version?.version}}</td>
|
||||
<td>
|
||||
<tr *ngFor="let version of versions?.page" [id]="'version-row-' + version.id">
|
||||
<td class="version-row-element-version">{{version?.version}}</td>
|
||||
<td class="version-row-element-item">
|
||||
<span *ngVar="(version?.item | async)?.payload as item">
|
||||
<a *ngIf="item" [routerLink]="['/items', item?.id]">{{item?.handle}}</a>
|
||||
<span *ngIf="version?.id === itemVersion?.id">*</span>
|
||||
</span>
|
||||
</td>
|
||||
<td *ngIf="(hasEpersons$ | async)">
|
||||
<td *ngIf="(hasEpersons$ | async)" class="version-row-element-editor">
|
||||
<span *ngVar="(version?.eperson | async)?.payload as eperson">
|
||||
<a *ngIf="eperson" [href]="'mailto:' + eperson?.email">{{eperson?.name}}</a>
|
||||
</span>
|
||||
</td>
|
||||
<td>{{version?.created}}</td>
|
||||
<td>{{version?.summary}}</td>
|
||||
<td class="version-row-element-date">{{version?.created}}</td>
|
||||
<td class="version-row-element-summary">{{version?.summary}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@@ -0,0 +1,121 @@
|
||||
import { ItemVersionsComponent } from './item-versions.component';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { VarDirective } from '../../utils/var.directive';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { Version } from '../../../core/shared/version.model';
|
||||
import { VersionHistory } from '../../../core/shared/version-history.model';
|
||||
import { createPaginatedList, createSuccessfulRemoteDataObject$ } from '../../testing/utils';
|
||||
import { VersionHistoryDataService } from '../../../core/data/version-history-data.service';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
describe('ItemVersionsComponent', () => {
|
||||
let component: ItemVersionsComponent;
|
||||
let fixture: ComponentFixture<ItemVersionsComponent>;
|
||||
|
||||
const versionHistory = Object.assign(new VersionHistory(), {
|
||||
id: 1
|
||||
});
|
||||
const version1 = Object.assign(new Version(), {
|
||||
id: 1,
|
||||
version: 1,
|
||||
created: new Date(2020, 1, 1),
|
||||
summary: 'first version',
|
||||
versionhistory: createSuccessfulRemoteDataObject$(versionHistory)
|
||||
});
|
||||
const version2 = Object.assign(new Version(), {
|
||||
id: 2,
|
||||
version: 2,
|
||||
summary: 'second version',
|
||||
created: new Date(2020, 1, 2),
|
||||
versionhistory: createSuccessfulRemoteDataObject$(versionHistory)
|
||||
});
|
||||
const versions = [version1, version2];
|
||||
versionHistory.versions = createSuccessfulRemoteDataObject$(createPaginatedList(versions));
|
||||
const item1 = Object.assign(new Item(), {
|
||||
uuid: 'item-identifier-1',
|
||||
handle: '123456789/1',
|
||||
version: createSuccessfulRemoteDataObject$(version1)
|
||||
});
|
||||
const item2 = Object.assign(new Item(), {
|
||||
uuid: 'item-identifier-2',
|
||||
handle: '123456789/2',
|
||||
version: createSuccessfulRemoteDataObject$(version2)
|
||||
});
|
||||
const items = [item1, item2];
|
||||
version1.item = createSuccessfulRemoteDataObject$(item1);
|
||||
version2.item = createSuccessfulRemoteDataObject$(item2);
|
||||
const versionHistoryService = jasmine.createSpyObj('versionHistoryService', {
|
||||
getVersions: createSuccessfulRemoteDataObject$(createPaginatedList(versions))
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ItemVersionsComponent, VarDirective],
|
||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
||||
providers: [
|
||||
{ provide: VersionHistoryDataService, useValue: versionHistoryService }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ItemVersionsComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.item = item1;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it(`should display ${versions.length} rows`, () => {
|
||||
const rows = fixture.debugElement.queryAll(By.css('tbody tr'));
|
||||
expect(rows.length).toBe(versions.length);
|
||||
});
|
||||
|
||||
versions.forEach((version: Version, index: number) => {
|
||||
const versionItem = items[index];
|
||||
|
||||
it(`should display version ${version.version} in the correct column for version ${version.id}`, () => {
|
||||
const id = fixture.debugElement.query(By.css(`#version-row-${version.id} .version-row-element-version`));
|
||||
expect(id.nativeElement.textContent).toEqual('' + version.version);
|
||||
});
|
||||
|
||||
it(`should display item handle ${versionItem.handle} in the correct column for version ${version.id}`, () => {
|
||||
const item = fixture.debugElement.query(By.css(`#version-row-${version.id} .version-row-element-item`));
|
||||
expect(item.nativeElement.textContent).toContain(versionItem.handle);
|
||||
});
|
||||
|
||||
// This version's item is equal to the component's item (the selected item)
|
||||
// Check if the handle contains an asterisk
|
||||
if (item1.uuid === versionItem.uuid) {
|
||||
it('should add an asterisk to the handle of the selected item', () => {
|
||||
const item = fixture.debugElement.query(By.css(`#version-row-${version.id} .version-row-element-item`));
|
||||
expect(item.nativeElement.textContent).toContain('*');
|
||||
});
|
||||
}
|
||||
|
||||
it(`should display date ${version.created} in the correct column for version ${version.id}`, () => {
|
||||
const date = fixture.debugElement.query(By.css(`#version-row-${version.id} .version-row-element-date`));
|
||||
expect(date.nativeElement.textContent).toEqual('' + version.created);
|
||||
});
|
||||
|
||||
it(`should display summary ${version.summary} in the correct column for version ${version.id}`, () => {
|
||||
const summary = fixture.debugElement.query(By.css(`#version-row-${version.id} .version-row-element-summary`));
|
||||
expect(summary.nativeElement.textContent).toEqual(version.summary);
|
||||
});
|
||||
});
|
||||
|
||||
describe('switchPage', () => {
|
||||
const page = 5;
|
||||
|
||||
beforeEach(() => {
|
||||
component.switchPage(page);
|
||||
});
|
||||
|
||||
it('should set the option\'s currentPage to the new page', () => {
|
||||
expect(component.options.currentPage).toEqual(page);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user