]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / nfs / nfs-form / nfs-form.component.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { ReactiveFormsModule } from '@angular/forms';
4import { ActivatedRoute } from '@angular/router';
5import { RouterTestingModule } from '@angular/router/testing';
6
11fdf7f2 7import { TypeaheadModule } from 'ngx-bootstrap/typeahead';
494da23a 8import { ToastrModule } from 'ngx-toastr';
11fdf7f2
TL
9
10import { ActivatedRouteStub } from '../../../../testing/activated-route-stub';
11import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
eafe8130 12import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe';
11fdf7f2
TL
13import { SummaryService } from '../../../shared/services/summary.service';
14import { SharedModule } from '../../../shared/shared.module';
15import { NfsFormClientComponent } from '../nfs-form-client/nfs-form-client.component';
16import { NfsFormComponent } from './nfs-form.component';
17
18describe('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']);
9f95a23c
TL
75 const user_dev = {
76 suspended: 0,
77 user_id: 'dev',
78 keys: ['a']
79 };
80 httpTesting.expectOne('api/rgw/user/dev').flush(user_dev);
81 const user_test = {
82 suspended: 1,
83 user_id: 'test',
84 keys: ['a']
85 };
86 httpTesting.expectOne('api/rgw/user/test').flush(user_test);
11fdf7f2
TL
87 httpTesting.verify();
88 });
89
90 it('should create', () => {
91 expect(component).toBeTruthy();
92 });
93
94 it('should process all data', () => {
95 expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] });
96 expect(component.isDefaultCluster).toEqual(false);
97 expect(component.allFsals).toEqual([
98 { descr: 'CephFS', value: 'CEPH' },
99 { descr: 'Object Gateway', value: 'RGW' }
100 ]);
101 expect(component.allCephxClients).toEqual(['admin', 'fs', 'rgw']);
102 expect(component.allFsNames).toEqual([{ id: 1, name: 'a' }]);
103 expect(component.allRgwUsers).toEqual(['dev']);
104 });
105
106 it('should create the form', () => {
107 expect(component.nfsForm.value).toEqual({
108 access_type: 'RW',
109 clients: [],
110 cluster_id: '',
111 daemons: [],
112 fsal: { fs_name: 'a', name: '', rgw_user_id: '', user_id: '' },
113 path: '',
114 protocolNfsv3: true,
115 protocolNfsv4: true,
116 pseudo: '',
117 sec_label_xattr: 'security.selinux',
118 security_label: false,
119 squash: '',
120 tag: '',
121 transportTCP: true,
122 transportUDP: true
123 });
124 });
125
126 it('should prepare data when selecting an cluster', () => {
127 expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] });
128 expect(component.daemonsSelections).toEqual([]);
129
130 component.nfsForm.patchValue({ cluster_id: 'cluster1' });
131 component.onClusterChange();
132
133 expect(component.daemonsSelections).toEqual([
81eedcae
TL
134 { description: '', name: 'node1', selected: false, enabled: true },
135 { description: '', name: 'node2', selected: false, enabled: true }
11fdf7f2
TL
136 ]);
137 });
138
139 it('should clean data when changing cluster', () => {
140 component.nfsForm.patchValue({ cluster_id: 'cluster1', daemons: ['node1'] });
141 component.nfsForm.patchValue({ cluster_id: 'node2' });
142 component.onClusterChange();
143
144 expect(component.nfsForm.getValue('daemons')).toEqual([]);
145 });
146
147 describe('should submit request', () => {
148 beforeEach(() => {
149 component.nfsForm.patchValue({
150 access_type: 'RW',
151 clients: [],
152 cluster_id: 'cluster1',
153 daemons: ['node2'],
154 fsal: { name: 'CEPH', user_id: 'fs', fs_name: 1, rgw_user_id: '' },
155 path: '/foo',
156 protocolNfsv3: true,
157 protocolNfsv4: true,
158 pseudo: '/baz',
159 squash: 'no_root_squash',
160 tag: 'bar',
161 transportTCP: true,
162 transportUDP: true
163 });
164 });
165
166 it('should remove "pseudo" requirement when NFS v4 disabled', () => {
167 component.nfsForm.patchValue({
168 protocolNfsv4: false,
169 pseudo: ''
170 });
171
172 component.nfsForm.updateValueAndValidity({ emitEvent: false });
173 expect(component.nfsForm.valid).toBeTruthy();
174 });
175
176 it('should call update', () => {
177 activatedRoute.setParams({ cluster_id: 'cluster1', export_id: '1' });
178 component.isEdit = true;
179 component.cluster_id = 'cluster1';
180 component.export_id = '1';
181 component.nfsForm.patchValue({ export_id: 1 });
182 component.submitAction();
183
184 const req = httpTesting.expectOne('api/nfs-ganesha/export/cluster1/1');
185 expect(req.request.method).toBe('PUT');
186 expect(req.request.body).toEqual({
187 access_type: 'RW',
188 clients: [],
189 cluster_id: 'cluster1',
190 daemons: ['node2'],
191 export_id: '1',
192 fsal: { fs_name: 1, name: 'CEPH', sec_label_xattr: null, user_id: 'fs' },
193 path: '/foo',
194 protocols: [3, 4],
195 pseudo: '/baz',
196 security_label: false,
197 squash: 'no_root_squash',
198 tag: 'bar',
199 transports: ['TCP', 'UDP']
200 });
201 });
202
203 it('should call create', () => {
204 activatedRoute.setParams({ cluster_id: undefined, export_id: undefined });
205 component.submitAction();
206
207 const req = httpTesting.expectOne('api/nfs-ganesha/export');
208 expect(req.request.method).toBe('POST');
209 expect(req.request.body).toEqual({
210 access_type: 'RW',
211 clients: [],
212 cluster_id: 'cluster1',
213 daemons: ['node2'],
214 fsal: {
215 fs_name: 1,
216 name: 'CEPH',
217 sec_label_xattr: null,
218 user_id: 'fs'
219 },
220 path: '/foo',
221 protocols: [3, 4],
222 pseudo: '/baz',
223 security_label: false,
224 squash: 'no_root_squash',
225 tag: 'bar',
226 transports: ['TCP', 'UDP']
227 });
228 });
229 });
230});