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