Commits
Tim Donohue authored and GitHub committed e04dd9e183c Merge
1 1 | import { RouteService } from '../../core/services/route.service'; |
2 2 | import { NotificationsService } from '../../shared/notifications/notifications.service'; |
3 3 | import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-data.service'; |
4 4 | import { RouterMock } from '../../shared/mocks/router.mock'; |
5 5 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
6 6 | |
7 7 | import { WorkspaceItemsDeletePageComponent } from './workspaceitems-delete-page.component'; |
8 8 | import { ActivatedRoute, Router } from '@angular/router'; |
9 - | import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; |
9 + | import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap'; |
10 10 | import { TranslateModule, TranslateService } from '@ngx-translate/core'; |
11 11 | import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub'; |
12 12 | import { EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core'; |
13 13 | import { Location } from '@angular/common'; |
14 14 | import { of as observableOf } from 'rxjs'; |
15 15 | import { routeServiceStub } from '../../shared/testing/route-service.stub'; |
16 16 | import { LocationStub } from '../../shared/testing/location.stub'; |
17 + | import { By } from '@angular/platform-browser'; |
17 18 | import { ActivatedRouteStub } from '../../shared/testing/active-router.stub'; |
18 19 | import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils'; |
19 20 | import { WorkspaceItem } from '../../core/submission/models/workspaceitem.model'; |
20 21 | import { DSpaceObject } from '../../core/shared/dspace-object.model'; |
21 22 | |
22 23 | describe('WorkspaceitemsDeletePageComponent', () => { |
23 24 | let component: WorkspaceItemsDeletePageComponent; |
24 25 | let fixture: ComponentFixture<WorkspaceItemsDeletePageComponent>; |
25 26 | |
26 27 | const workspaceitemDataServiceSpy = jasmine.createSpyObj('WorkspaceitemDataService', { |
32 33 | const dso = new DSpaceObject(); |
33 34 | dso.uuid = '1234'; |
34 35 | |
35 36 | const translateServiceStub = { |
36 37 | get: () => observableOf('test-message'), |
37 38 | onLangChange: new EventEmitter(), |
38 39 | onTranslationChange: new EventEmitter(), |
39 40 | onDefaultLangChange: new EventEmitter() |
40 41 | }; |
41 42 | |
42 - | const modalService = { |
43 - | open: () => {/** empty */}, |
44 - | }; |
45 - | |
46 43 | beforeEach(async () => { |
47 44 | await TestBed.configureTestingModule({ |
48 - | imports: [TranslateModule.forRoot()], |
45 + | imports: [ |
46 + | NgbModalModule, |
47 + | TranslateModule.forRoot() |
48 + | ], |
49 49 | declarations: [WorkspaceItemsDeletePageComponent], |
50 50 | providers: [ |
51 51 | { |
52 52 | provide: ActivatedRoute, |
53 53 | useValue: new ActivatedRouteStub( |
54 54 | {}, |
55 55 | { |
56 56 | wsi: createSuccessfulRemoteDataObject(wsi), |
57 57 | dso: createSuccessfulRemoteDataObject(dso), |
58 58 | } |
59 59 | ), |
60 60 | }, |
61 61 | { provide: Router, useValue: new RouterMock() }, |
62 62 | { |
63 63 | provide: WorkspaceitemDataService, |
64 64 | useValue: workspaceitemDataServiceSpy, |
65 65 | }, |
66 66 | { provide: Location, useValue: new LocationStub() }, |
67 - | { provide: NgbModal, useValue: modalService }, |
68 67 | { |
69 68 | provide: NotificationsService, |
70 69 | useValue: new NotificationsServiceStub(), |
71 70 | }, |
72 71 | { provide: TranslateService, useValue: translateServiceStub }, |
73 72 | { provide: RouteService, useValue: routeServiceStub }, |
74 73 | ], |
75 74 | schemas: [NO_ERRORS_SCHEMA], |
76 75 | }).compileComponents(); |
77 76 | }); |
85 84 | it('should create', () => { |
86 85 | expect(component).toBeTruthy(); |
87 86 | }); |
88 87 | |
89 88 | it('should have the current WorkspaceItem', () => { |
90 89 | (component as any).activatedRoute.data.subscribe((data) => { |
91 90 | expect(data.wsi.payload.id).toEqual('1234'); |
92 91 | }); |
93 92 | }); |
94 93 | |
95 - | /*it('should delete the target workspace item', () => { |
96 - | spyOn((component as any).modalService, 'open').and.returnValue({}); |
94 + | it('should delete the target workspace item', () => { |
95 + | spyOn((component as any).modalService, 'open').and.returnValue({result: Promise.resolve('ok')}); |
97 96 | component.confirmDelete(By.css('#delete-modal')); |
98 97 | fixture.detectChanges(); |
99 98 | expect((component as any).modalService.open).toHaveBeenCalled(); |
100 - | });*/ |
99 + | }); |
101 100 | |
102 101 | it('should call workspaceItemService.delete', () => { |
103 102 | component.sendDeleteRequest(); |
104 103 | expect((component as any).workspaceItemService.delete).toHaveBeenCalledWith('1234'); |
105 104 | }); |
106 105 | }); |