]> 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.1 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([]);
801d1391
TL
64 httpTesting.expectOne('api/nfs-ganesha/daemon').flush([
65 { daemon_id: 'node1', cluster_id: 'cluster1' },
66 { daemon_id: 'node2', cluster_id: 'cluster1' },
67 { daemon_id: 'node5', cluster_id: 'cluster2' }
68 ]);
11fdf7f2
TL
69 httpTesting.expectOne('ui-api/nfs-ganesha/fsals').flush(['CEPH', 'RGW']);
70 httpTesting.expectOne('ui-api/nfs-ganesha/cephx/clients').flush(['admin', 'fs', 'rgw']);
71 httpTesting.expectOne('ui-api/nfs-ganesha/cephfs/filesystems').flush([{ id: 1, name: 'a' }]);
72 httpTesting.expectOne('api/rgw/user').flush(['test', 'dev']);
9f95a23c
TL
73 const user_dev = {
74 suspended: 0,
75 user_id: 'dev',
76 keys: ['a']
77 };
78 httpTesting.expectOne('api/rgw/user/dev').flush(user_dev);
79 const user_test = {
80 suspended: 1,
81 user_id: 'test',
82 keys: ['a']
83 };
84 httpTesting.expectOne('api/rgw/user/test').flush(user_test);
11fdf7f2
TL
85 httpTesting.verify();
86 });
87
88 it('should create', () => {
89 expect(component).toBeTruthy();
90 });
91
92 it('should process all data', () => {
93 expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] });
94 expect(component.isDefaultCluster).toEqual(false);
95 expect(component.allFsals).toEqual([
96 { descr: 'CephFS', value: 'CEPH' },
97 { descr: 'Object Gateway', value: 'RGW' }
98 ]);
99 expect(component.allCephxClients).toEqual(['admin', 'fs', 'rgw']);
100 expect(component.allFsNames).toEqual([{ id: 1, name: 'a' }]);
101 expect(component.allRgwUsers).toEqual(['dev']);
102 });
103
104 it('should create the form', () => {
105 expect(component.nfsForm.value).toEqual({
106 access_type: 'RW',
107 clients: [],
108 cluster_id: '',
109 daemons: [],
110 fsal: { fs_name: 'a', name: '', rgw_user_id: '', user_id: '' },
111 path: '',
112 protocolNfsv3: true,
113 protocolNfsv4: true,
114 pseudo: '',
115 sec_label_xattr: 'security.selinux',
116 security_label: false,
117 squash: '',
118 tag: '',
119 transportTCP: true,
120 transportUDP: true
121 });
122 });
123
124 it('should prepare data when selecting an cluster', () => {
125 expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] });
126 expect(component.daemonsSelections).toEqual([]);
127
128 component.nfsForm.patchValue({ cluster_id: 'cluster1' });
129 component.onClusterChange();
130
131 expect(component.daemonsSelections).toEqual([
81eedcae
TL
132 { description: '', name: 'node1', selected: false, enabled: true },
133 { description: '', name: 'node2', selected: false, enabled: true }
11fdf7f2
TL
134 ]);
135 });
136
137 it('should clean data when changing cluster', () => {
138 component.nfsForm.patchValue({ cluster_id: 'cluster1', daemons: ['node1'] });
139 component.nfsForm.patchValue({ cluster_id: 'node2' });
140 component.onClusterChange();
141
142 expect(component.nfsForm.getValue('daemons')).toEqual([]);
143 });
144
145 describe('should submit request', () => {
146 beforeEach(() => {
147 component.nfsForm.patchValue({
148 access_type: 'RW',
149 clients: [],
150 cluster_id: 'cluster1',
151 daemons: ['node2'],
152 fsal: { name: 'CEPH', user_id: 'fs', fs_name: 1, rgw_user_id: '' },
153 path: '/foo',
154 protocolNfsv3: true,
155 protocolNfsv4: true,
156 pseudo: '/baz',
157 squash: 'no_root_squash',
158 tag: 'bar',
159 transportTCP: true,
160 transportUDP: true
161 });
162 });
163
164 it('should remove "pseudo" requirement when NFS v4 disabled', () => {
165 component.nfsForm.patchValue({
166 protocolNfsv4: false,
167 pseudo: ''
168 });
169
170 component.nfsForm.updateValueAndValidity({ emitEvent: false });
171 expect(component.nfsForm.valid).toBeTruthy();
172 });
173
174 it('should call update', () => {
175 activatedRoute.setParams({ cluster_id: 'cluster1', export_id: '1' });
176 component.isEdit = true;
177 component.cluster_id = 'cluster1';
178 component.export_id = '1';
179 component.nfsForm.patchValue({ export_id: 1 });
180 component.submitAction();
181
182 const req = httpTesting.expectOne('api/nfs-ganesha/export/cluster1/1');
183 expect(req.request.method).toBe('PUT');
184 expect(req.request.body).toEqual({
185 access_type: 'RW',
186 clients: [],
187 cluster_id: 'cluster1',
188 daemons: ['node2'],
189 export_id: '1',
190 fsal: { fs_name: 1, name: 'CEPH', sec_label_xattr: null, user_id: 'fs' },
191 path: '/foo',
192 protocols: [3, 4],
193 pseudo: '/baz',
194 security_label: false,
195 squash: 'no_root_squash',
196 tag: 'bar',
197 transports: ['TCP', 'UDP']
198 });
199 });
200
201 it('should call create', () => {
202 activatedRoute.setParams({ cluster_id: undefined, export_id: undefined });
203 component.submitAction();
204
205 const req = httpTesting.expectOne('api/nfs-ganesha/export');
206 expect(req.request.method).toBe('POST');
207 expect(req.request.body).toEqual({
208 access_type: 'RW',
209 clients: [],
210 cluster_id: 'cluster1',
211 daemons: ['node2'],
212 fsal: {
213 fs_name: 1,
214 name: 'CEPH',
215 sec_label_xattr: null,
216 user_id: 'fs'
217 },
218 path: '/foo',
219 protocols: [3, 4],
220 pseudo: '/baz',
221 security_label: false,
222 squash: 'no_root_squash',
223 tag: 'bar',
224 transports: ['TCP', 'UDP']
225 });
226 });
227 });
228});