]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
3 | import { ReactiveFormsModule } from '@angular/forms'; | |
4 | import { RouterTestingModule } from '@angular/router/testing'; | |
5 | ||
f67539c2 | 6 | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
9f95a23c TL |
7 | import { ToastrModule } from 'ngx-toastr'; |
8 | import { of } from 'rxjs'; | |
9 | ||
f67539c2 TL |
10 | import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service'; |
11 | import { NotificationService } from '~/app/shared/services/notification.service'; | |
12 | import { SharedModule } from '~/app/shared/shared.module'; | |
13 | import { configureTestBed } from '~/testing/unit-test-helper'; | |
9f95a23c TL |
14 | import { EditSiteNameModalComponent } from './edit-site-name-modal.component'; |
15 | ||
16 | describe('EditSiteNameModalComponent', () => { | |
17 | let component: EditSiteNameModalComponent; | |
18 | let fixture: ComponentFixture<EditSiteNameModalComponent>; | |
19 | let notificationService: NotificationService; | |
20 | let rbdMirroringService: RbdMirroringService; | |
21 | ||
22 | configureTestBed({ | |
23 | declarations: [EditSiteNameModalComponent], | |
24 | imports: [ | |
25 | HttpClientTestingModule, | |
26 | ReactiveFormsModule, | |
27 | RouterTestingModule, | |
28 | SharedModule, | |
29 | ToastrModule.forRoot() | |
30 | ], | |
f67539c2 | 31 | providers: [NgbActiveModal] |
9f95a23c TL |
32 | }); |
33 | ||
34 | beforeEach(() => { | |
35 | fixture = TestBed.createComponent(EditSiteNameModalComponent); | |
36 | component = fixture.componentInstance; | |
37 | component.siteName = 'site-A'; | |
38 | ||
f67539c2 | 39 | notificationService = TestBed.inject(NotificationService); |
9f95a23c TL |
40 | spyOn(notificationService, 'show').and.stub(); |
41 | ||
f67539c2 | 42 | rbdMirroringService = TestBed.inject(RbdMirroringService); |
9f95a23c TL |
43 | }); |
44 | ||
45 | it('should create', () => { | |
46 | expect(component).toBeTruthy(); | |
47 | }); | |
48 | ||
49 | describe('edit site name', () => { | |
50 | beforeEach(() => { | |
51 | spyOn(rbdMirroringService, 'getSiteName').and.callFake(() => of({ site_name: 'site-A' })); | |
52 | spyOn(rbdMirroringService, 'refresh').and.stub(); | |
f67539c2 | 53 | spyOn(component.activeModal, 'close').and.callThrough(); |
9f95a23c TL |
54 | fixture.detectChanges(); |
55 | }); | |
56 | ||
57 | afterEach(() => { | |
58 | expect(rbdMirroringService.getSiteName).toHaveBeenCalledTimes(1); | |
59 | expect(rbdMirroringService.refresh).toHaveBeenCalledTimes(1); | |
f67539c2 | 60 | expect(component.activeModal.close).toHaveBeenCalledTimes(1); |
9f95a23c TL |
61 | }); |
62 | ||
63 | it('should call setSiteName', () => { | |
64 | spyOn(rbdMirroringService, 'setSiteName').and.callFake(() => of({ site_name: 'new-site-A' })); | |
65 | ||
66 | component.editSiteNameForm.patchValue({ | |
67 | siteName: 'new-site-A' | |
68 | }); | |
69 | component.update(); | |
70 | expect(rbdMirroringService.setSiteName).toHaveBeenCalledWith('new-site-A'); | |
71 | }); | |
72 | }); | |
73 | }); |