mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge remote-tracking branch 'origin/main' into CST-5307
# Conflicts: # src/app/core/data/data.service.ts
This commit is contained in:
@@ -2,8 +2,8 @@ import { CommonModule } from '@angular/common';
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
import { FormsModule, ReactiveFormsModule, FormArray, FormControl, FormGroup,Validators, NG_VALIDATORS, NG_ASYNC_VALIDATORS } from '@angular/forms';
|
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule, By } from '@angular/platform-browser';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
@@ -35,6 +35,7 @@ import { RouterMock } from '../../../shared/mocks/router.mock';
|
|||||||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||||
import { Operation } from 'fast-json-patch';
|
import { Operation } from 'fast-json-patch';
|
||||||
import { ValidateGroupExists } from './validators/group-exists.validator';
|
import { ValidateGroupExists } from './validators/group-exists.validator';
|
||||||
|
import { NoContent } from '../../../core/shared/NoContent.model';
|
||||||
|
|
||||||
describe('GroupFormComponent', () => {
|
describe('GroupFormComponent', () => {
|
||||||
let component: GroupFormComponent;
|
let component: GroupFormComponent;
|
||||||
@@ -87,6 +88,9 @@ describe('GroupFormComponent', () => {
|
|||||||
patch(group: Group, operations: Operation[]) {
|
patch(group: Group, operations: Operation[]) {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
||||||
|
return createSuccessfulRemoteDataObject$({});
|
||||||
|
},
|
||||||
cancelEditGroup(): void {
|
cancelEditGroup(): void {
|
||||||
this.activeGroup = null;
|
this.activeGroup = null;
|
||||||
},
|
},
|
||||||
@@ -348,4 +352,46 @@ describe('GroupFormComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('delete', () => {
|
||||||
|
let deleteButton;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
component.initialisePage();
|
||||||
|
|
||||||
|
component.canEdit$ = observableOf(true);
|
||||||
|
component.groupBeingEdited = {
|
||||||
|
permanent: false
|
||||||
|
} as Group;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
deleteButton = fixture.debugElement.query(By.css('.delete-button')).nativeElement;
|
||||||
|
|
||||||
|
spyOn(groupsDataServiceStub, 'delete').and.callThrough();
|
||||||
|
spyOn(groupsDataServiceStub, 'getActiveGroup').and.returnValue(observableOf({ id: 'active-group' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('if confirmed via modal', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
deleteButton.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
(document as any).querySelector('.modal-footer .confirm').click();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should call GroupDataService.delete', () => {
|
||||||
|
expect(groupsDataServiceStub.delete).toHaveBeenCalledWith('active-group');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('if canceled via modal', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
deleteButton.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
(document as any).querySelector('.modal-footer .cancel').click();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not call GroupDataService.delete', () => {
|
||||||
|
expect(groupsDataServiceStub.delete).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -426,7 +426,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
|||||||
.subscribe((rd: RemoteData<NoContent>) => {
|
.subscribe((rd: RemoteData<NoContent>) => {
|
||||||
if (rd.hasSucceeded) {
|
if (rd.hasSucceeded) {
|
||||||
this.notificationsService.success(this.translateService.get(this.messagePrefix + '.notification.deleted.success', { name: group.name }));
|
this.notificationsService.success(this.translateService.get(this.messagePrefix + '.notification.deleted.success', { name: group.name }));
|
||||||
this.reset();
|
this.onCancel();
|
||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(
|
this.notificationsService.error(
|
||||||
this.translateService.get(this.messagePrefix + '.notification.deleted.failure.title', { name: group.name }),
|
this.translateService.get(this.messagePrefix + '.notification.deleted.failure.title', { name: group.name }),
|
||||||
@@ -439,16 +439,6 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method will ensure that the page gets reset and that the cache is cleared
|
|
||||||
*/
|
|
||||||
reset() {
|
|
||||||
this.groupDataService.getBrowseEndpoint().pipe(take(1)).subscribe((href: string) => {
|
|
||||||
this.requestService.removeByHrefSubstring(href);
|
|
||||||
});
|
|
||||||
this.onCancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the current edit when component is destroyed & unsub all subscriptions
|
* Cancel the current edit when component is destroyed & unsub all subscriptions
|
||||||
*/
|
*/
|
||||||
|
@@ -79,7 +79,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<button *ngIf="!groupDto.group?.permanent && groupDto.ableToDelete"
|
<button *ngIf="!groupDto.group?.permanent && groupDto.ableToDelete"
|
||||||
(click)="deleteGroup(groupDto)" class="btn btn-outline-danger btn-sm"
|
(click)="deleteGroup(groupDto)" class="btn btn-outline-danger btn-sm btn-delete"
|
||||||
title="{{messagePrefix + 'table.edit.buttons.remove' | translate: {name: groupDto.group.name} }}">
|
title="{{messagePrefix + 'table.edit.buttons.remove' | translate: {name: groupDto.group.name} }}">
|
||||||
<i class="fas fa-trash-alt fa-fw"></i>
|
<i class="fas fa-trash-alt fa-fw"></i>
|
||||||
</button>
|
</button>
|
||||||
|
@@ -31,6 +31,7 @@ import { RouterMock } from '../../shared/mocks/router.mock';
|
|||||||
import { PaginationService } from '../../core/pagination/pagination.service';
|
import { PaginationService } from '../../core/pagination/pagination.service';
|
||||||
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
|
||||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||||
|
import { NoContent } from '../../core/shared/NoContent.model';
|
||||||
|
|
||||||
describe('GroupRegistryComponent', () => {
|
describe('GroupRegistryComponent', () => {
|
||||||
let component: GroupsRegistryComponent;
|
let component: GroupsRegistryComponent;
|
||||||
@@ -145,7 +146,10 @@ describe('GroupRegistryComponent', () => {
|
|||||||
totalPages: 1,
|
totalPages: 1,
|
||||||
currentPage: 1
|
currentPage: 1
|
||||||
}), [result]));
|
}), [result]));
|
||||||
}
|
},
|
||||||
|
delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
||||||
|
return createSuccessfulRemoteDataObject$({});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
dsoDataServiceStub = {
|
dsoDataServiceStub = {
|
||||||
findByHref(href: string): Observable<RemoteData<DSpaceObject>> {
|
findByHref(href: string): Observable<RemoteData<DSpaceObject>> {
|
||||||
@@ -301,4 +305,29 @@ describe('GroupRegistryComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('delete', () => {
|
||||||
|
let deleteButton;
|
||||||
|
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
spyOn(groupsDataServiceStub, 'delete').and.callThrough();
|
||||||
|
|
||||||
|
setIsAuthorized(true, true);
|
||||||
|
|
||||||
|
// force rerender after setup changes
|
||||||
|
component.search({ query: '' });
|
||||||
|
tick();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
// only mockGroup[0] is deletable, so we should only get one button
|
||||||
|
deleteButton = fixture.debugElement.query(By.css('.btn-delete')).nativeElement;
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should call GroupDataService.delete', () => {
|
||||||
|
deleteButton.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(groupsDataServiceStub.delete).toHaveBeenCalledWith(mockGroups[0].id);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -9,7 +9,7 @@ import {
|
|||||||
of as observableOf,
|
of as observableOf,
|
||||||
Subscription
|
Subscription
|
||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
import { catchError, map, switchMap, take, tap } from 'rxjs/operators';
|
import { catchError, map, switchMap, tap } from 'rxjs/operators';
|
||||||
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
|
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
|
||||||
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';
|
||||||
@@ -199,7 +199,6 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
if (rd.hasSucceeded) {
|
if (rd.hasSucceeded) {
|
||||||
this.deletedGroupsIds = [...this.deletedGroupsIds, group.group.id];
|
this.deletedGroupsIds = [...this.deletedGroupsIds, group.group.id];
|
||||||
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.group.name }));
|
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.group.name }));
|
||||||
this.reset();
|
|
||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(
|
this.notificationsService.error(
|
||||||
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.title', { name: group.group.name }),
|
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.title', { name: group.group.name }),
|
||||||
@@ -209,17 +208,6 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method will set everything to stale, which will cause the lists on this page to update.
|
|
||||||
*/
|
|
||||||
reset() {
|
|
||||||
this.groupService.getBrowseEndpoint().pipe(
|
|
||||||
take(1)
|
|
||||||
).subscribe((href: string) => {
|
|
||||||
this.requestService.setStaleByHrefSubstring(href);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the members (epersons embedded value of a group)
|
* Get the members (epersons embedded value of a group)
|
||||||
* @param group
|
* @param group
|
||||||
|
@@ -128,7 +128,6 @@ export class MetadataRegistryComponent {
|
|||||||
* Delete all the selected metadata schemas
|
* Delete all the selected metadata schemas
|
||||||
*/
|
*/
|
||||||
deleteSchemas() {
|
deleteSchemas() {
|
||||||
this.registryService.clearMetadataSchemaRequests().subscribe();
|
|
||||||
this.registryService.getSelectedMetadataSchemas().pipe(take(1)).subscribe(
|
this.registryService.getSelectedMetadataSchemas().pipe(take(1)).subscribe(
|
||||||
(schemas) => {
|
(schemas) => {
|
||||||
const tasks$ = [];
|
const tasks$ = [];
|
||||||
@@ -148,7 +147,6 @@ export class MetadataRegistryComponent {
|
|||||||
}
|
}
|
||||||
this.registryService.deselectAllMetadataSchema();
|
this.registryService.deselectAllMetadataSchema();
|
||||||
this.registryService.cancelEditMetadataSchema();
|
this.registryService.cancelEditMetadataSchema();
|
||||||
this.forceUpdateSchemas();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@@ -174,15 +174,12 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
const failedResponses = responses.filter((response: RemoteData<NoContent>) => response.hasFailed);
|
const failedResponses = responses.filter((response: RemoteData<NoContent>) => response.hasFailed);
|
||||||
if (successResponses.length > 0) {
|
if (successResponses.length > 0) {
|
||||||
this.showNotification(true, successResponses.length);
|
this.showNotification(true, successResponses.length);
|
||||||
this.registryService.clearMetadataFieldRequests();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (failedResponses.length > 0) {
|
if (failedResponses.length > 0) {
|
||||||
this.showNotification(false, failedResponses.length);
|
this.showNotification(false, failedResponses.length);
|
||||||
}
|
}
|
||||||
this.registryService.deselectAllMetadataField();
|
this.registryService.deselectAllMetadataField();
|
||||||
this.registryService.cancelEditMetadataField();
|
this.registryService.cancelEditMetadataField();
|
||||||
this.forceUpdateFields();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@@ -5,7 +5,6 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
|
|||||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||||
import { Collection } from '../../core/shared/collection.model';
|
import { Collection } from '../../core/shared/collection.model';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { RequestService } from '../../core/data/request.service';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that represents the page where a user can delete an existing Collection
|
* Component that represents the page where a user can delete an existing Collection
|
||||||
@@ -24,8 +23,7 @@ export class DeleteCollectionPageComponent extends DeleteComColPageComponent<Col
|
|||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected notifications: NotificationsService,
|
protected notifications: NotificationsService,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected requestService: RequestService
|
|
||||||
) {
|
) {
|
||||||
super(dsoDataService, router, route, notifications, translate, requestService);
|
super(dsoDataService, router, route, notifications, translate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,6 @@ import { NotificationsService } from '../../../shared/notifications/notification
|
|||||||
import { Item } from '../../../core/shared/item.model';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { ItemTemplateDataService } from '../../../core/data/item-template-data.service';
|
import { ItemTemplateDataService } from '../../../core/data/item-template-data.service';
|
||||||
import { Collection } from '../../../core/shared/collection.model';
|
import { Collection } from '../../../core/shared/collection.model';
|
||||||
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
|
|
||||||
import { RequestService } from '../../../core/data/request.service';
|
import { RequestService } from '../../../core/data/request.service';
|
||||||
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||||
import { getCollectionItemTemplateRoute } from '../../collection-page-routing-paths';
|
import { getCollectionItemTemplateRoute } from '../../collection-page-routing-paths';
|
||||||
@@ -49,9 +48,6 @@ describe('CollectionMetadataComponent', () => {
|
|||||||
success: {},
|
success: {},
|
||||||
error: {}
|
error: {}
|
||||||
});
|
});
|
||||||
const objectCache = jasmine.createSpyObj('objectCache', {
|
|
||||||
remove: {}
|
|
||||||
});
|
|
||||||
const requestService = jasmine.createSpyObj('requestService', {
|
const requestService = jasmine.createSpyObj('requestService', {
|
||||||
setStaleByHrefSubstring: {}
|
setStaleByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -65,8 +61,7 @@ describe('CollectionMetadataComponent', () => {
|
|||||||
{ provide: ItemTemplateDataService, useValue: itemTemplateServiceStub },
|
{ provide: ItemTemplateDataService, useValue: itemTemplateServiceStub },
|
||||||
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: createSuccessfulRemoteDataObject(collection) }) } } },
|
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: createSuccessfulRemoteDataObject(collection) }) } } },
|
||||||
{ provide: NotificationsService, useValue: notificationsService },
|
{ provide: NotificationsService, useValue: notificationsService },
|
||||||
{ provide: ObjectCacheService, useValue: objectCache },
|
{ provide: RequestService, useValue: requestService },
|
||||||
{ provide: RequestService, useValue: requestService }
|
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -95,21 +90,19 @@ describe('CollectionMetadataComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteItemTemplate', () => {
|
describe('deleteItemTemplate', () => {
|
||||||
describe('when delete returns a success', () => {
|
beforeEach(() => {
|
||||||
beforeEach(() => {
|
(itemTemplateService.deleteByCollectionID as jasmine.Spy).and.returnValue(observableOf(true));
|
||||||
(itemTemplateService.deleteByCollectionID as jasmine.Spy).and.returnValue(observableOf(true));
|
comp.deleteItemTemplate();
|
||||||
comp.deleteItemTemplate();
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
it('should call ItemTemplateService.deleteByCollectionID', () => {
|
||||||
|
expect(itemTemplateService.deleteByCollectionID).toHaveBeenCalledWith(template, 'collection-id');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when delete returns a success', () => {
|
||||||
it('should display a success notification', () => {
|
it('should display a success notification', () => {
|
||||||
expect(notificationsService.success).toHaveBeenCalled();
|
expect(notificationsService.success).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset related object and request cache', () => {
|
|
||||||
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith(collectionTemplateHref);
|
|
||||||
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith(template.self);
|
|
||||||
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith(collection.self);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when delete returns a failure', () => {
|
describe('when delete returns a failure', () => {
|
||||||
|
@@ -8,10 +8,9 @@ import { combineLatest as combineLatestObservable, Observable } from 'rxjs';
|
|||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { Item } from '../../../core/shared/item.model';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
||||||
import { switchMap, tap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
|
|
||||||
import { RequestService } from '../../../core/data/request.service';
|
import { RequestService } from '../../../core/data/request.service';
|
||||||
import { getCollectionItemTemplateRoute } from '../../collection-page-routing-paths';
|
import { getCollectionItemTemplateRoute } from '../../collection-page-routing-paths';
|
||||||
|
|
||||||
@@ -38,8 +37,7 @@ export class CollectionMetadataComponent extends ComcolMetadataComponent<Collect
|
|||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected objectCache: ObjectCacheService,
|
protected requestService: RequestService,
|
||||||
protected requestService: RequestService
|
|
||||||
) {
|
) {
|
||||||
super(collectionDataService, router, route, notificationsService, translate);
|
super(collectionDataService, router, route, notificationsService, translate);
|
||||||
}
|
}
|
||||||
@@ -93,23 +91,9 @@ export class CollectionMetadataComponent extends ComcolMetadataComponent<Collect
|
|||||||
getFirstSucceededRemoteDataPayload(),
|
getFirstSucceededRemoteDataPayload(),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
const templateHref$ = collection$.pipe(
|
combineLatestObservable(collection$, template$).pipe(
|
||||||
switchMap((collection) => this.itemTemplateService.getCollectionEndpoint(collection.id)),
|
switchMap(([collection, template]) => {
|
||||||
);
|
return this.itemTemplateService.deleteByCollectionID(template, collection.uuid);
|
||||||
|
|
||||||
combineLatestObservable(collection$, template$, templateHref$).pipe(
|
|
||||||
switchMap(([collection, template, templateHref]) => {
|
|
||||||
return this.itemTemplateService.deleteByCollectionID(template, collection.uuid).pipe(
|
|
||||||
tap((success: boolean) => {
|
|
||||||
if (success) {
|
|
||||||
this.objectCache.remove(templateHref);
|
|
||||||
this.objectCache.remove(template.self);
|
|
||||||
this.requestService.setStaleByHrefSubstring(template.self);
|
|
||||||
this.requestService.setStaleByHrefSubstring(templateHref);
|
|
||||||
this.requestService.setStaleByHrefSubstring(collection.self);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
).subscribe((success: boolean) => {
|
).subscribe((success: boolean) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@@ -5,7 +5,6 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { DeleteComColPageComponent } from '../../shared/comcol/comcol-forms/delete-comcol-page/delete-comcol-page.component';
|
import { DeleteComColPageComponent } from '../../shared/comcol/comcol-forms/delete-comcol-page/delete-comcol-page.component';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { RequestService } from '../../core/data/request.service';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that represents the page where a user can delete an existing Community
|
* Component that represents the page where a user can delete an existing Community
|
||||||
@@ -24,9 +23,8 @@ export class DeleteCommunityPageComponent extends DeleteComColPageComponent<Comm
|
|||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected notifications: NotificationsService,
|
protected notifications: NotificationsService,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected requestService: RequestService
|
|
||||||
) {
|
) {
|
||||||
super(dsoDataService, router, route, notifications, translate, requestService);
|
super(dsoDataService, router, route, notifications, translate);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ describe('objectCacheReducer', () => {
|
|||||||
alternativeLinks: [altLink1, altLink2],
|
alternativeLinks: [altLink1, altLink2],
|
||||||
timeCompleted: new Date().getTime(),
|
timeCompleted: new Date().getTime(),
|
||||||
msToLive: 900000,
|
msToLive: 900000,
|
||||||
requestUUID: requestUUID1,
|
requestUUIDs: [requestUUID1],
|
||||||
patches: [],
|
patches: [],
|
||||||
isDirty: false,
|
isDirty: false,
|
||||||
},
|
},
|
||||||
@@ -55,7 +55,7 @@ describe('objectCacheReducer', () => {
|
|||||||
alternativeLinks: [altLink3, altLink4],
|
alternativeLinks: [altLink3, altLink4],
|
||||||
timeCompleted: new Date().getTime(),
|
timeCompleted: new Date().getTime(),
|
||||||
msToLive: 900000,
|
msToLive: 900000,
|
||||||
requestUUID: selfLink2,
|
requestUUIDs: [selfLink2],
|
||||||
patches: [],
|
patches: [],
|
||||||
isDirty: false
|
isDirty: false
|
||||||
}
|
}
|
||||||
|
10
src/app/core/cache/object-cache.reducer.ts
vendored
10
src/app/core/cache/object-cache.reducer.ts
vendored
@@ -63,9 +63,11 @@ export class ObjectCacheEntry implements CacheEntry {
|
|||||||
msToLive: number;
|
msToLive: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The UUID of the request that caused this entry to be added
|
* The UUIDs of the requests that caused this entry to be added
|
||||||
|
* New UUIDs should be added to the front of the array
|
||||||
|
* to make retrieving the latest UUID easier.
|
||||||
*/
|
*/
|
||||||
requestUUID: string;
|
requestUUIDs: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of patches that were made on the client side to this entry, but haven't been sent to the server yet
|
* An array of patches that were made on the client side to this entry, but haven't been sent to the server yet
|
||||||
@@ -156,11 +158,11 @@ function addToObjectCache(state: ObjectCacheState, action: AddToObjectCacheActio
|
|||||||
data: action.payload.objectToCache,
|
data: action.payload.objectToCache,
|
||||||
timeCompleted: action.payload.timeCompleted,
|
timeCompleted: action.payload.timeCompleted,
|
||||||
msToLive: action.payload.msToLive,
|
msToLive: action.payload.msToLive,
|
||||||
requestUUID: action.payload.requestUUID,
|
requestUUIDs: [action.payload.requestUUID, ...(existing.requestUUIDs || [])],
|
||||||
isDirty: isNotEmpty(existing.patches),
|
isDirty: isNotEmpty(existing.patches),
|
||||||
patches: existing.patches || [],
|
patches: existing.patches || [],
|
||||||
alternativeLinks: [...(existing.alternativeLinks || []), ...newAltLinks]
|
alternativeLinks: [...(existing.alternativeLinks || []), ...newAltLinks]
|
||||||
}
|
} as ObjectCacheEntry
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
66
src/app/core/cache/object-cache.service.spec.ts
vendored
66
src/app/core/cache/object-cache.service.spec.ts
vendored
@@ -211,25 +211,69 @@ describe('ObjectCacheService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('has', () => {
|
describe('hasByHref', () => {
|
||||||
|
describe('with requestUUID not specified', () => {
|
||||||
|
describe('getByHref emits an object', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(service, 'getByHref').and.returnValue(observableOf(cacheEntry));
|
||||||
|
});
|
||||||
|
|
||||||
describe('getByHref emits an object', () => {
|
it('should return true', () => {
|
||||||
beforeEach(() => {
|
expect(service.hasByHref(selfLink)).toBe(true);
|
||||||
spyOn(service, 'getByHref').and.returnValue(observableOf(cacheEntry));
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true', () => {
|
describe('getByHref emits nothing', () => {
|
||||||
expect(service.hasByHref(selfLink)).toBe(true);
|
beforeEach(() => {
|
||||||
|
spyOn(service, 'getByHref').and.returnValue(empty());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false', () => {
|
||||||
|
expect(service.hasByHref(selfLink)).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getByHref emits nothing', () => {
|
describe('with requestUUID specified', () => {
|
||||||
beforeEach(() => {
|
describe('getByHref emits an object that includes the specified requestUUID', () => {
|
||||||
spyOn(service, 'getByHref').and.returnValue(empty());
|
beforeEach(() => {
|
||||||
|
spyOn(service, 'getByHref').and.returnValue(observableOf(Object.assign(cacheEntry, {
|
||||||
|
requestUUIDs: [
|
||||||
|
'something',
|
||||||
|
'something-else',
|
||||||
|
'specific-request',
|
||||||
|
]
|
||||||
|
})));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
expect(service.hasByHref(selfLink, 'specific-request')).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false', () => {
|
describe('getByHref emits an object that doesn\'t include the specified requestUUID', () => {
|
||||||
expect(service.hasByHref(selfLink)).toBe(false);
|
beforeEach(() => {
|
||||||
|
spyOn(service, 'getByHref').and.returnValue(observableOf(Object.assign(cacheEntry, {
|
||||||
|
requestUUIDs: [
|
||||||
|
'something',
|
||||||
|
'something-else',
|
||||||
|
]
|
||||||
|
})));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
expect(service.hasByHref(selfLink, 'specific-request')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getByHref emits nothing', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(service, 'getByHref').and.returnValue(empty());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false', () => {
|
||||||
|
expect(service.hasByHref(selfLink, 'specific-request')).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
4
src/app/core/cache/object-cache.service.ts
vendored
4
src/app/core/cache/object-cache.service.ts
vendored
@@ -197,7 +197,7 @@ export class ObjectCacheService {
|
|||||||
*/
|
*/
|
||||||
getRequestUUIDBySelfLink(selfLink: string): Observable<string> {
|
getRequestUUIDBySelfLink(selfLink: string): Observable<string> {
|
||||||
return this.getByHref(selfLink).pipe(
|
return this.getByHref(selfLink).pipe(
|
||||||
map((entry: ObjectCacheEntry) => entry.requestUUID),
|
map((entry: ObjectCacheEntry) => entry.requestUUIDs[0]),
|
||||||
distinctUntilChanged());
|
distinctUntilChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ export class ObjectCacheService {
|
|||||||
let result = false;
|
let result = false;
|
||||||
this.getByHref(href).subscribe((entry: ObjectCacheEntry) => {
|
this.getByHref(href).subscribe((entry: ObjectCacheEntry) => {
|
||||||
if (isNotEmpty(requestUUID)) {
|
if (isNotEmpty(requestUUID)) {
|
||||||
result = entry.requestUUID === requestUUID;
|
result = entry.requestUUIDs.includes(requestUUID);
|
||||||
} else {
|
} else {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,12 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
}
|
}
|
||||||
} as Store<CoreState>;
|
} as Store<CoreState>;
|
||||||
|
|
||||||
const objectCache = {} as ObjectCacheService;
|
const requestUUIDs = ['some', 'uuid'];
|
||||||
|
|
||||||
|
const objectCache = jasmine.createSpyObj('objectCache', {
|
||||||
|
getByHref: observableOf({ requestUUIDs })
|
||||||
|
}) as ObjectCacheService;
|
||||||
|
|
||||||
const halEndpointService = {
|
const halEndpointService = {
|
||||||
getEndpoint(linkPath: string): Observable<string> {
|
getEndpoint(linkPath: string): Observable<string> {
|
||||||
return cold('a', { a: bitstreamFormatsEndpoint });
|
return cold('a', { a: bitstreamFormatsEndpoint });
|
||||||
@@ -76,6 +81,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -96,6 +102,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -118,6 +125,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -139,6 +147,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -163,6 +172,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -186,6 +196,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -209,6 +220,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -231,6 +243,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -253,6 +266,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: cold('a', { a: responseCacheEntry }),
|
getByUUID: cold('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
@@ -273,6 +287,7 @@ describe('BitstreamFormatDataService', () => {
|
|||||||
send: {},
|
send: {},
|
||||||
getByHref: observableOf(responseCacheEntry),
|
getByHref: observableOf(responseCacheEntry),
|
||||||
getByUUID: hot('a', { a: responseCacheEntry }),
|
getByUUID: hot('a', { a: responseCacheEntry }),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
generateRequestId: 'request-id',
|
generateRequestId: 'request-id',
|
||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
|
@@ -22,6 +22,7 @@ import {
|
|||||||
import { BitstreamDataService } from './bitstream-data.service';
|
import { BitstreamDataService } from './bitstream-data.service';
|
||||||
import { CoreState } from '../core-state.model';
|
import { CoreState } from '../core-state.model';
|
||||||
import { FindListOptions } from './find-list-options.model';
|
import { FindListOptions } from './find-list-options.model';
|
||||||
|
import { Bitstream } from '../shared/bitstream.model';
|
||||||
|
|
||||||
const LINK_NAME = 'test';
|
const LINK_NAME = 'test';
|
||||||
|
|
||||||
@@ -244,4 +245,75 @@ describe('ComColDataService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('deleteLogo', () => {
|
||||||
|
let dso;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
dso = {
|
||||||
|
_links: {
|
||||||
|
logo: {
|
||||||
|
href: 'logo-href'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when DSO has no logo', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
dso.logo = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a failed RD', (done) => {
|
||||||
|
service.deleteLogo(dso).subscribe(rd => {
|
||||||
|
expect(rd.hasFailed).toBeTrue();
|
||||||
|
expect(bitstreamDataService.deleteByHref).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when DSO has a logo', () => {
|
||||||
|
let logo;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
logo = Object.assign(new Bitstream, {
|
||||||
|
id: 'logo-id',
|
||||||
|
_links: {
|
||||||
|
self: {
|
||||||
|
href: 'logo-href',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('that can be retrieved', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
dso.logo = createSuccessfulRemoteDataObject$(logo);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call BitstreamDataService.deleteByHref', (done) => {
|
||||||
|
service.deleteLogo(dso).subscribe(rd => {
|
||||||
|
expect(rd.hasSucceeded).toBeTrue();
|
||||||
|
expect(bitstreamDataService.deleteByHref).toHaveBeenCalledWith('logo-href');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('that cannot be retrieved', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
dso.logo = createFailedRemoteDataObject$(logo);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call BitstreamDataService.deleteByHref', (done) => {
|
||||||
|
service.deleteLogo(dso).subscribe(rd => {
|
||||||
|
expect(rd.hasFailed).toBeTrue();
|
||||||
|
expect(bitstreamDataService.deleteByHref).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -11,7 +11,11 @@ import { ObjectCacheService } from '../cache/object-cache.service';
|
|||||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
import {
|
||||||
|
createFailedRemoteDataObject,
|
||||||
|
createSuccessfulRemoteDataObject,
|
||||||
|
createSuccessfulRemoteDataObject$,
|
||||||
|
} from '../../shared/remote-data.utils';
|
||||||
import { ChangeAnalyzer } from './change-analyzer';
|
import { ChangeAnalyzer } from './change-analyzer';
|
||||||
import { DataService } from './data.service';
|
import { DataService } from './data.service';
|
||||||
import { PatchRequest } from './request.models';
|
import { PatchRequest } from './request.models';
|
||||||
@@ -25,9 +29,12 @@ import { RemoteData } from './remote-data';
|
|||||||
import { RequestEntryState } from './request-entry-state.model';
|
import { RequestEntryState } from './request-entry-state.model';
|
||||||
import { CoreState } from '../core-state.model';
|
import { CoreState } from '../core-state.model';
|
||||||
import { FindListOptions } from './find-list-options.model';
|
import { FindListOptions } from './find-list-options.model';
|
||||||
|
import { fakeAsync, tick } from '@angular/core/testing';
|
||||||
|
|
||||||
const endpoint = 'https://rest.api/core';
|
const endpoint = 'https://rest.api/core';
|
||||||
|
|
||||||
|
const BOOLEAN = { f: false, t: true };
|
||||||
|
|
||||||
class TestService extends DataService<any> {
|
class TestService extends DataService<any> {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -86,6 +93,9 @@ describe('DataService', () => {
|
|||||||
},
|
},
|
||||||
getObjectBySelfLink: () => {
|
getObjectBySelfLink: () => {
|
||||||
/* empty */
|
/* empty */
|
||||||
|
},
|
||||||
|
getByHref: () => {
|
||||||
|
/* empty */
|
||||||
}
|
}
|
||||||
} as any;
|
} as any;
|
||||||
store = {} as Store<CoreState>;
|
store = {} as Store<CoreState>;
|
||||||
@@ -833,4 +843,149 @@ describe('DataService', () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('invalidateByHref', () => {
|
||||||
|
let getByHrefSpy: jasmine.Spy;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
getByHrefSpy = spyOn(objectCache, 'getByHref').and.returnValue(observableOf({
|
||||||
|
requestUUIDs: ['request1', 'request2', 'request3']
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call setStaleByUUID for every request associated with this DSO', (done) => {
|
||||||
|
service.invalidateByHref('some-href').subscribe((ok) => {
|
||||||
|
expect(ok).toBeTrue();
|
||||||
|
expect(getByHrefSpy).toHaveBeenCalledWith('some-href');
|
||||||
|
expect(requestService.setStaleByUUID).toHaveBeenCalledWith('request1');
|
||||||
|
expect(requestService.setStaleByUUID).toHaveBeenCalledWith('request2');
|
||||||
|
expect(requestService.setStaleByUUID).toHaveBeenCalledWith('request3');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call setStaleByUUID even if not subscribing to returned Observable', fakeAsync(() => {
|
||||||
|
service.invalidateByHref('some-href');
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(getByHrefSpy).toHaveBeenCalledWith('some-href');
|
||||||
|
expect(requestService.setStaleByUUID).toHaveBeenCalledWith('request1');
|
||||||
|
expect(requestService.setStaleByUUID).toHaveBeenCalledWith('request2');
|
||||||
|
expect(requestService.setStaleByUUID).toHaveBeenCalledWith('request3');
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should return an Observable that only emits true once all requests are stale', () => {
|
||||||
|
testScheduler.run(({ cold, expectObservable }) => {
|
||||||
|
requestService.setStaleByUUID.and.callFake((uuid) => {
|
||||||
|
switch (uuid) { // fake requests becoming stale at different times
|
||||||
|
case 'request1':
|
||||||
|
return cold('--(t|)', BOOLEAN);
|
||||||
|
case 'request2':
|
||||||
|
return cold('----(t|)', BOOLEAN);
|
||||||
|
case 'request3':
|
||||||
|
return cold('------(t|)', BOOLEAN);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const done$ = service.invalidateByHref('some-href');
|
||||||
|
|
||||||
|
// emit true as soon as the final request is stale
|
||||||
|
expectObservable(done$).toBe('------(t|)', BOOLEAN);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('delete', () => {
|
||||||
|
let MOCK_SUCCEEDED_RD;
|
||||||
|
let MOCK_FAILED_RD;
|
||||||
|
|
||||||
|
let invalidateByHrefSpy: jasmine.Spy;
|
||||||
|
let buildFromRequestUUIDSpy: jasmine.Spy;
|
||||||
|
let getIDHrefObsSpy: jasmine.Spy;
|
||||||
|
let deleteByHrefSpy: jasmine.Spy;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
invalidateByHrefSpy = spyOn(service, 'invalidateByHref').and.returnValue(observableOf(true));
|
||||||
|
buildFromRequestUUIDSpy = spyOn(rdbService, 'buildFromRequestUUID').and.callThrough();
|
||||||
|
getIDHrefObsSpy = spyOn(service, 'getIDHrefObs').and.callThrough();
|
||||||
|
deleteByHrefSpy = spyOn(service, 'deleteByHref').and.callThrough();
|
||||||
|
|
||||||
|
MOCK_SUCCEEDED_RD = createSuccessfulRemoteDataObject({});
|
||||||
|
MOCK_FAILED_RD = createFailedRemoteDataObject('something went wrong');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should retrieve href by ID and call deleteByHref', () => {
|
||||||
|
getIDHrefObsSpy.and.returnValue(observableOf('some-href'));
|
||||||
|
buildFromRequestUUIDSpy.and.returnValue(createSuccessfulRemoteDataObject$({}));
|
||||||
|
|
||||||
|
service.delete('some-id', ['a', 'b', 'c']).subscribe(rd => {
|
||||||
|
expect(getIDHrefObsSpy).toHaveBeenCalledWith('some-id');
|
||||||
|
expect(deleteByHrefSpy).toHaveBeenCalledWith('some-href', ['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('deleteByHref', () => {
|
||||||
|
it('should call invalidateByHref if the DELETE request succeeds', (done) => {
|
||||||
|
buildFromRequestUUIDSpy.and.returnValue(observableOf(MOCK_SUCCEEDED_RD));
|
||||||
|
|
||||||
|
service.deleteByHref('some-href').subscribe(rd => {
|
||||||
|
expect(rd).toBe(MOCK_SUCCEEDED_RD);
|
||||||
|
expect(invalidateByHrefSpy).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call invalidateByHref even if not subscribing to returned Observable', fakeAsync(() => {
|
||||||
|
buildFromRequestUUIDSpy.and.returnValue(observableOf(MOCK_SUCCEEDED_RD));
|
||||||
|
|
||||||
|
service.deleteByHref('some-href');
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(invalidateByHrefSpy).toHaveBeenCalled();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not call invalidateByHref if the DELETE request fails', (done) => {
|
||||||
|
buildFromRequestUUIDSpy.and.returnValue(observableOf(MOCK_FAILED_RD));
|
||||||
|
|
||||||
|
service.deleteByHref('some-href').subscribe(rd => {
|
||||||
|
expect(rd).toBe(MOCK_FAILED_RD);
|
||||||
|
expect(invalidateByHrefSpy).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should wait for invalidateByHref before emitting', () => {
|
||||||
|
testScheduler.run(({ cold, expectObservable }) => {
|
||||||
|
buildFromRequestUUIDSpy.and.returnValue(
|
||||||
|
cold('(r|)', { r: MOCK_SUCCEEDED_RD}) // RD emits right away
|
||||||
|
);
|
||||||
|
invalidateByHrefSpy.and.returnValue(
|
||||||
|
cold('----(t|)', BOOLEAN) // but we pretend that setting requests to stale takes longer
|
||||||
|
);
|
||||||
|
|
||||||
|
const done$ = service.deleteByHref('some-href');
|
||||||
|
expectObservable(done$).toBe(
|
||||||
|
'----(r|)', { r: MOCK_SUCCEEDED_RD} // ...and expect the returned Observable to wait until that's done
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should wait for the DELETE request to resolve before emitting', () => {
|
||||||
|
testScheduler.run(({ cold, expectObservable }) => {
|
||||||
|
buildFromRequestUUIDSpy.and.returnValue(
|
||||||
|
cold('----(r|)', { r: MOCK_SUCCEEDED_RD}) // the request takes a while
|
||||||
|
);
|
||||||
|
invalidateByHrefSpy.and.returnValue(
|
||||||
|
cold('(t|)', BOOLEAN) // but we pretend that setting to stale happens sooner
|
||||||
|
); // e.g.: maybe already stale before this call?
|
||||||
|
|
||||||
|
const done$ = service.deleteByHref('some-href');
|
||||||
|
expectObservable(done$).toBe(
|
||||||
|
'----(r|)', { r: MOCK_SUCCEEDED_RD} // ...and expect the returned Observable to wait for the request
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { Operation } from 'fast-json-patch';
|
import { Operation } from 'fast-json-patch';
|
||||||
import { Observable, of as observableOf } from 'rxjs';
|
import { AsyncSubject, combineLatest, from as observableFrom, Observable, of as observableOf } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
distinctUntilChanged,
|
distinctUntilChanged,
|
||||||
filter,
|
filter,
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
take,
|
take,
|
||||||
takeWhile,
|
takeWhile,
|
||||||
tap,
|
tap,
|
||||||
|
toArray
|
||||||
} from 'rxjs/operators';
|
} from 'rxjs/operators';
|
||||||
import { hasValue, isNotEmpty, isNotEmptyOperator } from '../../shared/empty.util';
|
import { hasValue, isNotEmpty, isNotEmptyOperator } from '../../shared/empty.util';
|
||||||
import { NotificationOptions } from '../../shared/notifications/models/notification-options.model';
|
import { NotificationOptions } from '../../shared/notifications/models/notification-options.model';
|
||||||
@@ -21,11 +22,12 @@ import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
|||||||
import { getClassForType } from '../cache/builders/build-decorators';
|
import { getClassForType } from '../cache/builders/build-decorators';
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
import { RequestParam } from '../cache/models/request-param.model';
|
import { RequestParam } from '../cache/models/request-param.model';
|
||||||
|
import { ObjectCacheEntry } from '../cache/object-cache.reducer';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { DSpaceSerializer } from '../dspace-rest/dspace.serializer';
|
import { DSpaceSerializer } from '../dspace-rest/dspace.serializer';
|
||||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { getFirstSucceededRemoteData, getRemoteDataPayload, } from '../shared/operators';
|
import { getFirstCompletedRemoteData, getFirstSucceededRemoteData, getRemoteDataPayload } from '../shared/operators';
|
||||||
import { URLCombiner } from '../url-combiner/url-combiner';
|
import { URLCombiner } from '../url-combiner/url-combiner';
|
||||||
import { ChangeAnalyzer } from './change-analyzer';
|
import { ChangeAnalyzer } from './change-analyzer';
|
||||||
import { PaginatedList } from './paginated-list.model';
|
import { PaginatedList } from './paginated-list.model';
|
||||||
@@ -573,6 +575,38 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
|
|||||||
return result$;
|
return result$;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidate an existing DSpaceObject by marking all requests it is included in as stale
|
||||||
|
* @param objectId The id of the object to be invalidated
|
||||||
|
* @return An Observable that will emit `true` once all requests are stale
|
||||||
|
*/
|
||||||
|
invalidate(objectId: string): Observable<boolean> {
|
||||||
|
return this.getIDHrefObs(objectId).pipe(
|
||||||
|
switchMap((href: string) => this.invalidateByHref(href))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidate an existing DSpaceObject by marking all requests it is included in as stale
|
||||||
|
* @param href The self link of the object to be invalidated
|
||||||
|
* @return An Observable that will emit `true` once all requests are stale
|
||||||
|
*/
|
||||||
|
invalidateByHref(href: string): Observable<boolean> {
|
||||||
|
const done$ = new AsyncSubject<boolean>();
|
||||||
|
|
||||||
|
this.objectCache.getByHref(href).pipe(
|
||||||
|
switchMap((oce: ObjectCacheEntry) => observableFrom(oce.requestUUIDs).pipe(
|
||||||
|
mergeMap((requestUUID: string) => this.requestService.setStaleByUUID(requestUUID)),
|
||||||
|
toArray(),
|
||||||
|
)),
|
||||||
|
).subscribe(() => {
|
||||||
|
done$.next(true);
|
||||||
|
done$.complete();
|
||||||
|
});
|
||||||
|
|
||||||
|
return done$;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an existing DSpace Object on the server
|
* Delete an existing DSpace Object on the server
|
||||||
* @param objectId The id of the object to be removed
|
* @param objectId The id of the object to be removed
|
||||||
@@ -594,6 +628,7 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
|
|||||||
* metadata should be saved as real metadata
|
* metadata should be saved as real metadata
|
||||||
* @return A RemoteData observable with an empty payload, but still representing the state of the request: statusCode,
|
* @return A RemoteData observable with an empty payload, but still representing the state of the request: statusCode,
|
||||||
* errorMessage, timeCompleted, etc
|
* errorMessage, timeCompleted, etc
|
||||||
|
* Only emits once all request related to the DSO has been invalidated.
|
||||||
*/
|
*/
|
||||||
deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
||||||
const requestId = this.requestService.generateRequestId();
|
const requestId = this.requestService.generateRequestId();
|
||||||
@@ -612,7 +647,27 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
|
|||||||
}
|
}
|
||||||
this.requestService.send(request);
|
this.requestService.send(request);
|
||||||
|
|
||||||
return this.rdbService.buildFromRequestUUID(requestId);
|
const response$ = this.rdbService.buildFromRequestUUID(requestId);
|
||||||
|
|
||||||
|
const invalidated$ = new AsyncSubject<boolean>();
|
||||||
|
response$.pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
switchMap((rd: RemoteData<NoContent>) => {
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
return this.invalidateByHref(href);
|
||||||
|
} else {
|
||||||
|
return [true];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
).subscribe(() => {
|
||||||
|
invalidated$.next(true);
|
||||||
|
invalidated$.complete();
|
||||||
|
});
|
||||||
|
|
||||||
|
return combineLatest([response$, invalidated$]).pipe(
|
||||||
|
filter(([_, invalidated]) => invalidated),
|
||||||
|
map(([response, _]) => response),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -8,7 +8,7 @@ import { defaultUUID, getMockUUIDService } from '../../shared/mocks/uuid.service
|
|||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { coreReducers} from '../core.reducers';
|
import { coreReducers} from '../core.reducers';
|
||||||
import { UUIDService } from '../shared/uuid.service';
|
import { UUIDService } from '../shared/uuid.service';
|
||||||
import { RequestConfigureAction, RequestExecuteAction } from './request.actions';
|
import { RequestConfigureAction, RequestExecuteAction, RequestStaleAction } from './request.actions';
|
||||||
import {
|
import {
|
||||||
DeleteRequest,
|
DeleteRequest,
|
||||||
GetRequest,
|
GetRequest,
|
||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
PutRequest
|
PutRequest
|
||||||
} from './request.models';
|
} from './request.models';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
import { fakeAsync, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
import { storeModuleConfig } from '../../app.reducer';
|
import { storeModuleConfig } from '../../app.reducer';
|
||||||
import { MockStore, provideMockStore } from '@ngrx/store/testing';
|
import { MockStore, provideMockStore } from '@ngrx/store/testing';
|
||||||
import { RequestEntryState } from './request-entry-state.model';
|
import { RequestEntryState } from './request-entry-state.model';
|
||||||
@@ -426,7 +426,7 @@ describe('RequestService', () => {
|
|||||||
describe('and it is cached', () => {
|
describe('and it is cached', () => {
|
||||||
describe('in the ObjectCache', () => {
|
describe('in the ObjectCache', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
(objectCache.getByHref as any).and.returnValue(observableOf({ requestUUID: 'some-uuid' }));
|
(objectCache.getByHref as any).and.returnValue(observableOf({ requestUUIDs: ['some-uuid'] }));
|
||||||
spyOn(serviceAsAny, 'hasByHref').and.returnValue(false);
|
spyOn(serviceAsAny, 'hasByHref').and.returnValue(false);
|
||||||
spyOn(serviceAsAny, 'hasByUUID').and.returnValue(true);
|
spyOn(serviceAsAny, 'hasByUUID').and.returnValue(true);
|
||||||
});
|
});
|
||||||
@@ -596,4 +596,33 @@ describe('RequestService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('setStaleByUUID', () => {
|
||||||
|
let dispatchSpy: jasmine.Spy;
|
||||||
|
let getByUUIDSpy: jasmine.Spy;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
dispatchSpy = spyOn(store, 'dispatch');
|
||||||
|
getByUUIDSpy = spyOn(service, 'getByUUID').and.callThrough();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should dispatch a RequestStaleAction', () => {
|
||||||
|
service.setStaleByUUID('something');
|
||||||
|
const firstAction = dispatchSpy.calls.argsFor(0)[0];
|
||||||
|
expect(firstAction).toBeInstanceOf(RequestStaleAction);
|
||||||
|
expect(firstAction.payload).toEqual({ uuid: 'something' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an Observable that emits true as soon as the request is stale', fakeAsync(() => {
|
||||||
|
dispatchSpy.and.callFake(() => { /* empty */ }); // don't actually set as stale
|
||||||
|
getByUUIDSpy.and.returnValue(cold('a-b--c--d-', { // but fake the state in the cache
|
||||||
|
a: { state: RequestEntryState.ResponsePending },
|
||||||
|
b: { state: RequestEntryState.Success },
|
||||||
|
c: { state: RequestEntryState.SuccessStale },
|
||||||
|
d: { state: RequestEntryState.Error },
|
||||||
|
}));
|
||||||
|
|
||||||
|
const done$ = service.setStaleByUUID('something');
|
||||||
|
expect(done$).toBeObservable(cold('-----(t|)', { t: true }));
|
||||||
|
}));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -311,6 +311,21 @@ export class RequestService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark a request as stale
|
||||||
|
* @param uuid the UUID of the request
|
||||||
|
* @return an Observable that will emit true once the Request becomes stale
|
||||||
|
*/
|
||||||
|
setStaleByUUID(uuid: string): Observable<boolean> {
|
||||||
|
this.store.dispatch(new RequestStaleAction(uuid));
|
||||||
|
|
||||||
|
return this.getByUUID(uuid).pipe(
|
||||||
|
map((request: RequestEntry) => isStale(request.state)),
|
||||||
|
filter((stale: boolean) => stale),
|
||||||
|
take(1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a GET request is in the cache or if it's still pending
|
* Check if a GET request is in the cache or if it's still pending
|
||||||
* @param {GetRequest} request The request to check
|
* @param {GetRequest} request The request to check
|
||||||
@@ -339,7 +354,7 @@ export class RequestService {
|
|||||||
.subscribe((entry: ObjectCacheEntry) => {
|
.subscribe((entry: ObjectCacheEntry) => {
|
||||||
// if the object cache has a match, check if the request that the object came with is
|
// if the object cache has a match, check if the request that the object came with is
|
||||||
// still valid
|
// still valid
|
||||||
inObjCache = this.hasByUUID(entry.requestUUID);
|
inObjCache = this.hasByUUID(entry.requestUUIDs[0]);
|
||||||
}).unsubscribe();
|
}).unsubscribe();
|
||||||
|
|
||||||
// we should send the request if it isn't cached
|
// we should send the request if it isn't cached
|
||||||
|
@@ -21,7 +21,7 @@ import { EPersonDataService } from './eperson-data.service';
|
|||||||
import { EPerson } from './models/eperson.model';
|
import { EPerson } from './models/eperson.model';
|
||||||
import { EPersonMock, EPersonMock2 } from '../../shared/testing/eperson.mock';
|
import { EPersonMock, EPersonMock2 } from '../../shared/testing/eperson.mock';
|
||||||
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
import { createNoContentRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
import { getMockRemoteDataBuildServiceHrefMap } from '../../shared/mocks/remote-data-build.service.mock';
|
import { getMockRemoteDataBuildServiceHrefMap } from '../../shared/mocks/remote-data-build.service.mock';
|
||||||
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
|
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
|
||||||
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
|
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
|
||||||
@@ -287,13 +287,12 @@ describe('EPersonDataService', () => {
|
|||||||
|
|
||||||
describe('deleteEPerson', () => {
|
describe('deleteEPerson', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(service, 'findById').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMock));
|
spyOn(service, 'delete').and.returnValue(createNoContentRemoteDataObject$());
|
||||||
service.deleteEPerson(EPersonMock).subscribe();
|
service.deleteEPerson(EPersonMock).subscribe();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send DeleteRequest', () => {
|
it('should call DataService.delete with the EPerson\'s UUID', () => {
|
||||||
const expected = new DeleteRequest(requestService.generateRequestId(), epersonsEndpoint + '/' + EPersonMock.uuid);
|
expect(service.delete).toHaveBeenCalledWith(EPersonMock.id);
|
||||||
expect(requestService.send).toHaveBeenCalledWith(expected);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -386,6 +386,10 @@ describe('RegistryService', () => {
|
|||||||
result = registryService.deleteMetadataSchema(mockSchemasList[0].id);
|
result = registryService.deleteMetadataSchema(mockSchemasList[0].id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should defer to MetadataSchemaDataService.delete', () => {
|
||||||
|
expect(metadataSchemaService.delete).toHaveBeenCalledWith(`${mockSchemasList[0].id}`);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return a successful response', () => {
|
it('should return a successful response', () => {
|
||||||
result.subscribe((response: RemoteData<NoContent>) => {
|
result.subscribe((response: RemoteData<NoContent>) => {
|
||||||
expect(response.hasSucceeded).toBe(true);
|
expect(response.hasSucceeded).toBe(true);
|
||||||
@@ -400,6 +404,10 @@ describe('RegistryService', () => {
|
|||||||
result = registryService.deleteMetadataField(mockFieldsList[0].id);
|
result = registryService.deleteMetadataField(mockFieldsList[0].id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should defer to MetadataFieldDataService.delete', () => {
|
||||||
|
expect(metadataFieldService.delete).toHaveBeenCalledWith(`${mockFieldsList[0].id}`);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return a successful response', () => {
|
it('should return a successful response', () => {
|
||||||
result.subscribe((response: RemoteData<NoContent>) => {
|
result.subscribe((response: RemoteData<NoContent>) => {
|
||||||
expect(response.hasSucceeded).toBe(true);
|
expect(response.hasSucceeded).toBe(true);
|
||||||
|
@@ -147,7 +147,6 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
|||||||
// Perform the setup actions from above in order and display notifications
|
// Perform the setup actions from above in order and display notifications
|
||||||
removedResponses$.pipe(take(1)).subscribe((responses: RemoteData<NoContent>[]) => {
|
removedResponses$.pipe(take(1)).subscribe((responses: RemoteData<NoContent>[]) => {
|
||||||
this.displayNotifications('item.edit.bitstreams.notifications.remove', responses);
|
this.displayNotifications('item.edit.bitstreams.notifications.remove', responses);
|
||||||
this.reset();
|
|
||||||
this.submitting = false;
|
this.submitting = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -242,27 +241,6 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* De-cache the current item (it should automatically reload due to itemUpdateSubscription)
|
|
||||||
*/
|
|
||||||
reset() {
|
|
||||||
this.refreshItemCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the current item's cache from object- and request-cache
|
|
||||||
*/
|
|
||||||
refreshItemCache() {
|
|
||||||
this.bundles$.pipe(take(1)).subscribe((bundles: Bundle[]) => {
|
|
||||||
bundles.forEach((bundle: Bundle) => {
|
|
||||||
this.objectCache.remove(bundle.self);
|
|
||||||
this.requestService.removeByHrefSubstring(bundle.self);
|
|
||||||
});
|
|
||||||
this.objectCache.remove(this.item.self);
|
|
||||||
this.requestService.removeByHrefSubstring(this.item.self);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsubscribe from open subscriptions whenever the component gets destroyed
|
* Unsubscribe from open subscriptions whenever the component gets destroyed
|
||||||
*/
|
*/
|
||||||
|
@@ -2,7 +2,7 @@ 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 { VersionHistoryDataService } from '../../../../core/data/version-history-data.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
import { VersionDataService } from '../../../../core/data/version-data.service';
|
import { VersionDataService } from '../../../../core/data/version-data.service';
|
||||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||||
import { ItemVersionsSharedService } from '../../../../shared/item/item-versions/item-versions-shared.service';
|
import { ItemVersionsSharedService } from '../../../../shared/item/item-versions/item-versions-shared.service';
|
||||||
@@ -19,6 +19,7 @@ import { SearchService } from '../../../../core/shared/search/search.service';
|
|||||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||||
import { Version } from '../../../../core/shared/version.model';
|
import { Version } from '../../../../core/shared/version.model';
|
||||||
import { RouteService } from '../../../../core/services/route.service';
|
import { RouteService } from '../../../../core/services/route.service';
|
||||||
|
import { TranslateLoaderMock } from '../../../../shared/testing/translate-loader.mock';
|
||||||
|
|
||||||
const mockItem: Item = Object.assign(new Item(), {
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])),
|
bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])),
|
||||||
@@ -57,10 +58,17 @@ describe('VersionedItemComponent', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
declarations: [VersionedItemComponent, DummyComponent],
|
declarations: [VersionedItemComponent, DummyComponent],
|
||||||
imports: [RouterTestingModule],
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: TranslateLoaderMock,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy },
|
{ provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy },
|
||||||
{ provide: TranslateService, useValue: {} },
|
|
||||||
{ provide: VersionDataService, useValue: versionServiceSpy },
|
{ provide: VersionDataService, useValue: versionServiceSpy },
|
||||||
{ provide: NotificationsService, useValue: {} },
|
{ provide: NotificationsService, useValue: {} },
|
||||||
{ provide: ItemVersionsSharedService, useValue: {} },
|
{ provide: ItemVersionsSharedService, useValue: {} },
|
||||||
|
@@ -55,6 +55,9 @@ describe('ComColFormComponent', () => {
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const logo = {
|
||||||
|
id: 'logo'
|
||||||
|
};
|
||||||
const logoEndpoint = 'rest/api/logo/endpoint';
|
const logoEndpoint = 'rest/api/logo/endpoint';
|
||||||
const dsoService = Object.assign({
|
const dsoService = Object.assign({
|
||||||
getLogoEndpoint: () => observableOf(logoEndpoint),
|
getLogoEndpoint: () => observableOf(logoEndpoint),
|
||||||
@@ -207,7 +210,7 @@ describe('ComColFormComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
initComponent(Object.assign(new Community(), {
|
initComponent(Object.assign(new Community(), {
|
||||||
id: 'community-id',
|
id: 'community-id',
|
||||||
logo: createSuccessfulRemoteDataObject$({}),
|
logo: createSuccessfulRemoteDataObject$(logo),
|
||||||
_links: {
|
_links: {
|
||||||
self: { href: 'community-self' },
|
self: { href: 'community-self' },
|
||||||
logo: { href: 'community-logo' },
|
logo: { href: 'community-logo' },
|
||||||
@@ -225,28 +228,31 @@ describe('ComColFormComponent', () => {
|
|||||||
|
|
||||||
describe('submit with logo marked for deletion', () => {
|
describe('submit with logo marked for deletion', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
spyOn(dsoService, 'deleteLogo').and.callThrough();
|
||||||
comp.markLogoForDeletion = true;
|
comp.markLogoForDeletion = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should call dsoService.deleteLogo on the DSO', () => {
|
||||||
|
comp.onSubmit();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(dsoService.deleteLogo).toHaveBeenCalledWith(comp.dso);
|
||||||
|
});
|
||||||
|
|
||||||
describe('when dsoService.deleteLogo returns a successful response', () => {
|
describe('when dsoService.deleteLogo returns a successful response', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(dsoService, 'deleteLogo').and.returnValue(createSuccessfulRemoteDataObject$({}));
|
dsoService.deleteLogo.and.returnValue(createSuccessfulRemoteDataObject$({}));
|
||||||
comp.onSubmit();
|
comp.onSubmit();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display a success notification', () => {
|
it('should display a success notification', () => {
|
||||||
expect(notificationsService.success).toHaveBeenCalled();
|
expect(notificationsService.success).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove the object\'s cache', () => {
|
|
||||||
expect(requestServiceStub.removeByHrefSubstring).toHaveBeenCalled();
|
|
||||||
expect(objectCacheStub.remove).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when dsoService.deleteLogo returns an error response', () => {
|
describe('when dsoService.deleteLogo returns an error response', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(dsoService, 'deleteLogo').and.returnValue(createFailedRemoteDataObject$('Error', 500));
|
dsoService.deleteLogo.and.returnValue(createFailedRemoteDataObject$('Error', 500));
|
||||||
comp.onSubmit();
|
comp.onSubmit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -184,7 +184,6 @@ export class ComColFormComponent<T extends Collection | Community> implements On
|
|||||||
}
|
}
|
||||||
this.dso.logo = undefined;
|
this.dso.logo = undefined;
|
||||||
this.uploadFilesOptions.method = RestRequestMethod.POST;
|
this.uploadFilesOptions.method = RestRequestMethod.POST;
|
||||||
this.refreshCache();
|
|
||||||
this.finish.emit();
|
this.finish.emit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -68,7 +68,6 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
{
|
{
|
||||||
delete: createNoContentRemoteDataObject$(),
|
delete: createNoContentRemoteDataObject$(),
|
||||||
findByHref: jasmine.createSpy('findByHref'),
|
findByHref: jasmine.createSpy('findByHref'),
|
||||||
refreshCache: jasmine.createSpy('refreshCache')
|
|
||||||
});
|
});
|
||||||
|
|
||||||
routerStub = {
|
routerStub = {
|
||||||
@@ -79,10 +78,6 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
data: observableOf(community)
|
data: observableOf(community)
|
||||||
};
|
};
|
||||||
|
|
||||||
requestServiceStub = jasmine.createSpyObj('RequestService', {
|
|
||||||
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring')
|
|
||||||
});
|
|
||||||
|
|
||||||
translateServiceStub = jasmine.createSpyObj('TranslateService', {
|
translateServiceStub = jasmine.createSpyObj('TranslateService', {
|
||||||
instant: jasmine.createSpy('instant')
|
instant: jasmine.createSpy('instant')
|
||||||
});
|
});
|
||||||
@@ -99,7 +94,6 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
{ provide: ActivatedRoute, useValue: routeStub },
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||||
{ provide: TranslateService, useValue: translateServiceStub },
|
{ provide: TranslateService, useValue: translateServiceStub },
|
||||||
{ provide: RequestService, useValue: requestServiceStub }
|
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -159,7 +153,6 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(notificationsService.error).toHaveBeenCalled();
|
expect(notificationsService.error).toHaveBeenCalled();
|
||||||
expect(dsoDataService.refreshCache).not.toHaveBeenCalled();
|
|
||||||
expect(router.navigate).toHaveBeenCalled();
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -169,7 +162,6 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(notificationsService.success).toHaveBeenCalled();
|
expect(notificationsService.success).toHaveBeenCalled();
|
||||||
expect(dsoDataService.refreshCache).toHaveBeenCalled();
|
|
||||||
expect(router.navigate).toHaveBeenCalled();
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import { NotificationsService } from '../../../notifications/notifications.servi
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
|
import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
|
||||||
import { NoContent } from '../../../../core/shared/NoContent.model';
|
import { NoContent } from '../../../../core/shared/NoContent.model';
|
||||||
import { RequestService } from '../../../../core/data/request.service';
|
|
||||||
import { ComColDataService } from '../../../../core/data/comcol-data.service';
|
import { ComColDataService } from '../../../../core/data/comcol-data.service';
|
||||||
import { Community } from '../../../../core/shared/community.model';
|
import { Community } from '../../../../core/shared/community.model';
|
||||||
import { Collection } from '../../../../core/shared/collection.model';
|
import { Collection } from '../../../../core/shared/collection.model';
|
||||||
@@ -41,7 +40,6 @@ export class DeleteComColPageComponent<TDomain extends Community | Collection> i
|
|||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected notifications: NotificationsService,
|
protected notifications: NotificationsService,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected requestService: RequestService
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +59,6 @@ export class DeleteComColPageComponent<TDomain extends Community | Collection> i
|
|||||||
if (response.hasSucceeded) {
|
if (response.hasSucceeded) {
|
||||||
const successMessage = this.translate.instant((dso as any).type + '.delete.notification.success');
|
const successMessage = this.translate.instant((dso as any).type + '.delete.notification.success');
|
||||||
this.notifications.success(successMessage);
|
this.notifications.success(successMessage);
|
||||||
this.dsoDataService.refreshCache(dso);
|
|
||||||
} else {
|
} else {
|
||||||
const errorMessage = this.translate.instant((dso as any).type + '.delete.notification.fail');
|
const errorMessage = this.translate.instant((dso as any).type + '.delete.notification.fail');
|
||||||
this.notifications.error(errorMessage);
|
this.notifications.error(errorMessage);
|
||||||
|
@@ -46,27 +46,27 @@ describe('ConfirmationModalComponent', () => {
|
|||||||
|
|
||||||
describe('confirmPressed', () => {
|
describe('confirmPressed', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(component.response, 'next');
|
spyOn(component.response, 'emit');
|
||||||
component.confirmPressed();
|
component.confirmPressed();
|
||||||
});
|
});
|
||||||
it('should call the close method on the active modal', () => {
|
it('should call the close method on the active modal', () => {
|
||||||
expect(modalStub.close).toHaveBeenCalled();
|
expect(modalStub.close).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('behaviour subject should have true as next', () => {
|
it('behaviour subject should emit true', () => {
|
||||||
expect(component.response.next).toHaveBeenCalledWith(true);
|
expect(component.response.emit).toHaveBeenCalledWith(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('cancelPressed', () => {
|
describe('cancelPressed', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(component.response, 'next');
|
spyOn(component.response, 'emit');
|
||||||
component.cancelPressed();
|
component.cancelPressed();
|
||||||
});
|
});
|
||||||
it('should call the close method on the active modal', () => {
|
it('should call the close method on the active modal', () => {
|
||||||
expect(modalStub.close).toHaveBeenCalled();
|
expect(modalStub.close).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('behaviour subject should have false as next', () => {
|
it('behaviour subject should emit false', () => {
|
||||||
expect(component.response.next).toHaveBeenCalledWith(false);
|
expect(component.response.emit).toHaveBeenCalledWith(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ describe('ConfirmationModalComponent', () => {
|
|||||||
describe('when the click method emits on cancel button', () => {
|
describe('when the click method emits on cancel button', () => {
|
||||||
beforeEach(fakeAsync(() => {
|
beforeEach(fakeAsync(() => {
|
||||||
spyOn(component, 'close');
|
spyOn(component, 'close');
|
||||||
spyOn(component.response, 'next');
|
spyOn(component.response, 'emit');
|
||||||
debugElement.query(By.css('button.cancel')).triggerEventHandler('click', {
|
debugElement.query(By.css('button.cancel')).triggerEventHandler('click', {
|
||||||
preventDefault: () => {/**/
|
preventDefault: () => {/**/
|
||||||
}
|
}
|
||||||
@@ -99,15 +99,15 @@ describe('ConfirmationModalComponent', () => {
|
|||||||
it('should call the close method on the component', () => {
|
it('should call the close method on the component', () => {
|
||||||
expect(component.close).toHaveBeenCalled();
|
expect(component.close).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('behaviour subject should have false as next', () => {
|
it('behaviour subject should emit false', () => {
|
||||||
expect(component.response.next).toHaveBeenCalledWith(false);
|
expect(component.response.emit).toHaveBeenCalledWith(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the click method emits on confirm button', () => {
|
describe('when the click method emits on confirm button', () => {
|
||||||
beforeEach(fakeAsync(() => {
|
beforeEach(fakeAsync(() => {
|
||||||
spyOn(component, 'close');
|
spyOn(component, 'close');
|
||||||
spyOn(component.response, 'next');
|
spyOn(component.response, 'emit');
|
||||||
debugElement.query(By.css('button.confirm')).triggerEventHandler('click', {
|
debugElement.query(By.css('button.confirm')).triggerEventHandler('click', {
|
||||||
preventDefault: () => {/**/
|
preventDefault: () => {/**/
|
||||||
}
|
}
|
||||||
@@ -118,8 +118,8 @@ describe('ConfirmationModalComponent', () => {
|
|||||||
it('should call the close method on the component', () => {
|
it('should call the close method on the component', () => {
|
||||||
expect(component.close).toHaveBeenCalled();
|
expect(component.close).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('behaviour subject should have true as next', () => {
|
it('behaviour subject should emit false', () => {
|
||||||
expect(component.response.next).toHaveBeenCalledWith(true);
|
expect(component.response.emit).toHaveBeenCalledWith(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { Component, Input, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { Subject } from 'rxjs';
|
|
||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -24,7 +23,7 @@ export class ConfirmationModalComponent {
|
|||||||
* An event fired when the cancel or confirm button is clicked, with respectively false or true
|
* An event fired when the cancel or confirm button is clicked, with respectively false or true
|
||||||
*/
|
*/
|
||||||
@Output()
|
@Output()
|
||||||
response: Subject<boolean> = new Subject();
|
response = new EventEmitter<boolean>();
|
||||||
|
|
||||||
constructor(protected activeModal: NgbActiveModal) {
|
constructor(protected activeModal: NgbActiveModal) {
|
||||||
}
|
}
|
||||||
@@ -33,7 +32,7 @@ export class ConfirmationModalComponent {
|
|||||||
* Confirm the action that led to the modal
|
* Confirm the action that led to the modal
|
||||||
*/
|
*/
|
||||||
confirmPressed() {
|
confirmPressed() {
|
||||||
this.response.next(true);
|
this.response.emit(true);
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ export class ConfirmationModalComponent {
|
|||||||
* Cancel the action that led to the modal and close modal
|
* Cancel the action that led to the modal and close modal
|
||||||
*/
|
*/
|
||||||
cancelPressed() {
|
cancelPressed() {
|
||||||
this.response.next(false);
|
this.response.emit(false);
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,7 +46,7 @@ describe('IdleModalComponent', () => {
|
|||||||
|
|
||||||
describe('extendSessionPressed', () => {
|
describe('extendSessionPressed', () => {
|
||||||
beforeEach(fakeAsync(() => {
|
beforeEach(fakeAsync(() => {
|
||||||
spyOn(component.response, 'next');
|
spyOn(component.response, 'emit');
|
||||||
component.extendSessionPressed();
|
component.extendSessionPressed();
|
||||||
}));
|
}));
|
||||||
it('should set idle to false', () => {
|
it('should set idle to false', () => {
|
||||||
@@ -55,8 +55,8 @@ describe('IdleModalComponent', () => {
|
|||||||
it('should close the modal', () => {
|
it('should close the modal', () => {
|
||||||
expect(modalStub.close).toHaveBeenCalled();
|
expect(modalStub.close).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('response \'closed\' should have true as next', () => {
|
it('response \'closed\' should emit true', () => {
|
||||||
expect(component.response.next).toHaveBeenCalledWith(true);
|
expect(component.response.emit).toHaveBeenCalledWith(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ describe('IdleModalComponent', () => {
|
|||||||
|
|
||||||
describe('closePressed', () => {
|
describe('closePressed', () => {
|
||||||
beforeEach(fakeAsync(() => {
|
beforeEach(fakeAsync(() => {
|
||||||
spyOn(component.response, 'next');
|
spyOn(component.response, 'emit');
|
||||||
component.closePressed();
|
component.closePressed();
|
||||||
}));
|
}));
|
||||||
it('should set idle to false', () => {
|
it('should set idle to false', () => {
|
||||||
@@ -83,8 +83,8 @@ describe('IdleModalComponent', () => {
|
|||||||
it('should close the modal', () => {
|
it('should close the modal', () => {
|
||||||
expect(modalStub.close).toHaveBeenCalled();
|
expect(modalStub.close).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('response \'closed\' should have true as next', () => {
|
it('response \'closed\' should emit true', () => {
|
||||||
expect(component.response.next).toHaveBeenCalledWith(true);
|
expect(component.response.emit).toHaveBeenCalledWith(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
import { Component, OnInit, Output } from '@angular/core';
|
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
||||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../../environments/environment';
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
import { Subject } from 'rxjs';
|
|
||||||
import { hasValue } from '../empty.util';
|
import { hasValue } from '../empty.util';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppState } from '../../app.reducer';
|
import { AppState } from '../../app.reducer';
|
||||||
@@ -29,7 +28,7 @@ export class IdleModalComponent implements OnInit {
|
|||||||
* An event fired when the modal is closed
|
* An event fired when the modal is closed
|
||||||
*/
|
*/
|
||||||
@Output()
|
@Output()
|
||||||
response: Subject<boolean> = new Subject();
|
response = new EventEmitter<boolean>();
|
||||||
|
|
||||||
constructor(private activeModal: NgbActiveModal,
|
constructor(private activeModal: NgbActiveModal,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
@@ -84,6 +83,6 @@ export class IdleModalComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
closeModal() {
|
closeModal() {
|
||||||
this.activeModal.close();
|
this.activeModal.close();
|
||||||
this.response.next(true);
|
this.response.emit(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,12 +8,12 @@
|
|||||||
<p class="pb-2">{{ "item.version.delete.modal.text" | translate : {version: versionNumber} }}</p>
|
<p class="pb-2">{{ "item.version.delete.modal.text" | translate : {version: versionNumber} }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button class="btn btn-outline-secondary btn-sm"
|
<button class="btn btn-outline-secondary btn-sm cancel"
|
||||||
(click)="onModalClose()"
|
(click)="onModalClose()"
|
||||||
title="{{'item.version.delete.modal.button.cancel.tooltip' | translate}}">
|
title="{{'item.version.delete.modal.button.cancel.tooltip' | translate}}">
|
||||||
<i class="fas fa-times fa-fw"></i> {{'item.version.delete.modal.button.cancel' | translate}}
|
<i class="fas fa-times fa-fw"></i> {{'item.version.delete.modal.button.cancel' | translate}}
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-danger btn-sm"
|
<button class="btn btn-danger btn-sm confirm"
|
||||||
(click)="onModalSubmit()"
|
(click)="onModalSubmit()"
|
||||||
title="{{'item.version.delete.modal.button.confirm.tooltip' | translate}}">
|
title="{{'item.version.delete.modal.button.confirm.tooltip' | translate}}">
|
||||||
<i class="fas fa-check fa-fw"></i> {{'item.version.delete.modal.button.confirm' | translate}}
|
<i class="fas fa-check fa-fw"></i> {{'item.version.delete.modal.button.confirm' | translate}}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component, EventEmitter, Output } from '@angular/core';
|
||||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -7,6 +7,11 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
|||||||
styleUrls: ['./item-versions-delete-modal.component.scss']
|
styleUrls: ['./item-versions-delete-modal.component.scss']
|
||||||
})
|
})
|
||||||
export class ItemVersionsDeleteModalComponent {
|
export class ItemVersionsDeleteModalComponent {
|
||||||
|
/**
|
||||||
|
* An event fired when the cancel or confirm button is clicked, with respectively false or true
|
||||||
|
*/
|
||||||
|
@Output()
|
||||||
|
response = new EventEmitter<boolean>();
|
||||||
|
|
||||||
versionNumber: number;
|
versionNumber: number;
|
||||||
|
|
||||||
@@ -15,10 +20,12 @@ export class ItemVersionsDeleteModalComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onModalClose() {
|
onModalClose() {
|
||||||
|
this.response.emit(false);
|
||||||
this.activeModal.dismiss();
|
this.activeModal.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
onModalSubmit() {
|
onModalSubmit() {
|
||||||
|
this.response.emit(true);
|
||||||
this.activeModal.close();
|
this.activeModal.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,14 +1,15 @@
|
|||||||
import { ItemVersionsComponent } from './item-versions.component';
|
import { ItemVersionsComponent } from './item-versions.component';
|
||||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
import {
|
||||||
|
ComponentFixture, TestBed, waitForAsync
|
||||||
|
} from '@angular/core/testing';
|
||||||
import { VarDirective } from '../../utils/var.directive';
|
import { VarDirective } from '../../utils/var.directive';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
|
||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { Item } from '../../../core/shared/item.model';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { Version } from '../../../core/shared/version.model';
|
import { Version } from '../../../core/shared/version.model';
|
||||||
import { VersionHistory } from '../../../core/shared/version-history.model';
|
import { VersionHistory } from '../../../core/shared/version-history.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 { BrowserModule, 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 { EMPTY, of, of as observableOf } from 'rxjs';
|
import { EMPTY, of, of as observableOf } from 'rxjs';
|
||||||
@@ -17,7 +18,7 @@ import { PaginationServiceStub } from '../../testing/pagination-service.stub';
|
|||||||
import { AuthService } from '../../../core/auth/auth.service';
|
import { AuthService } from '../../../core/auth/auth.service';
|
||||||
import { VersionDataService } from '../../../core/data/version-data.service';
|
import { VersionDataService } from '../../../core/data/version-data.service';
|
||||||
import { ItemDataService } from '../../../core/data/item-data.service';
|
import { ItemDataService } from '../../../core/data/item-data.service';
|
||||||
import { FormBuilder } from '@angular/forms';
|
import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { NotificationsService } from '../../notifications/notifications.service';
|
import { NotificationsService } from '../../notifications/notifications.service';
|
||||||
import { NotificationsServiceStub } from '../../testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../testing/notifications-service.stub';
|
||||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||||
@@ -25,6 +26,9 @@ 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';
|
||||||
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
|
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
|
||||||
describe('ItemVersionsComponent', () => {
|
describe('ItemVersionsComponent', () => {
|
||||||
let component: ItemVersionsComponent;
|
let component: ItemVersionsComponent;
|
||||||
@@ -70,6 +74,7 @@ describe('ItemVersionsComponent', () => {
|
|||||||
versionHistory.versions = createSuccessfulRemoteDataObject$(createPaginatedList(versions));
|
versionHistory.versions = createSuccessfulRemoteDataObject$(createPaginatedList(versions));
|
||||||
|
|
||||||
const item1 = Object.assign(new Item(), { // is a workspace item
|
const item1 = Object.assign(new Item(), { // is a workspace item
|
||||||
|
id: 'item-identifier-1',
|
||||||
uuid: 'item-identifier-1',
|
uuid: 'item-identifier-1',
|
||||||
handle: '123456789/1',
|
handle: '123456789/1',
|
||||||
version: createSuccessfulRemoteDataObject$(version1),
|
version: createSuccessfulRemoteDataObject$(version1),
|
||||||
@@ -80,6 +85,7 @@ describe('ItemVersionsComponent', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const item2 = Object.assign(new Item(), {
|
const item2 = Object.assign(new Item(), {
|
||||||
|
id: 'item-identifier-2',
|
||||||
uuid: 'item-identifier-2',
|
uuid: 'item-identifier-2',
|
||||||
handle: '123456789/2',
|
handle: '123456789/2',
|
||||||
version: createSuccessfulRemoteDataObject$(version2),
|
version: createSuccessfulRemoteDataObject$(version2),
|
||||||
@@ -95,6 +101,8 @@ describe('ItemVersionsComponent', () => {
|
|||||||
|
|
||||||
const versionHistoryServiceSpy = jasmine.createSpyObj('versionHistoryService', {
|
const versionHistoryServiceSpy = jasmine.createSpyObj('versionHistoryService', {
|
||||||
getVersions: createSuccessfulRemoteDataObject$(createPaginatedList(versions)),
|
getVersions: createSuccessfulRemoteDataObject$(createPaginatedList(versions)),
|
||||||
|
getVersionHistoryFromVersion$: of(versionHistory),
|
||||||
|
getLatestVersionItemFromHistory$: of(item1), // called when version2 is deleted
|
||||||
});
|
});
|
||||||
const authenticationServiceSpy = jasmine.createSpyObj('authenticationService', {
|
const authenticationServiceSpy = jasmine.createSpyObj('authenticationService', {
|
||||||
isAuthenticated: observableOf(true),
|
isAuthenticated: observableOf(true),
|
||||||
@@ -117,11 +125,19 @@ describe('ItemVersionsComponent', () => {
|
|||||||
findByPropertyName: of(true),
|
findByPropertyName: of(true),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const itemDataServiceSpy = jasmine.createSpyObj('itemDataService', {
|
||||||
|
delete: createSuccessfulRemoteDataObject$({}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const routerSpy = jasmine.createSpyObj('router', {
|
||||||
|
navigateByUrl: null,
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ItemVersionsComponent, VarDirective],
|
declarations: [ItemVersionsComponent, VarDirective],
|
||||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
imports: [TranslateModule.forRoot(), CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: PaginationService, useValue: new PaginationServiceStub()},
|
{provide: PaginationService, useValue: new PaginationServiceStub()},
|
||||||
{provide: FormBuilder, useValue: new FormBuilder()},
|
{provide: FormBuilder, useValue: new FormBuilder()},
|
||||||
@@ -129,11 +145,12 @@ describe('ItemVersionsComponent', () => {
|
|||||||
{provide: AuthService, useValue: authenticationServiceSpy},
|
{provide: AuthService, useValue: authenticationServiceSpy},
|
||||||
{provide: AuthorizationDataService, useValue: authorizationServiceSpy},
|
{provide: AuthorizationDataService, useValue: authorizationServiceSpy},
|
||||||
{provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy},
|
{provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy},
|
||||||
{provide: ItemDataService, useValue: {}},
|
{provide: ItemDataService, useValue: itemDataServiceSpy},
|
||||||
{provide: VersionDataService, useValue: versionServiceSpy},
|
{provide: VersionDataService, useValue: versionServiceSpy},
|
||||||
{provide: WorkspaceitemDataService, useValue: workspaceItemDataServiceSpy},
|
{provide: WorkspaceitemDataService, useValue: workspaceItemDataServiceSpy},
|
||||||
{provide: WorkflowItemDataService, useValue: workflowItemDataServiceSpy},
|
{provide: WorkflowItemDataService, useValue: workflowItemDataServiceSpy},
|
||||||
{provide: ConfigurationDataService, useValue: configurationServiceSpy},
|
{provide: ConfigurationDataService, useValue: configurationServiceSpy},
|
||||||
|
{ provide: Router, useValue: routerSpy },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -277,4 +294,43 @@ describe('ItemVersionsComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when deleting a version', () => {
|
||||||
|
let deleteButton;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const canDelete = (featureID: FeatureID, url: string ) => of(featureID === FeatureID.CanDeleteVersion);
|
||||||
|
authorizationServiceSpy.isAuthorized.and.callFake(canDelete);
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
// delete the last version in the table (version2 → item2)
|
||||||
|
deleteButton = fixture.debugElement.queryAll(By.css('.version-row-element-delete'))[1].nativeElement;
|
||||||
|
|
||||||
|
itemDataServiceSpy.delete.calls.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('if confirmed via modal', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
deleteButton.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
(document as any).querySelector('.modal-footer .confirm').click();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should call ItemService.delete', () => {
|
||||||
|
expect(itemDataServiceSpy.delete).toHaveBeenCalledWith(item2.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('if canceled via modal', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
deleteButton.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
(document as any).querySelector('.modal-footer .cancel').click();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not call ItemService.delete', () => {
|
||||||
|
expect(itemDataServiceSpy.delete).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -283,44 +283,42 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
activeModal.componentInstance.firstVersion = false;
|
activeModal.componentInstance.firstVersion = false;
|
||||||
|
|
||||||
// On modal submit/dismiss
|
// On modal submit/dismiss
|
||||||
activeModal.result.then(() => {
|
activeModal.componentInstance.response.pipe(take(1)).subscribe((ok) => {
|
||||||
versionItem$.pipe(
|
if (ok) {
|
||||||
getFirstSucceededRemoteDataPayload<Item>(),
|
versionItem$.pipe(
|
||||||
// Retrieve version history and invalidate cache
|
getFirstSucceededRemoteDataPayload<Item>(),
|
||||||
mergeMap((item: Item) => combineLatest([
|
// Retrieve version history
|
||||||
of(item),
|
mergeMap((item: Item) => combineLatest([
|
||||||
this.versionHistoryService.getVersionHistoryFromVersion$(version).pipe(
|
of(item),
|
||||||
tap((versionHistory: VersionHistory) => {
|
this.versionHistoryService.getVersionHistoryFromVersion$(version)
|
||||||
this.versionHistoryService.invalidateVersionHistoryCache(versionHistory.id);
|
])),
|
||||||
})
|
// Delete item
|
||||||
)
|
mergeMap(([item, versionHistory]: [Item, VersionHistory]) => combineLatest([
|
||||||
])),
|
this.deleteItemAndGetResult$(item),
|
||||||
// Delete item
|
of(versionHistory)
|
||||||
mergeMap(([item, versionHistory]: [Item, VersionHistory]) => combineLatest([
|
])),
|
||||||
this.deleteItemAndGetResult$(item),
|
// Retrieve new latest version
|
||||||
of(versionHistory)
|
mergeMap(([deleteItemResult, versionHistory]: [boolean, VersionHistory]) => combineLatest([
|
||||||
])),
|
of(deleteItemResult),
|
||||||
// Retrieve new latest version
|
this.versionHistoryService.getLatestVersionItemFromHistory$(versionHistory).pipe(
|
||||||
mergeMap(([deleteItemResult, versionHistory]: [boolean, VersionHistory]) => combineLatest([
|
tap(() => {
|
||||||
of(deleteItemResult),
|
this.getAllVersions(of(versionHistory));
|
||||||
this.versionHistoryService.getLatestVersionItemFromHistory$(versionHistory).pipe(
|
}),
|
||||||
tap(() => {
|
)
|
||||||
this.getAllVersions(of(versionHistory));
|
])),
|
||||||
}),
|
).subscribe(([deleteHasSucceeded, newLatestVersionItem]: [boolean, Item]) => {
|
||||||
)
|
// Notify operation result and redirect to latest item
|
||||||
])),
|
if (deleteHasSucceeded) {
|
||||||
).subscribe(([deleteHasSucceeded, newLatestVersionItem]: [boolean, Item]) => {
|
this.notificationsService.success(null, this.translateService.get(successMessageKey, {'version': versionNumber}));
|
||||||
// Notify operation result and redirect to latest item
|
} else {
|
||||||
if (deleteHasSucceeded) {
|
this.notificationsService.error(null, this.translateService.get(failureMessageKey, {'version': versionNumber}));
|
||||||
this.notificationsService.success(null, this.translateService.get(successMessageKey, {'version': versionNumber}));
|
}
|
||||||
} else {
|
if (redirectToLatest) {
|
||||||
this.notificationsService.error(null, this.translateService.get(failureMessageKey, {'version': versionNumber}));
|
const path = getItemEditVersionhistoryRoute(newLatestVersionItem);
|
||||||
}
|
this.router.navigateByUrl(path);
|
||||||
if (redirectToLatest) {
|
}
|
||||||
const path = getItemEditVersionhistoryRoute(newLatestVersionItem);
|
});
|
||||||
this.router.navigateByUrl(path);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -13,6 +13,7 @@ export function getMockRequestService(requestEntry$: Observable<RequestEntry> =
|
|||||||
isCachedOrPending: false,
|
isCachedOrPending: false,
|
||||||
removeByHrefSubstring: observableOf(true),
|
removeByHrefSubstring: observableOf(true),
|
||||||
setStaleByHrefSubstring: observableOf(true),
|
setStaleByHrefSubstring: observableOf(true),
|
||||||
|
setStaleByUUID: observableOf(true),
|
||||||
hasByHref$: observableOf(false)
|
hasByHref$: observableOf(false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -343,6 +343,16 @@ describe('ResourcePoliciesComponent test suite', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should call ResourcePolicyService.delete for the checked policies', () => {
|
||||||
|
resourcePolicyService.delete.and.returnValue(observableOf(true));
|
||||||
|
scheduler = getTestScheduler();
|
||||||
|
scheduler.schedule(() => comp.deleteSelectedResourcePolicies());
|
||||||
|
scheduler.flush();
|
||||||
|
|
||||||
|
// only the first one is checked
|
||||||
|
expect(resourcePolicyService.delete).toHaveBeenCalledWith(resourcePolicy.id);
|
||||||
|
});
|
||||||
|
|
||||||
it('should notify success when delete is successful', () => {
|
it('should notify success when delete is successful', () => {
|
||||||
|
|
||||||
resourcePolicyService.delete.and.returnValue(observableOf(true));
|
resourcePolicyService.delete.and.returnValue(observableOf(true));
|
||||||
|
@@ -157,7 +157,6 @@ export class ResourcePoliciesComponent implements OnInit, OnDestroy {
|
|||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(null, this.translate.get('resource-policies.delete.failure.content'));
|
this.notificationsService.error(null, this.translate.get('resource-policies.delete.failure.content'));
|
||||||
}
|
}
|
||||||
this.requestService.setStaleByHrefSubstring(this.resourceUUID);
|
|
||||||
this.processingDelete$.next(false);
|
this.processingDelete$.next(false);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@@ -84,7 +84,7 @@ describe('SearchSwitchConfigurationComponent', () => {
|
|||||||
expect(childElements.length).toEqual(comp.configurationList.length);
|
expect(childElements.length).toEqual(comp.configurationList.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call onSelect method when selecting an option', () => {
|
it('should call onSelect method when selecting an option', waitForAsync(() => {
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
spyOn(comp, 'onSelect');
|
spyOn(comp, 'onSelect');
|
||||||
select = fixture.debugElement.query(By.css('select'));
|
select = fixture.debugElement.query(By.css('select'));
|
||||||
@@ -94,8 +94,7 @@ describe('SearchSwitchConfigurationComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(comp.onSelect).toHaveBeenCalled();
|
expect(comp.onSelect).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
it('should navigate to the route when selecting an option', () => {
|
it('should navigate to the route when selecting an option', () => {
|
||||||
spyOn((comp as any), 'getSearchLinkParts').and.returnValue([MYDSPACE_ROUTE]);
|
spyOn((comp as any), 'getSearchLinkParts').and.returnValue([MYDSPACE_ROUTE]);
|
||||||
|
@@ -7,6 +7,7 @@ import {
|
|||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
platformBrowserDynamicTesting
|
platformBrowserDynamicTesting
|
||||||
} from '@angular/platform-browser-dynamic/testing';
|
} from '@angular/platform-browser-dynamic/testing';
|
||||||
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
declare const require: any;
|
declare const require: any;
|
||||||
|
|
||||||
@@ -17,9 +18,11 @@ getTestBed().initTestEnvironment(
|
|||||||
{ teardown: { destroyAfterEach: false } }
|
{ teardown: { destroyAfterEach: false } }
|
||||||
);
|
);
|
||||||
|
|
||||||
// If store is mocked, reset state after each test (see https://ngrx.io/guide/migration/v13)
|
|
||||||
jasmine.getEnv().afterEach(() => {
|
jasmine.getEnv().afterEach(() => {
|
||||||
|
// If store is mocked, reset state after each test (see https://ngrx.io/guide/migration/v13)
|
||||||
getTestBed().inject(MockStore, null)?.resetSelectors();
|
getTestBed().inject(MockStore, null)?.resetSelectors();
|
||||||
|
// Close any leftover modals
|
||||||
|
getTestBed().inject(NgbModal, null)?.dismissAll?.();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Then we find all the tests.
|
// Then we find all the tests.
|
||||||
|
Reference in New Issue
Block a user