mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 19:43:04 +00:00
[CSTPER-66] onConfirm tests executed within a scheduler and provided _links section on tested data
This commit is contained in:
@@ -32,6 +32,8 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
let translateServiceStub;
|
let translateServiceStub;
|
||||||
let requestServiceStub;
|
let requestServiceStub;
|
||||||
|
|
||||||
|
let scheduler;
|
||||||
|
|
||||||
const validUUID = 'valid-uuid';
|
const validUUID = 'valid-uuid';
|
||||||
const invalidUUID = 'invalid-uuid';
|
const invalidUUID = 'invalid-uuid';
|
||||||
const frontendURL = '/testType';
|
const frontendURL = '/testType';
|
||||||
@@ -109,34 +111,51 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
notificationsService = (comp as any).notifications;
|
notificationsService = (comp as any).notifications;
|
||||||
(comp as any).frontendURL = frontendURL;
|
(comp as any).frontendURL = frontendURL;
|
||||||
router = (comp as any).router;
|
router = (comp as any).router;
|
||||||
|
scheduler = getTestScheduler();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onConfirm', () => {
|
describe('onConfirm', () => {
|
||||||
let data1;
|
let data1;
|
||||||
let data2;
|
let data2;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
data1 = Object.assign(new Community(), {
|
data1 = {
|
||||||
uuid: validUUID,
|
dso: Object.assign(new Community(), {
|
||||||
metadata: [{
|
uuid: validUUID,
|
||||||
key: 'dc.title',
|
metadata: [{
|
||||||
value: 'test'
|
key: 'dc.title',
|
||||||
}]
|
value: 'test'
|
||||||
});
|
}]
|
||||||
|
}),
|
||||||
|
_links: {}
|
||||||
|
};
|
||||||
|
|
||||||
data2 = Object.assign(new Community(), {
|
data2 = {
|
||||||
uuid: invalidUUID,
|
dso: Object.assign(new Community(), {
|
||||||
metadata: [{
|
uuid: invalidUUID,
|
||||||
key: 'dc.title',
|
metadata: [{
|
||||||
value: 'test'
|
key: 'dc.title',
|
||||||
}]
|
value: 'test'
|
||||||
});
|
}]
|
||||||
|
}),
|
||||||
|
_links: {},
|
||||||
|
uploader: {
|
||||||
|
options: {
|
||||||
|
url: ''
|
||||||
|
},
|
||||||
|
queue: [],
|
||||||
|
/* tslint:disable:no-empty */
|
||||||
|
uploadAll: () => {}
|
||||||
|
/* tslint:enable:no-empty */
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show an error notification on failure', () => {
|
it('should show an error notification on failure', () => {
|
||||||
(dsoDataService.delete as any).and.returnValue(observableOf({ isSuccessful: false }));
|
(dsoDataService.delete as any).and.returnValue(observableOf({ isSuccessful: false }));
|
||||||
spyOn(router, 'navigate');
|
spyOn(router, 'navigate');
|
||||||
spyOn((comp as any), 'refreshCache');
|
spyOn((comp as any), 'refreshCache');
|
||||||
comp.onConfirm(data2);
|
scheduler.schedule(() => comp.onConfirm(data2));
|
||||||
|
scheduler.flush();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(notificationsService.error).toHaveBeenCalled();
|
expect(notificationsService.error).toHaveBeenCalled();
|
||||||
expect((comp as any).refreshCache).not.toHaveBeenCalled();
|
expect((comp as any).refreshCache).not.toHaveBeenCalled();
|
||||||
@@ -146,7 +165,8 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
it('should show a success notification on success and navigate', () => {
|
it('should show a success notification on success and navigate', () => {
|
||||||
spyOn(router, 'navigate');
|
spyOn(router, 'navigate');
|
||||||
spyOn((comp as any), 'refreshCache');
|
spyOn((comp as any), 'refreshCache');
|
||||||
comp.onConfirm(data1);
|
scheduler.schedule(() => comp.onConfirm(data1));
|
||||||
|
scheduler.flush();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(notificationsService.success).toHaveBeenCalled();
|
expect(notificationsService.success).toHaveBeenCalled();
|
||||||
expect((comp as any).refreshCache).toHaveBeenCalled();
|
expect((comp as any).refreshCache).toHaveBeenCalled();
|
||||||
@@ -160,14 +180,9 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('cache refresh', () => {
|
describe('cache refresh', () => {
|
||||||
let scheduler;
|
|
||||||
let communityWithoutParentHref;
|
let communityWithoutParentHref;
|
||||||
let deletedCommunity;
|
let deletedCommunity;
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
scheduler = getTestScheduler();
|
|
||||||
|
|
||||||
})
|
|
||||||
describe('cache refreshed top level community', () => {
|
describe('cache refreshed top level community', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
(dsoDataService.findByHref as any).and.returnValue(createNoContentRemoteDataObject$());
|
(dsoDataService.findByHref as any).and.returnValue(createNoContentRemoteDataObject$());
|
||||||
|
Reference in New Issue
Block a user