]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
3 | import { ReactiveFormsModule } from '@angular/forms'; | |
2a845540 | 4 | import { ActivatedRoute } from '@angular/router'; |
11fdf7f2 TL |
5 | import { RouterTestingModule } from '@angular/router/testing'; |
6 | ||
f67539c2 | 7 | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
494da23a | 8 | import { ToastrModule } from 'ngx-toastr'; |
11fdf7f2 TL |
9 | import { of } from 'rxjs'; |
10 | ||
f67539c2 TL |
11 | import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service'; |
12 | import { NotificationService } from '~/app/shared/services/notification.service'; | |
13 | import { SharedModule } from '~/app/shared/shared.module'; | |
2a845540 | 14 | import { ActivatedRouteStub } from '~/testing/activated-route-stub'; |
f67539c2 | 15 | import { configureTestBed, FormHelper } from '~/testing/unit-test-helper'; |
11fdf7f2 TL |
16 | import { PoolEditModeModalComponent } from './pool-edit-mode-modal.component'; |
17 | ||
18 | describe('PoolEditModeModalComponent', () => { | |
19 | let component: PoolEditModeModalComponent; | |
20 | let fixture: ComponentFixture<PoolEditModeModalComponent>; | |
21 | let notificationService: NotificationService; | |
22 | let rbdMirroringService: RbdMirroringService; | |
23 | let formHelper: FormHelper; | |
2a845540 | 24 | let activatedRoute: ActivatedRouteStub; |
11fdf7f2 TL |
25 | |
26 | configureTestBed({ | |
27 | declarations: [PoolEditModeModalComponent], | |
28 | imports: [ | |
29 | HttpClientTestingModule, | |
30 | ReactiveFormsModule, | |
31 | RouterTestingModule, | |
32 | SharedModule, | |
494da23a | 33 | ToastrModule.forRoot() |
11fdf7f2 | 34 | ], |
2a845540 TL |
35 | providers: [ |
36 | NgbActiveModal, | |
37 | { | |
38 | provide: ActivatedRoute, | |
39 | useValue: new ActivatedRouteStub({ pool_name: 'somePool' }) | |
40 | } | |
41 | ] | |
11fdf7f2 TL |
42 | }); |
43 | ||
44 | beforeEach(() => { | |
45 | fixture = TestBed.createComponent(PoolEditModeModalComponent); | |
46 | component = fixture.componentInstance; | |
47 | component.poolName = 'somePool'; | |
48 | ||
f67539c2 | 49 | notificationService = TestBed.inject(NotificationService); |
11fdf7f2 TL |
50 | spyOn(notificationService, 'show').and.stub(); |
51 | ||
f67539c2 | 52 | rbdMirroringService = TestBed.inject(RbdMirroringService); |
2a845540 | 53 | activatedRoute = <ActivatedRouteStub>TestBed.inject(ActivatedRoute); |
11fdf7f2 TL |
54 | |
55 | formHelper = new FormHelper(component.editModeForm); | |
56 | fixture.detectChanges(); | |
57 | }); | |
58 | ||
59 | it('should create', () => { | |
60 | expect(component).toBeTruthy(); | |
61 | }); | |
62 | ||
63 | describe('update pool mode', () => { | |
64 | beforeEach(() => { | |
f67539c2 | 65 | spyOn(component.activeModal, 'close').and.callThrough(); |
11fdf7f2 TL |
66 | }); |
67 | ||
11fdf7f2 | 68 | it('should call updatePool', () => { |
2a845540 | 69 | activatedRoute.setParams({ pool_name: 'somePool' }); |
11fdf7f2 TL |
70 | spyOn(rbdMirroringService, 'updatePool').and.callFake(() => of('')); |
71 | ||
72 | component.editModeForm.patchValue({ mirrorMode: 'disabled' }); | |
73 | component.update(); | |
74 | expect(rbdMirroringService.updatePool).toHaveBeenCalledWith('somePool', { | |
75 | mirror_mode: 'disabled' | |
76 | }); | |
77 | }); | |
78 | }); | |
79 | ||
80 | describe('form validation', () => { | |
81 | it('should prevent disabling mirroring if peers exist', () => { | |
82 | component.peerExists = true; | |
83 | formHelper.expectErrorChange('mirrorMode', 'disabled', 'cannotDisable'); | |
84 | }); | |
85 | }); | |
86 | }); |