mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 04:53:06 +00:00
[CST-4499] Version history - New version refactored (with tests)
This commit is contained in:
@@ -1,6 +1,23 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { VersionedItemComponent } from './versioned-item.component';
|
import { VersionedItemComponent } from './versioned-item.component';
|
||||||
|
import { VersionHistoryDataService } from '../../../../core/data/version-history-data.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { VersionDataService } from '../../../../core/data/version-data.service';
|
||||||
|
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||||
|
import { ItemVersionsSharedService } from '../../../../shared/item/item-versions/item-versions-shared.service';
|
||||||
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
||||||
|
import { buildPaginatedList } from '../../../../core/data/paginated-list.model';
|
||||||
|
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||||
|
import { MetadataMap } from '../../../../core/shared/metadata.models';
|
||||||
|
import { createRelationshipsObservable } from '../shared/item.component.spec';
|
||||||
|
|
||||||
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
|
bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])),
|
||||||
|
metadata: new MetadataMap(),
|
||||||
|
relationships: createRelationshipsObservable()
|
||||||
|
});
|
||||||
|
|
||||||
describe('VersionedItemComponent', () => {
|
describe('VersionedItemComponent', () => {
|
||||||
let component: VersionedItemComponent;
|
let component: VersionedItemComponent;
|
||||||
@@ -8,7 +25,14 @@ describe('VersionedItemComponent', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
declarations: [ VersionedItemComponent ]
|
declarations: [ VersionedItemComponent ],
|
||||||
|
providers: [
|
||||||
|
{ provide: VersionHistoryDataService, useValue: {} },
|
||||||
|
{ provide: TranslateService, useValue: {} },
|
||||||
|
{ provide: VersionDataService, useValue: {} },
|
||||||
|
{ provide: NotificationsService, useValue: {} },
|
||||||
|
{ provide: ItemVersionsSharedService, useValue: {} },
|
||||||
|
]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
});
|
});
|
||||||
@@ -16,6 +40,7 @@ describe('VersionedItemComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(VersionedItemComponent);
|
fixture = TestBed.createComponent(VersionedItemComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
component.object = mockItem;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -51,8 +51,7 @@ describe('VersionPageComponent', () => {
|
|||||||
{ provide: VersionDataService, useValue: {} },
|
{ provide: VersionDataService, useValue: {} },
|
||||||
{ provide: AuthService, useValue: authService },
|
{ provide: AuthService, useValue: authService },
|
||||||
],
|
],
|
||||||
})
|
}).compileComponents();
|
||||||
.compileComponents();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,12 +1,27 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { ItemVersionsSharedService } from './item-versions-shared.service';
|
import { ItemVersionsSharedService } from './item-versions-shared.service';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { VersionDataService } from '../../../core/data/version-data.service';
|
||||||
|
import { AuthService } from '../../../core/auth/auth.service';
|
||||||
|
import { NotificationsService } from '../../notifications/notifications.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { VersionHistoryDataService } from '../../../core/data/version-history-data.service';
|
||||||
|
|
||||||
describe('ItemVersionsSharedService', () => {
|
describe('ItemVersionsSharedService', () => {
|
||||||
let service: ItemVersionsSharedService;
|
let service: ItemVersionsSharedService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({});
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
{ provide: ActivatedRoute, useValue: {} },
|
||||||
|
{ provide: VersionDataService, useValue: {} },
|
||||||
|
{ provide: VersionHistoryDataService, useValue: {} },
|
||||||
|
{ provide: AuthService, useValue: {} },
|
||||||
|
{ provide: NotificationsService, useValue: {} },
|
||||||
|
{ provide: TranslateService, useValue: {} },
|
||||||
|
],
|
||||||
|
});
|
||||||
service = TestBed.inject(ItemVersionsSharedService);
|
service = TestBed.inject(ItemVersionsSharedService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -47,7 +47,7 @@
|
|||||||
<div class="btn-group edit-field">
|
<div class="btn-group edit-field">
|
||||||
<!--EDIT / SAVE-->
|
<!--EDIT / SAVE-->
|
||||||
<ng-container *ngIf="canEditVersion$(version) | async">
|
<ng-container *ngIf="canEditVersion$(version) | async">
|
||||||
<button class="btn btn-outline-primary btn-sm"
|
<button class="btn btn-outline-primary btn-sm version-row-element-edit"
|
||||||
*ngIf="!isThisBeingEdited(version)"
|
*ngIf="!isThisBeingEdited(version)"
|
||||||
[disabled]="isAnyBeingEdited()"
|
[disabled]="isAnyBeingEdited()"
|
||||||
(click)="enableVersionEditing(version)"
|
(click)="enableVersionEditing(version)"
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
<!--CREATE-->
|
<!--CREATE-->
|
||||||
<ng-container *ngIf="canCreateVersion$ | async">
|
<ng-container *ngIf="canCreateVersion$ | async">
|
||||||
<button class="btn btn-outline-primary btn-sm"
|
<button class="btn btn-outline-primary btn-sm version-row-element-create"
|
||||||
[disabled]="isAnyBeingEdited() || (hasDraftVersion$ | async)"
|
[disabled]="isAnyBeingEdited() || (hasDraftVersion$ | async)"
|
||||||
(click)="createNewVersion(version)"
|
(click)="createNewVersion(version)"
|
||||||
title="{{createVersionTitle$ | async | translate }}">
|
title="{{createVersionTitle$ | async | translate }}">
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
<!--DELETE-->
|
<!--DELETE-->
|
||||||
<ng-container *ngIf="canDeleteVersion$(version) | async">
|
<ng-container *ngIf="canDeleteVersion$(version) | async">
|
||||||
<button class="btn btn-sm"
|
<button class="btn btn-sm version-row-element-delete"
|
||||||
[ngClass]="isAnyBeingEdited() ? 'btn-outline-primary' : 'btn-outline-danger'"
|
[ngClass]="isAnyBeingEdited() ? 'btn-outline-primary' : 'btn-outline-danger'"
|
||||||
[disabled]="isAnyBeingEdited()"
|
[disabled]="isAnyBeingEdited()"
|
||||||
(click)="deleteVersion(version, version.id==itemVersion.id)"
|
(click)="deleteVersion(version, version.id==itemVersion.id)"
|
||||||
|
@@ -23,7 +23,7 @@ import { NotificationsServiceStub } from '../../testing/notifications-service.st
|
|||||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
||||||
|
|
||||||
fdescribe('ItemVersionsComponent', () => {
|
describe('ItemVersionsComponent', () => {
|
||||||
let component: ItemVersionsComponent;
|
let component: ItemVersionsComponent;
|
||||||
let fixture: ComponentFixture<ItemVersionsComponent>;
|
let fixture: ComponentFixture<ItemVersionsComponent>;
|
||||||
let authenticationService: AuthService;
|
let authenticationService: AuthService;
|
||||||
@@ -124,7 +124,7 @@ fdescribe('ItemVersionsComponent', () => {
|
|||||||
fixture = TestBed.createComponent(ItemVersionsComponent);
|
fixture = TestBed.createComponent(ItemVersionsComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
component.item = item1;
|
component.item = item1;
|
||||||
// component.displayActions = true;
|
component.displayActions = true;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -174,21 +174,22 @@ fdescribe('ItemVersionsComponent', () => {
|
|||||||
const canDelete = (featureID: FeatureID, url: string ) => of(featureID === FeatureID.CanDeleteVersion);
|
const canDelete = (featureID: FeatureID, url: string ) => of(featureID === FeatureID.CanDeleteVersion);
|
||||||
authorizationServiceSpy.isAuthorized.and.callFake(canDelete);
|
authorizationServiceSpy.isAuthorized.and.callFake(canDelete);
|
||||||
}));
|
}));
|
||||||
beforeEach(() => {
|
|
||||||
component.displayActions = true;
|
|
||||||
});
|
|
||||||
it('should not disable the delete button', () => {
|
it('should not disable the delete button', () => {
|
||||||
const rows = fixture.debugElement.queryAll(By.css('tbody tr'));
|
const deleteButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-delete`));
|
||||||
expect(rows.length).toBe(versions.length);
|
deleteButtons.forEach((btn) => {
|
||||||
console.log(rows);
|
expect(btn.nativeElement.disabled).toBe(false);
|
||||||
const btn = fixture.debugElement.query(By.css(`.version-row-element-delete`));
|
});
|
||||||
|
|
||||||
console.log(btn);
|
|
||||||
});
|
});
|
||||||
it('should disable other buttons', () => {
|
it('should disable other buttons', () => {
|
||||||
// expect
|
const createButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-create`));
|
||||||
|
createButtons.forEach((btn) => {
|
||||||
|
expect(btn.nativeElement.disabled).toBe(true);
|
||||||
|
});
|
||||||
|
const editButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-create`));
|
||||||
|
editButtons.forEach((btn) => {
|
||||||
|
expect(btn.nativeElement.disabled).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user