mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Fixed feedback
This commit is contained in:
@@ -27,8 +27,6 @@ let routerStub;
|
|||||||
let mockItemDataService: ItemDataService;
|
let mockItemDataService: ItemDataService;
|
||||||
let routeStub;
|
let routeStub;
|
||||||
let notificationsServiceStub;
|
let notificationsServiceStub;
|
||||||
let successfulRestResponse;
|
|
||||||
let failRestResponse;
|
|
||||||
|
|
||||||
describe('ItemDeleteComponent', () => {
|
describe('ItemDeleteComponent', () => {
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
@@ -46,14 +44,12 @@ describe('ItemDeleteComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mockItemDataService = jasmine.createSpyObj('mockItemDataService', {
|
mockItemDataService = jasmine.createSpyObj('mockItemDataService', {
|
||||||
delete: observableOf(new RestResponse(true, '200'))
|
delete: observableOf(true)
|
||||||
});
|
});
|
||||||
|
|
||||||
routeStub = {
|
routeStub = {
|
||||||
data: observableOf({
|
data: observableOf({
|
||||||
item: new RemoteData(false, false, true, null, {
|
item: new RemoteData(false, false, true, null, mockItem)
|
||||||
id: 'fake-id'
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,10 +59,10 @@ describe('ItemDeleteComponent', () => {
|
|||||||
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule.forRoot()],
|
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule.forRoot()],
|
||||||
declarations: [ItemDeleteComponent],
|
declarations: [ItemDeleteComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: ActivatedRoute, useValue: routeStub},
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
{provide: Router, useValue: routerStub},
|
{ provide: Router, useValue: routerStub },
|
||||||
{provide: ItemDataService, useValue: mockItemDataService},
|
{ provide: ItemDataService, useValue: mockItemDataService },
|
||||||
{provide: NotificationsService, useValue: notificationsServiceStub},
|
{ provide: NotificationsService, useValue: notificationsServiceStub },
|
||||||
], schemas: [
|
], schemas: [
|
||||||
CUSTOM_ELEMENTS_SCHEMA
|
CUSTOM_ELEMENTS_SCHEMA
|
||||||
]
|
]
|
||||||
@@ -74,9 +70,6 @@ describe('ItemDeleteComponent', () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
successfulRestResponse = new RestResponse(true, '200');
|
|
||||||
failRestResponse = new RestResponse(false, '500');
|
|
||||||
|
|
||||||
fixture = TestBed.createComponent(ItemDeleteComponent);
|
fixture = TestBed.createComponent(ItemDeleteComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -95,22 +88,21 @@ describe('ItemDeleteComponent', () => {
|
|||||||
|
|
||||||
describe('performAction', () => {
|
describe('performAction', () => {
|
||||||
it('should call delete function from the ItemDataService', () => {
|
it('should call delete function from the ItemDataService', () => {
|
||||||
spyOn(comp, 'processRestResponse');
|
spyOn(comp, 'notify');
|
||||||
comp.performAction();
|
comp.performAction();
|
||||||
|
expect(mockItemDataService.delete).toHaveBeenCalledWith(mockItem);
|
||||||
expect(mockItemDataService.delete).toHaveBeenCalledWith(mockItem.id);
|
expect(comp.notify).toHaveBeenCalled();
|
||||||
expect(comp.processRestResponse).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('processRestResponse', () => {
|
describe('notify', () => {
|
||||||
it('should navigate to the homepage on successful deletion of the item', () => {
|
it('should navigate to the homepage on successful deletion of the item', () => {
|
||||||
comp.processRestResponse(successfulRestResponse);
|
comp.notify(true);
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith(['']);
|
expect(routerStub.navigate).toHaveBeenCalledWith(['']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('processRestResponse', () => {
|
describe('notify', () => {
|
||||||
it('should navigate to the item edit page on failed deletion of the item', () => {
|
it('should navigate to the item edit page on failed deletion of the item', () => {
|
||||||
comp.processRestResponse(failRestResponse);
|
comp.notify(false);
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith([getItemEditPath('fake-id')]);
|
expect(routerStub.navigate).toHaveBeenCalledWith([getItemEditPath('fake-id')]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -19,20 +19,19 @@ export class ItemDeleteComponent extends AbstractSimpleItemActionComponent {
|
|||||||
* Perform the delete action to the item
|
* Perform the delete action to the item
|
||||||
*/
|
*/
|
||||||
performAction() {
|
performAction() {
|
||||||
this.itemDataService.delete(this.item.id).pipe(first()).subscribe(
|
this.itemDataService.delete(this.item).pipe(first()).subscribe(
|
||||||
(response: RestResponse) => {
|
(succeeded: boolean) => {
|
||||||
this.processRestResponse(response);
|
this.notify(succeeded);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the RestResponse retrieved from the server.
|
|
||||||
* When the item is successfully delete, navigate to the homepage, otherwise navigate back to the item edit page
|
* When the item is successfully delete, navigate to the homepage, otherwise navigate back to the item edit page
|
||||||
* @param response
|
* @param response
|
||||||
*/
|
*/
|
||||||
processRestResponse(response: RestResponse) {
|
notify(succeeded: boolean) {
|
||||||
if (response.isSuccessful) {
|
if (succeeded) {
|
||||||
this.notificationsService.success(this.translateService.get('item.edit.' + this.messageKey + '.success'));
|
this.notificationsService.success(this.translateService.get('item.edit.' + this.messageKey + '.success'));
|
||||||
this.router.navigate(['']);
|
this.router.navigate(['']);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -95,6 +95,11 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
|
|||||||
return this.rdbService.buildList<TNormalized, TDomain>(hrefObs) as Observable<RemoteData<PaginatedList<TDomain>>>;
|
return this.rdbService.buildList<TNormalized, TDomain>(hrefObs) as Observable<RemoteData<PaginatedList<TDomain>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the HREF for a specific object based on its identifier
|
||||||
|
* @param endpoint The base endpoint for the type of object
|
||||||
|
* @param resourceID The identifier for the object
|
||||||
|
*/
|
||||||
getIDHref(endpoint, resourceID): string {
|
getIDHref(endpoint, resourceID): string {
|
||||||
return `${endpoint}/${resourceID}`;
|
return `${endpoint}/${resourceID}`;
|
||||||
}
|
}
|
||||||
@@ -199,6 +204,11 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete an existing DSpace Object on the server
|
||||||
|
* @param dso The DSpace Object to be removed
|
||||||
|
* Return an observable that emits true when the deletion was successful, false when it failed
|
||||||
|
*/
|
||||||
delete(dso: TDomain): Observable<boolean> {
|
delete(dso: TDomain): Observable<boolean> {
|
||||||
const requestId = this.requestService.generateRequestId();
|
const requestId = this.requestService.generateRequestId();
|
||||||
|
|
||||||
|
@@ -162,25 +162,4 @@ describe('ItemDataService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getItemDeleteEndpoint', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
scheduler = getTestScheduler();
|
|
||||||
service = initTestService();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the endpoint to make an item private or public', () => {
|
|
||||||
const result = service.getItemDeleteEndpoint(scopeID);
|
|
||||||
const expected = cold('a', {a: ScopedItemEndpoint});
|
|
||||||
|
|
||||||
expect(result).toBeObservable(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete the item', () => {
|
|
||||||
const expected = new RestResponse(true, '200');
|
|
||||||
const result = service.delete(scopeID);
|
|
||||||
result.subscribe((v) => expect(v).toEqual(expected));
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -14,7 +14,7 @@ import { URLCombiner } from '../url-combiner/url-combiner';
|
|||||||
import { DataService } from './data.service';
|
import { DataService } from './data.service';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { DeleteRequest, FindAllOptions, PatchRequest, RestRequest } from './request.models';
|
import { FindAllOptions, PatchRequest, RestRequest } from './request.models';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
@@ -64,7 +64,7 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
|
|||||||
*/
|
*/
|
||||||
public getItemWithdrawEndpoint(itemId: string): Observable<string> {
|
public getItemWithdrawEndpoint(itemId: string): Observable<string> {
|
||||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||||
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
|
map((endpoint: string) => this.getIDHref(endpoint, itemId))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,17 +74,7 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
|
|||||||
*/
|
*/
|
||||||
public getItemDiscoverableEndpoint(itemId: string): Observable<string> {
|
public getItemDiscoverableEndpoint(itemId: string): Observable<string> {
|
||||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||||
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
|
map((endpoint: string) => this.getIDHref(endpoint, itemId))
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the endpoint to delete the item
|
|
||||||
* @param itemId
|
|
||||||
*/
|
|
||||||
public getItemDeleteEndpoint(itemId: string): Observable<string> {
|
|
||||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
|
||||||
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,22 +119,4 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
|
|||||||
map((requestEntry: RequestEntry) => requestEntry.response)
|
map((requestEntry: RequestEntry) => requestEntry.response)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the item
|
|
||||||
* @param itemId
|
|
||||||
*/
|
|
||||||
public delete(itemId: string) {
|
|
||||||
return this.getItemDeleteEndpoint(itemId).pipe(
|
|
||||||
distinctUntilChanged(),
|
|
||||||
map((endpointURL: string) =>
|
|
||||||
new DeleteRequest(this.requestService.generateRequestId(), endpointURL)
|
|
||||||
),
|
|
||||||
configureRequest(this.requestService),
|
|
||||||
map((request: RestRequest) => request.href),
|
|
||||||
getRequestFromRequestHref(this.requestService),
|
|
||||||
map((requestEntry: RequestEntry) => requestEntry.response)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -227,6 +227,9 @@ export class CreateRequest extends PostRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to delete an object based on its identifier
|
||||||
|
*/
|
||||||
export class DeleteByIDRequest extends DeleteRequest {
|
export class DeleteByIDRequest extends DeleteRequest {
|
||||||
constructor(
|
constructor(
|
||||||
uuid: string,
|
uuid: string,
|
||||||
|
Reference in New Issue
Block a user