]>
Commit | Line | Data |
---|---|---|
f67539c2 | 1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
b3b6e05e | 2 | import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; |
9f95a23c | 3 | import { ReactiveFormsModule } from '@angular/forms'; |
f67539c2 | 4 | import { RouterTestingModule } from '@angular/router/testing'; |
9f95a23c TL |
5 | |
6 | import { ToastrModule } from 'ngx-toastr'; | |
7 | ||
f67539c2 TL |
8 | import { LoadingPanelComponent } from '~/app/shared/components/loading-panel/loading-panel.component'; |
9 | import { SharedModule } from '~/app/shared/shared.module'; | |
b3b6e05e | 10 | import { configureTestBed, FormHelper } from '~/testing/unit-test-helper'; |
9f95a23c TL |
11 | import { HostFormComponent } from './host-form.component'; |
12 | ||
13 | describe('HostFormComponent', () => { | |
14 | let component: HostFormComponent; | |
15 | let fixture: ComponentFixture<HostFormComponent>; | |
b3b6e05e | 16 | let formHelper: FormHelper; |
9f95a23c | 17 | |
f67539c2 TL |
18 | configureTestBed( |
19 | { | |
20 | imports: [ | |
21 | SharedModule, | |
22 | HttpClientTestingModule, | |
23 | RouterTestingModule, | |
24 | ReactiveFormsModule, | |
25 | ToastrModule.forRoot() | |
26 | ], | |
27 | declarations: [HostFormComponent] | |
28 | }, | |
29 | [LoadingPanelComponent] | |
30 | ); | |
9f95a23c TL |
31 | |
32 | beforeEach(() => { | |
33 | fixture = TestBed.createComponent(HostFormComponent); | |
34 | component = fixture.componentInstance; | |
b3b6e05e | 35 | formHelper = new FormHelper(component.hostForm); |
9f95a23c TL |
36 | fixture.detectChanges(); |
37 | }); | |
38 | ||
39 | it('should create', () => { | |
40 | expect(component).toBeTruthy(); | |
41 | }); | |
b3b6e05e TL |
42 | |
43 | it('should validate the network address is valid', fakeAsync(() => { | |
44 | formHelper.setValue('addr', '115.42.150.37', true); | |
45 | tick(); | |
46 | formHelper.expectValid('addr'); | |
47 | })); | |
48 | ||
49 | it('should show error if network address is invalid', fakeAsync(() => { | |
50 | formHelper.setValue('addr', '666.10.10.20', true); | |
51 | tick(); | |
52 | formHelper.expectError('addr', 'pattern'); | |
53 | })); | |
54 | ||
55 | it('should submit the network address', () => { | |
56 | component.hostForm.get('addr').setValue('127.0.0.1'); | |
57 | fixture.detectChanges(); | |
58 | component.submit(); | |
59 | expect(component.addr).toBe('127.0.0.1'); | |
60 | }); | |
61 | ||
62 | it('should validate the labels are added', () => { | |
63 | const labels = ['label1', 'label2']; | |
64 | component.hostForm.get('labels').patchValue(labels); | |
65 | fixture.detectChanges(); | |
66 | component.submit(); | |
67 | expect(component.allLabels).toBe(labels); | |
68 | }); | |
69 | ||
70 | it('should select maintenance mode', () => { | |
71 | component.hostForm.get('maintenance').setValue(true); | |
72 | fixture.detectChanges(); | |
73 | component.submit(); | |
74 | expect(component.status).toBe('maintenance'); | |
75 | }); | |
9f95a23c | 76 | }); |