mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
[CST-4499] Version history - Test item-versions.component
This commit is contained in:
@@ -110,7 +110,7 @@
|
|||||||
<ng-container *ngIf="(canEditVersion$(version) | async) && isThisBeingEdited(version)">
|
<ng-container *ngIf="(canEditVersion$(version) | async) && isThisBeingEdited(version)">
|
||||||
<button class="btn btn-sm"
|
<button class="btn btn-sm"
|
||||||
[ngClass]="isThisBeingEdited(version) ? 'btn-outline-warning' : 'btn-outline-primary'"
|
[ngClass]="isThisBeingEdited(version) ? 'btn-outline-warning' : 'btn-outline-primary'"
|
||||||
(click)="disableSummaryEditing()"
|
(click)="disableVersionEditing()"
|
||||||
title="{{'item.version.history.table.action.discardSummary' | translate}}">
|
title="{{'item.version.history.table.action.discardSummary' | translate}}">
|
||||||
<i class="fas fa-undo-alt fa-fw"></i>
|
<i class="fas fa-undo-alt fa-fw"></i>
|
||||||
</button>
|
</button>
|
||||||
|
@@ -11,7 +11,7 @@ import { VersionHistoryDataService } from '../../../core/data/version-history-da
|
|||||||
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, of as observableOf } from 'rxjs';
|
import { EMPTY, of, of as observableOf } from 'rxjs';
|
||||||
import { PaginationService } from '../../../core/pagination/pagination.service';
|
import { PaginationService } from '../../../core/pagination/pagination.service';
|
||||||
import { PaginationServiceStub } from '../../testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../../testing/pagination-service.stub';
|
||||||
import { AuthService } from '../../../core/auth/auth.service';
|
import { AuthService } from '../../../core/auth/auth.service';
|
||||||
@@ -25,7 +25,7 @@ import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
|||||||
import { WorkspaceitemDataService } from '../../../core/submission/workspaceitem-data.service';
|
import { WorkspaceitemDataService } from '../../../core/submission/workspaceitem-data.service';
|
||||||
import { WorkflowItemDataService } from '../../../core/submission/workflowitem-data.service';
|
import { WorkflowItemDataService } from '../../../core/submission/workflowitem-data.service';
|
||||||
|
|
||||||
describe('ItemVersionsComponent', () => {
|
fdescribe('ItemVersionsComponent', () => {
|
||||||
let component: ItemVersionsComponent;
|
let component: ItemVersionsComponent;
|
||||||
let fixture: ComponentFixture<ItemVersionsComponent>;
|
let fixture: ComponentFixture<ItemVersionsComponent>;
|
||||||
let authenticationService: AuthService;
|
let authenticationService: AuthService;
|
||||||
@@ -33,6 +33,7 @@ describe('ItemVersionsComponent', () => {
|
|||||||
let versionHistoryService: VersionHistoryDataService;
|
let versionHistoryService: VersionHistoryDataService;
|
||||||
let workspaceItemDataService: WorkspaceitemDataService;
|
let workspaceItemDataService: WorkspaceitemDataService;
|
||||||
let workflowItemDataService: WorkflowItemDataService;
|
let workflowItemDataService: WorkflowItemDataService;
|
||||||
|
let versionService: VersionDataService;
|
||||||
|
|
||||||
const versionHistory = Object.assign(new VersionHistory(), {
|
const versionHistory = Object.assign(new VersionHistory(), {
|
||||||
id: '1',
|
id: '1',
|
||||||
@@ -94,16 +95,18 @@ describe('ItemVersionsComponent', () => {
|
|||||||
getVersions: createSuccessfulRemoteDataObject$(createPaginatedList(versions)),
|
getVersions: createSuccessfulRemoteDataObject$(createPaginatedList(versions)),
|
||||||
});
|
});
|
||||||
const authenticationServiceSpy = jasmine.createSpyObj('authenticationService', {
|
const authenticationServiceSpy = jasmine.createSpyObj('authenticationService', {
|
||||||
isAuthenticated: observableOf(true),
|
isAuthenticated: observableOf(true),
|
||||||
setRedirectUrl: {}
|
setRedirectUrl: {}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
const authorizationServiceSpy = jasmine.createSpyObj('authorizationService', ['isAuthorized']);
|
const authorizationServiceSpy = jasmine.createSpyObj('authorizationService', ['isAuthorized']);
|
||||||
const workspaceItemDataServiceSpy = jasmine.createSpyObj('workspaceItemDataService', {
|
const workspaceItemDataServiceSpy = jasmine.createSpyObj('workspaceItemDataService', {
|
||||||
findByItem: of(undefined),
|
findByItem: EMPTY,
|
||||||
});
|
});
|
||||||
const workflowItemDataServiceSpy = jasmine.createSpyObj('workflowItemDataService', {
|
const workflowItemDataServiceSpy = jasmine.createSpyObj('workflowItemDataService', {
|
||||||
findByItem: of(undefined),
|
findByItem: EMPTY,
|
||||||
|
});
|
||||||
|
const versionServiceSpy = jasmine.createSpyObj('versionService', {
|
||||||
|
findById: EMPTY,
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
@@ -119,7 +122,7 @@ describe('ItemVersionsComponent', () => {
|
|||||||
{provide: AuthorizationDataService, useValue: authorizationServiceSpy},
|
{provide: AuthorizationDataService, useValue: authorizationServiceSpy},
|
||||||
{provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy},
|
{provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy},
|
||||||
{provide: ItemDataService, useValue: {}},
|
{provide: ItemDataService, useValue: {}},
|
||||||
{provide: VersionDataService, useValue: {}},
|
{provide: VersionDataService, useValue: versionServiceSpy},
|
||||||
{provide: WorkspaceitemDataService, useValue: workspaceItemDataServiceSpy},
|
{provide: WorkspaceitemDataService, useValue: workspaceItemDataServiceSpy},
|
||||||
{provide: WorkflowItemDataService, useValue: workflowItemDataServiceSpy},
|
{provide: WorkflowItemDataService, useValue: workflowItemDataServiceSpy},
|
||||||
],
|
],
|
||||||
@@ -131,6 +134,7 @@ describe('ItemVersionsComponent', () => {
|
|||||||
authorizationService = TestBed.inject(AuthorizationDataService);
|
authorizationService = TestBed.inject(AuthorizationDataService);
|
||||||
workspaceItemDataService = TestBed.inject(WorkspaceitemDataService);
|
workspaceItemDataService = TestBed.inject(WorkspaceitemDataService);
|
||||||
workflowItemDataService = TestBed.inject(WorkflowItemDataService);
|
workflowItemDataService = TestBed.inject(WorkflowItemDataService);
|
||||||
|
versionService = TestBed.inject(VersionDataService);
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -214,4 +218,53 @@ describe('ItemVersionsComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when onSummarySubmit() is called', () => {
|
||||||
|
const id = 'version-being-edited-id';
|
||||||
|
beforeEach(() => {
|
||||||
|
component.versionBeingEditedId = id;
|
||||||
|
});
|
||||||
|
it('should call versionService.findById', () => {
|
||||||
|
component.onSummarySubmit();
|
||||||
|
expect(versionService.findById).toHaveBeenCalledWith(id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when editing is enabled for an item', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
component.enableVersionEditing(version1);
|
||||||
|
});
|
||||||
|
it('should set all variables', () => {
|
||||||
|
expect(component.versionBeingEditedSummary).toEqual('first version');
|
||||||
|
expect(component.versionBeingEditedNumber).toEqual(1);
|
||||||
|
expect(component.versionBeingEditedId).toEqual('1');
|
||||||
|
});
|
||||||
|
it('isAnyBeingEdited should be true', () => {
|
||||||
|
expect(component.isAnyBeingEdited()).toBeTrue();
|
||||||
|
});
|
||||||
|
it('isThisBeingEdited should be true for version1', () => {
|
||||||
|
expect(component.isThisBeingEdited(version1)).toBeTrue();
|
||||||
|
});
|
||||||
|
it('isThisBeingEdited should be false for version2', () => {
|
||||||
|
expect(component.isThisBeingEdited(version2)).toBeFalse();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when editing is disabled', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
component.disableVersionEditing();
|
||||||
|
});
|
||||||
|
it('should unset all variables', () => {
|
||||||
|
expect(component.versionBeingEditedSummary).toBeUndefined();
|
||||||
|
expect(component.versionBeingEditedNumber).toBeUndefined();
|
||||||
|
expect(component.versionBeingEditedId).toBeUndefined();
|
||||||
|
});
|
||||||
|
it('isAnyBeingEdited should be false', () => {
|
||||||
|
expect(component.isAnyBeingEdited()).toBeFalse();
|
||||||
|
});
|
||||||
|
it('isThisBeingEdited should be false for all versions', () => {
|
||||||
|
expect(component.isThisBeingEdited(version1)).toBeFalse();
|
||||||
|
expect(component.isThisBeingEdited(version2)).toBeFalse();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -152,7 +152,7 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* The number of the version whose summary is currently being edited
|
* The number of the version whose summary is currently being edited
|
||||||
*/
|
*/
|
||||||
versionBeingEditedNumber: string;
|
versionBeingEditedNumber: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The id of the version whose summary is currently being edited
|
* The id of the version whose summary is currently being edited
|
||||||
@@ -195,14 +195,14 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
* True if the specified version is being edited
|
* True if the specified version is being edited
|
||||||
* (used to show input field and to change buttons for specified version)
|
* (used to show input field and to change buttons for specified version)
|
||||||
*/
|
*/
|
||||||
isThisBeingEdited(version): boolean {
|
isThisBeingEdited(version: Version): boolean {
|
||||||
return version?.version === this.versionBeingEditedNumber;
|
return version?.version === this.versionBeingEditedNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables editing for the specified version
|
* Enables editing for the specified version
|
||||||
*/
|
*/
|
||||||
enableVersionEditing(version): void {
|
enableVersionEditing(version: Version): void {
|
||||||
this.versionBeingEditedSummary = version?.summary;
|
this.versionBeingEditedSummary = version?.summary;
|
||||||
this.versionBeingEditedNumber = version?.version;
|
this.versionBeingEditedNumber = version?.version;
|
||||||
this.versionBeingEditedId = version?.id;
|
this.versionBeingEditedId = version?.id;
|
||||||
@@ -211,7 +211,7 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* Disables editing for the specified version and discards all pending changes
|
* Disables editing for the specified version and discards all pending changes
|
||||||
*/
|
*/
|
||||||
disableSummaryEditing(): void {
|
disableVersionEditing(): void {
|
||||||
this.versionBeingEditedSummary = undefined;
|
this.versionBeingEditedSummary = undefined;
|
||||||
this.versionBeingEditedNumber = undefined;
|
this.versionBeingEditedNumber = undefined;
|
||||||
this.versionBeingEditedId = undefined;
|
this.versionBeingEditedId = undefined;
|
||||||
@@ -248,7 +248,7 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
} else {
|
} else {
|
||||||
this.notificationsService.warning(null, this.translateService.get(failureMessageKey, {'version': this.versionBeingEditedNumber}));
|
this.notificationsService.warning(null, this.translateService.get(failureMessageKey, {'version': this.versionBeingEditedNumber}));
|
||||||
}
|
}
|
||||||
this.disableSummaryEditing();
|
this.disableVersionEditing();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user