]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
3 | import { ReactiveFormsModule } from '@angular/forms'; | |
4 | import { ActivatedRoute } from '@angular/router'; | |
5 | import { RouterTestingModule } from '@angular/router/testing'; | |
6 | ||
11fdf7f2 | 7 | import { TypeaheadModule } from 'ngx-bootstrap/typeahead'; |
494da23a | 8 | import { ToastrModule } from 'ngx-toastr'; |
11fdf7f2 TL |
9 | |
10 | import { ActivatedRouteStub } from '../../../../testing/activated-route-stub'; | |
11 | import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; | |
eafe8130 | 12 | import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe'; |
11fdf7f2 TL |
13 | import { SummaryService } from '../../../shared/services/summary.service'; |
14 | import { SharedModule } from '../../../shared/shared.module'; | |
15 | import { NfsFormClientComponent } from '../nfs-form-client/nfs-form-client.component'; | |
16 | import { NfsFormComponent } from './nfs-form.component'; | |
17 | ||
18 | describe('NfsFormComponent', () => { | |
19 | let component: NfsFormComponent; | |
20 | let fixture: ComponentFixture<NfsFormComponent>; | |
21 | let httpTesting: HttpTestingController; | |
22 | let activatedRoute: ActivatedRouteStub; | |
23 | ||
24 | configureTestBed( | |
25 | { | |
26 | declarations: [NfsFormComponent, NfsFormClientComponent], | |
27 | imports: [ | |
28 | HttpClientTestingModule, | |
29 | ReactiveFormsModule, | |
30 | RouterTestingModule, | |
31 | SharedModule, | |
494da23a | 32 | ToastrModule.forRoot(), |
11fdf7f2 TL |
33 | TypeaheadModule.forRoot() |
34 | ], | |
35 | providers: [ | |
36 | { | |
37 | provide: ActivatedRoute, | |
38 | useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined }) | |
39 | }, | |
eafe8130 TL |
40 | i18nProviders, |
41 | SummaryService, | |
42 | CephReleaseNamePipe | |
11fdf7f2 TL |
43 | ] |
44 | }, | |
45 | true | |
46 | ); | |
47 | ||
48 | beforeEach(() => { | |
49 | const summaryService = TestBed.get(SummaryService); | |
50 | spyOn(summaryService, 'refresh').and.callFake(() => true); | |
eafe8130 TL |
51 | spyOn(summaryService, 'getCurrentSummary').and.callFake(() => { |
52 | return { | |
53 | version: 'master' | |
54 | }; | |
55 | }); | |
11fdf7f2 TL |
56 | |
57 | fixture = TestBed.createComponent(NfsFormComponent); | |
58 | component = fixture.componentInstance; | |
59 | httpTesting = TestBed.get(HttpTestingController); | |
60 | activatedRoute = TestBed.get(ActivatedRoute); | |
61 | fixture.detectChanges(); | |
62 | ||
63 | httpTesting.expectOne('api/summary').flush([]); | |
64 | httpTesting | |
65 | .expectOne('api/nfs-ganesha/daemon') | |
66 | .flush([ | |
67 | { daemon_id: 'node1', cluster_id: 'cluster1' }, | |
68 | { daemon_id: 'node2', cluster_id: 'cluster1' }, | |
69 | { daemon_id: 'node5', cluster_id: 'cluster2' } | |
70 | ]); | |
71 | httpTesting.expectOne('ui-api/nfs-ganesha/fsals').flush(['CEPH', 'RGW']); | |
72 | httpTesting.expectOne('ui-api/nfs-ganesha/cephx/clients').flush(['admin', 'fs', 'rgw']); | |
73 | httpTesting.expectOne('ui-api/nfs-ganesha/cephfs/filesystems').flush([{ id: 1, name: 'a' }]); | |
74 | httpTesting.expectOne('api/rgw/user').flush(['test', 'dev']); | |
75 | httpTesting.expectOne('api/rgw/user/dev').flush({ suspended: 0, user_id: 'dev', keys: ['a'] }); | |
76 | httpTesting | |
77 | .expectOne('api/rgw/user/test') | |
78 | .flush({ suspended: 1, user_id: 'test', keys: ['a'] }); | |
79 | httpTesting.verify(); | |
80 | }); | |
81 | ||
82 | it('should create', () => { | |
83 | expect(component).toBeTruthy(); | |
84 | }); | |
85 | ||
86 | it('should process all data', () => { | |
87 | expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] }); | |
88 | expect(component.isDefaultCluster).toEqual(false); | |
89 | expect(component.allFsals).toEqual([ | |
90 | { descr: 'CephFS', value: 'CEPH' }, | |
91 | { descr: 'Object Gateway', value: 'RGW' } | |
92 | ]); | |
93 | expect(component.allCephxClients).toEqual(['admin', 'fs', 'rgw']); | |
94 | expect(component.allFsNames).toEqual([{ id: 1, name: 'a' }]); | |
95 | expect(component.allRgwUsers).toEqual(['dev']); | |
96 | }); | |
97 | ||
98 | it('should create the form', () => { | |
99 | expect(component.nfsForm.value).toEqual({ | |
100 | access_type: 'RW', | |
101 | clients: [], | |
102 | cluster_id: '', | |
103 | daemons: [], | |
104 | fsal: { fs_name: 'a', name: '', rgw_user_id: '', user_id: '' }, | |
105 | path: '', | |
106 | protocolNfsv3: true, | |
107 | protocolNfsv4: true, | |
108 | pseudo: '', | |
109 | sec_label_xattr: 'security.selinux', | |
110 | security_label: false, | |
111 | squash: '', | |
112 | tag: '', | |
113 | transportTCP: true, | |
114 | transportUDP: true | |
115 | }); | |
116 | }); | |
117 | ||
118 | it('should prepare data when selecting an cluster', () => { | |
119 | expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] }); | |
120 | expect(component.daemonsSelections).toEqual([]); | |
121 | ||
122 | component.nfsForm.patchValue({ cluster_id: 'cluster1' }); | |
123 | component.onClusterChange(); | |
124 | ||
125 | expect(component.daemonsSelections).toEqual([ | |
81eedcae TL |
126 | { description: '', name: 'node1', selected: false, enabled: true }, |
127 | { description: '', name: 'node2', selected: false, enabled: true } | |
11fdf7f2 TL |
128 | ]); |
129 | }); | |
130 | ||
131 | it('should clean data when changing cluster', () => { | |
132 | component.nfsForm.patchValue({ cluster_id: 'cluster1', daemons: ['node1'] }); | |
133 | component.nfsForm.patchValue({ cluster_id: 'node2' }); | |
134 | component.onClusterChange(); | |
135 | ||
136 | expect(component.nfsForm.getValue('daemons')).toEqual([]); | |
137 | }); | |
138 | ||
139 | describe('should submit request', () => { | |
140 | beforeEach(() => { | |
141 | component.nfsForm.patchValue({ | |
142 | access_type: 'RW', | |
143 | clients: [], | |
144 | cluster_id: 'cluster1', | |
145 | daemons: ['node2'], | |
146 | fsal: { name: 'CEPH', user_id: 'fs', fs_name: 1, rgw_user_id: '' }, | |
147 | path: '/foo', | |
148 | protocolNfsv3: true, | |
149 | protocolNfsv4: true, | |
150 | pseudo: '/baz', | |
151 | squash: 'no_root_squash', | |
152 | tag: 'bar', | |
153 | transportTCP: true, | |
154 | transportUDP: true | |
155 | }); | |
156 | }); | |
157 | ||
158 | it('should remove "pseudo" requirement when NFS v4 disabled', () => { | |
159 | component.nfsForm.patchValue({ | |
160 | protocolNfsv4: false, | |
161 | pseudo: '' | |
162 | }); | |
163 | ||
164 | component.nfsForm.updateValueAndValidity({ emitEvent: false }); | |
165 | expect(component.nfsForm.valid).toBeTruthy(); | |
166 | }); | |
167 | ||
168 | it('should call update', () => { | |
169 | activatedRoute.setParams({ cluster_id: 'cluster1', export_id: '1' }); | |
170 | component.isEdit = true; | |
171 | component.cluster_id = 'cluster1'; | |
172 | component.export_id = '1'; | |
173 | component.nfsForm.patchValue({ export_id: 1 }); | |
174 | component.submitAction(); | |
175 | ||
176 | const req = httpTesting.expectOne('api/nfs-ganesha/export/cluster1/1'); | |
177 | expect(req.request.method).toBe('PUT'); | |
178 | expect(req.request.body).toEqual({ | |
179 | access_type: 'RW', | |
180 | clients: [], | |
181 | cluster_id: 'cluster1', | |
182 | daemons: ['node2'], | |
183 | export_id: '1', | |
184 | fsal: { fs_name: 1, name: 'CEPH', sec_label_xattr: null, user_id: 'fs' }, | |
185 | path: '/foo', | |
186 | protocols: [3, 4], | |
187 | pseudo: '/baz', | |
188 | security_label: false, | |
189 | squash: 'no_root_squash', | |
190 | tag: 'bar', | |
191 | transports: ['TCP', 'UDP'] | |
192 | }); | |
193 | }); | |
194 | ||
195 | it('should call create', () => { | |
196 | activatedRoute.setParams({ cluster_id: undefined, export_id: undefined }); | |
197 | component.submitAction(); | |
198 | ||
199 | const req = httpTesting.expectOne('api/nfs-ganesha/export'); | |
200 | expect(req.request.method).toBe('POST'); | |
201 | expect(req.request.body).toEqual({ | |
202 | access_type: 'RW', | |
203 | clients: [], | |
204 | cluster_id: 'cluster1', | |
205 | daemons: ['node2'], | |
206 | fsal: { | |
207 | fs_name: 1, | |
208 | name: 'CEPH', | |
209 | sec_label_xattr: null, | |
210 | user_id: 'fs' | |
211 | }, | |
212 | path: '/foo', | |
213 | protocols: [3, 4], | |
214 | pseudo: '/baz', | |
215 | security_label: false, | |
216 | squash: 'no_root_squash', | |
217 | tag: 'bar', | |
218 | transports: ['TCP', 'UDP'] | |
219 | }); | |
220 | }); | |
221 | }); | |
222 | }); |