Skip to content

Commit 2eb625f

Browse files
[DURACOM-383] update tests
1 parent f4f568f commit 2eb625f

3 files changed

Lines changed: 116 additions & 17 deletions

File tree

src/app/collection-page/delete-collection-page/delete-collection-page.component.spec.ts

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,61 @@ import {
55
TestBed,
66
waitForAsync,
77
} from '@angular/core/testing';
8-
import { ActivatedRoute } from '@angular/router';
8+
import {
9+
ActivatedRoute,
10+
Router,
11+
} from '@angular/router';
912
import { RouterTestingModule } from '@angular/router/testing';
1013
import { TranslateModule } from '@ngx-translate/core';
1114
import { of } from 'rxjs';
1215

1316
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
1417
import { CollectionDataService } from '../../core/data/collection-data.service';
15-
import { RequestService } from '../../core/data/request.service';
18+
import {
19+
DSPACE_OBJECT_DELETION_SCRIPT_NAME,
20+
ScriptDataService,
21+
} from '../../core/data/processes/script-data.service';
22+
import { Collection } from '../../core/shared/collection.model';
23+
import { getProcessDetailRoute } from '../../process-page/process-page-routing.paths';
24+
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
1625
import { DSONameServiceMock } from '../../shared/mocks/dso-name.service.mock';
1726
import { NotificationsService } from '../../shared/notifications/notifications.service';
27+
import {
28+
createFailedRemoteDataObject$,
29+
createSuccessfulRemoteDataObject$,
30+
} from '../../shared/remote-data.utils';
31+
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
1832
import { DeleteCollectionPageComponent } from './delete-collection-page.component';
1933

2034
describe('DeleteCollectionPageComponent', () => {
2135
let comp: DeleteCollectionPageComponent;
2236
let fixture: ComponentFixture<DeleteCollectionPageComponent>;
37+
let scriptService;
38+
let notificationService: NotificationsServiceStub;
39+
let router;
40+
41+
const mockCollection: Collection = Object.assign(new Collection(), {
42+
uuid: 'test-uuid',
43+
id: 'test-uuid',
44+
name: 'Test Collection',
45+
type: 'collection',
46+
});
2347

2448
beforeEach(waitForAsync(() => {
49+
notificationService = new NotificationsServiceStub();
50+
scriptService = jasmine.createSpyObj('scriptService', {
51+
invoke: createSuccessfulRemoteDataObject$({ processId: '123' }),
52+
});
53+
router = jasmine.createSpyObj('router', ['navigateByUrl']);
2554
TestBed.configureTestingModule({
2655
imports: [TranslateModule.forRoot(), CommonModule, RouterTestingModule, DeleteCollectionPageComponent],
2756
providers: [
2857
{ provide: DSONameService, useValue: new DSONameServiceMock() },
2958
{ provide: CollectionDataService, useValue: {} },
30-
{ provide: ActivatedRoute, useValue: { data: of({ dso: { payload: {} } }) } },
31-
{ provide: NotificationsService, useValue: {} },
32-
{ provide: RequestService, useValue: {} },
59+
{ provide: ActivatedRoute, useValue: { data: of({ dso: { payload: mockCollection } }) } },
60+
{ provide: NotificationsService, useValue: notificationService },
61+
{ provide: ScriptDataService, useValue: scriptService },
62+
{ provide: Router, useValue: router },
3363
],
3464
schemas: [NO_ERRORS_SCHEMA],
3565
}).compileComponents();
@@ -41,9 +71,28 @@ describe('DeleteCollectionPageComponent', () => {
4171
fixture.detectChanges();
4272
});
4373

44-
describe('frontendURL', () => {
45-
it('should have the right frontendURL set', () => {
46-
expect((comp as any).frontendURL).toEqual('/collections/');
74+
it('should create', () => {
75+
expect(comp).toBeTruthy();
76+
});
77+
78+
it('should have the right frontendURL set', () => {
79+
expect((comp as any).frontendURL).toEqual('/collections/');
80+
});
81+
82+
describe('onConfirm', () => {
83+
it('should invoke the deletion script with correct params, show success notification and redirect on success', (done) => {
84+
const parameterValues: ProcessParameter[] = [
85+
Object.assign(new ProcessParameter(), { name: '-i', value: mockCollection.uuid }),
86+
];
87+
(scriptService.invoke as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$({ processId: '123' }));
88+
expect(scriptService.invoke).toHaveBeenCalledWith(DSPACE_OBJECT_DELETION_SCRIPT_NAME, parameterValues, []);
89+
expect(notificationService.success).toHaveBeenCalledWith('collection.delete.notification.success');
90+
expect(router.navigateByUrl).toHaveBeenCalledWith(getProcessDetailRoute('123'));
91+
});
92+
93+
it('error notification is shown', (done) => {
94+
(scriptService.invoke as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$('Error', 500));
95+
expect(notificationService.error).toHaveBeenCalledWith('collection.delete.notification.fail');
4796
});
4897
});
4998
});

src/app/community-page/delete-community-page/delete-community-page.component.spec.ts

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,61 @@ import {
55
TestBed,
66
waitForAsync,
77
} from '@angular/core/testing';
8-
import { ActivatedRoute } from '@angular/router';
8+
import {
9+
ActivatedRoute,
10+
Router,
11+
} from '@angular/router';
912
import { RouterTestingModule } from '@angular/router/testing';
1013
import { TranslateModule } from '@ngx-translate/core';
1114
import { of } from 'rxjs';
1215

1316
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
1417
import { CommunityDataService } from '../../core/data/community-data.service';
15-
import { RequestService } from '../../core/data/request.service';
18+
import {
19+
DSPACE_OBJECT_DELETION_SCRIPT_NAME,
20+
ScriptDataService,
21+
} from '../../core/data/processes/script-data.service';
22+
import { Community } from '../../core/shared/community.model';
23+
import { getProcessDetailRoute } from '../../process-page/process-page-routing.paths';
24+
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
1625
import { DSONameServiceMock } from '../../shared/mocks/dso-name.service.mock';
1726
import { NotificationsService } from '../../shared/notifications/notifications.service';
27+
import {
28+
createFailedRemoteDataObject$,
29+
createSuccessfulRemoteDataObject$,
30+
} from '../../shared/remote-data.utils';
31+
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
1832
import { DeleteCommunityPageComponent } from './delete-community-page.component';
1933

2034
describe('DeleteCommunityPageComponent', () => {
2135
let comp: DeleteCommunityPageComponent;
2236
let fixture: ComponentFixture<DeleteCommunityPageComponent>;
37+
let scriptService;
38+
let notificationService: NotificationsServiceStub;
39+
let router;
40+
41+
const mockCommunity: Community = Object.assign(new Community(), {
42+
uuid: 'test-uuid',
43+
id: 'test-uuid',
44+
name: 'Test Community',
45+
type: 'community',
46+
});
2347

2448
beforeEach(waitForAsync(() => {
49+
notificationService = new NotificationsServiceStub();
50+
scriptService = jasmine.createSpyObj('scriptService', {
51+
invoke: createSuccessfulRemoteDataObject$({ processId: '123' }),
52+
});
53+
router = jasmine.createSpyObj('router', ['navigateByUrl']);
2554
TestBed.configureTestingModule({
2655
imports: [TranslateModule.forRoot(), CommonModule, RouterTestingModule, DeleteCommunityPageComponent],
2756
providers: [
2857
{ provide: DSONameService, useValue: new DSONameServiceMock() },
2958
{ provide: CommunityDataService, useValue: {} },
30-
{ provide: ActivatedRoute, useValue: { data: of({ dso: { payload: {} } }) } },
31-
{ provide: NotificationsService, useValue: {} },
32-
{ provide: RequestService, useValue: {} },
59+
{ provide: ActivatedRoute, useValue: { data: of({ dso: { payload: mockCommunity } }) } },
60+
{ provide: NotificationsService, useValue: notificationService },
61+
{ provide: ScriptDataService, useValue: scriptService },
62+
{ provide: Router, useValue: router },
3363
],
3464
schemas: [NO_ERRORS_SCHEMA],
3565
}).compileComponents();
@@ -41,9 +71,29 @@ describe('DeleteCommunityPageComponent', () => {
4171
fixture.detectChanges();
4272
});
4373

44-
describe('frontendURL', () => {
45-
it('should have the right frontendURL set', () => {
46-
expect((comp as any).frontendURL).toEqual('/communities/');
74+
it('should create', () => {
75+
expect(comp).toBeTruthy();
76+
});
77+
78+
it('should have the right frontendURL set', () => {
79+
expect((comp as any).frontendURL).toEqual('/communities/');
80+
});
81+
82+
describe('onConfirm', () => {
83+
it('should invoke the deletion script with correct params, show success notification and redirect on success', (done) => {
84+
const parameterValues: ProcessParameter[] = [
85+
Object.assign(new ProcessParameter(), { name: '-i', value: mockCommunity.uuid }),
86+
];
87+
(scriptService.invoke as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$({ processId: '123' }));
88+
expect(scriptService.invoke).toHaveBeenCalledWith(DSPACE_OBJECT_DELETION_SCRIPT_NAME, parameterValues, []);
89+
expect(notificationService.success).toHaveBeenCalledWith('community.delete.notification.success');
90+
expect(router.navigateByUrl).toHaveBeenCalledWith(getProcessDetailRoute('123'));
91+
});
92+
93+
it('error notification is shown', (done) => {
94+
(scriptService.invoke as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$('Error', 500));
95+
expect(notificationService.error).toHaveBeenCalledWith('community.delete.notification.fail');
4796
});
4897
});
98+
4999
});

src/app/item-page/edit-item-page/item-delete/item-delete.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class ItemDeleteComponent
178178
protected relationshipService: RelationshipDataService,
179179
protected entityTypeService: EntityTypeDataService,
180180
protected linkService: LinkService,
181-
protected scriptDataService: ScriptDataService, // AGGIUNTO
181+
protected scriptDataService: ScriptDataService,
182182
) {
183183
super(
184184
route,

0 commit comments

Comments
 (0)