Commits
Tim Donohue authored and GitHub committed 6d582cd39ea Merge
1 1 | import { NO_ERRORS_SCHEMA } from '@angular/core'; |
2 2 | import { |
3 3 | ComponentFixture, |
4 4 | TestBed, |
5 5 | waitForAsync, |
6 6 | } from '@angular/core/testing'; |
7 7 | import { ActivatedRoute } from '@angular/router'; |
8 8 | import { TranslateModule } from '@ngx-translate/core'; |
9 9 | import { of as observableOf } from 'rxjs'; |
10 + | import { ServerResponseService } from 'src/app/core/services/server-response.service'; |
10 11 | |
11 12 | import { ActivatedRouteStub } from '../../shared/testing/active-router.stub'; |
12 13 | import { ObjectNotFoundComponent } from './objectnotfound.component'; |
13 14 | |
14 15 | describe('ObjectNotFoundComponent', () => { |
15 16 | let comp: ObjectNotFoundComponent; |
16 17 | let fixture: ComponentFixture<ObjectNotFoundComponent>; |
17 18 | const testUUID = '34cfed7c-f597-49ef-9cbe-ea351f0023c2'; |
18 19 | const uuidType = 'uuid'; |
19 20 | const handlePrefix = '123456789'; |
20 21 | const handleId = '22'; |
21 22 | const activatedRouteStub = Object.assign(new ActivatedRouteStub(), { |
22 23 | params: observableOf({ id: testUUID, idType: uuidType }), |
23 24 | }); |
25 + | const serverResponseServiceStub = jasmine.createSpyObj('ServerResponseService', { |
26 + | setNotFound: jasmine.createSpy('setNotFound'), |
27 + | }); |
28 + | |
24 29 | const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), { |
25 30 | params: observableOf({ id: handleId, idType: handlePrefix }), |
26 31 | }); |
27 32 | describe('uuid request', () => { |
28 33 | beforeEach(waitForAsync(() => { |
29 34 | TestBed.configureTestingModule({ |
30 35 | imports: [ |
31 36 | TranslateModule.forRoot(), |
32 37 | ObjectNotFoundComponent, |
33 38 | ], providers: [ |
39 + | { provide: ServerResponseService, useValue: serverResponseServiceStub } , |
34 40 | { provide: ActivatedRoute, useValue: activatedRouteStub }, |
35 41 | ], |
36 42 | schemas: [NO_ERRORS_SCHEMA], |
37 43 | }).compileComponents(); |
38 44 | })); |
39 45 | |
40 46 | beforeEach(() => { |
41 47 | fixture = TestBed.createComponent(ObjectNotFoundComponent); |
42 48 | comp = fixture.componentInstance; |
43 49 | fixture.detectChanges(); |
44 50 | }); |
45 51 | |
46 52 | it('should create instance', () => { |
47 53 | expect(comp).toBeDefined(); |
48 54 | }); |
49 55 | |
50 56 | it('should have id and idType', () => { |
51 57 | expect(comp.id).toEqual(testUUID); |
52 58 | expect(comp.idType).toEqual(uuidType); |
53 59 | expect(comp.missingItem).toEqual('uuid: ' + testUUID); |
54 60 | }); |
61 + | |
62 + | it('should call serverResponseService.setNotFound', () => { |
63 + | expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled(); |
64 + | }); |
55 65 | }); |
56 66 | |
57 67 | describe( 'legacy handle request', () => { |
58 68 | beforeEach(waitForAsync(() => { |
59 69 | TestBed.configureTestingModule({ |
60 70 | imports: [ |
61 71 | TranslateModule.forRoot(), |
62 72 | ObjectNotFoundComponent, |
63 73 | ], providers: [ |
74 + | { provide: ServerResponseService, useValue: serverResponseServiceStub }, |
64 75 | { provide: ActivatedRoute, useValue: activatedRouteStubHandle }, |
65 76 | ], |
66 77 | schemas: [NO_ERRORS_SCHEMA], |
67 78 | }).compileComponents(); |
68 79 | })); |
69 80 | |
70 81 | beforeEach(() => { |
71 82 | fixture = TestBed.createComponent(ObjectNotFoundComponent); |
72 83 | comp = fixture.componentInstance; |
73 84 | fixture.detectChanges(); |
74 85 | }); |
75 86 | |
76 87 | it('should have handle prefix and id', () => { |
77 88 | expect(comp.id).toEqual(handleId); |
78 89 | expect(comp.idType).toEqual(handlePrefix); |
79 90 | expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId); |
80 91 | }); |
92 + | |
93 + | it('should call serverResponseService.setNotFound', () => { |
94 + | expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled(); |
95 + | }); |
81 96 | }); |
82 97 | |
83 98 | }); |