]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
a4b75251 TL |
2 | import { Router } from '@angular/router'; |
3 | import { RouterTestingModule } from '@angular/router/testing'; | |
11fdf7f2 | 4 | |
f67539c2 | 5 | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
11fdf7f2 | 6 | |
f67539c2 | 7 | import { configureTestBed } from '~/testing/unit-test-helper'; |
11fdf7f2 TL |
8 | import { ModalComponent } from './modal.component'; |
9 | ||
10 | describe('ModalComponent', () => { | |
11 | let component: ModalComponent; | |
12 | let fixture: ComponentFixture<ModalComponent>; | |
a4b75251 | 13 | let routerNavigateSpy: jasmine.Spy; |
11fdf7f2 TL |
14 | |
15 | configureTestBed({ | |
a4b75251 TL |
16 | declarations: [ModalComponent], |
17 | imports: [RouterTestingModule] | |
11fdf7f2 TL |
18 | }); |
19 | ||
20 | beforeEach(() => { | |
21 | fixture = TestBed.createComponent(ModalComponent); | |
22 | component = fixture.componentInstance; | |
a4b75251 TL |
23 | routerNavigateSpy = spyOn(TestBed.inject(Router), 'navigate'); |
24 | routerNavigateSpy.and.returnValue(true); | |
11fdf7f2 TL |
25 | fixture.detectChanges(); |
26 | }); | |
27 | ||
28 | it('should create', () => { | |
29 | expect(component).toBeTruthy(); | |
30 | }); | |
31 | ||
32 | it('should call the hide callback function', () => { | |
33 | spyOn(component.hide, 'emit'); | |
34 | const nativeElement = fixture.nativeElement; | |
35 | const button = nativeElement.querySelector('button'); | |
36 | button.dispatchEvent(new Event('click')); | |
37 | fixture.detectChanges(); | |
38 | expect(component.hide.emit).toHaveBeenCalled(); | |
39 | }); | |
40 | ||
41 | it('should hide the modal', () => { | |
f67539c2 TL |
42 | component.modalRef = new NgbActiveModal(); |
43 | spyOn(component.modalRef, 'close'); | |
11fdf7f2 | 44 | component.close(); |
f67539c2 | 45 | expect(component.modalRef.close).toHaveBeenCalled(); |
11fdf7f2 | 46 | }); |
a4b75251 TL |
47 | |
48 | it('should hide the routed modal', () => { | |
49 | component.pageURL = 'hosts'; | |
50 | component.close(); | |
51 | expect(routerNavigateSpy).toHaveBeenCalledTimes(1); | |
52 | expect(routerNavigateSpy).toHaveBeenCalledWith(['hosts', { outlets: { modal: null } }]); | |
53 | }); | |
11fdf7f2 | 54 | }); |