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';
7 import { TypeaheadModule } from 'ngx-bootstrap/typeahead';
8 import { ToastrModule } from 'ngx-toastr';
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';
18 describe('NfsFormComponent', () => {
19 let component: NfsFormComponent;
20 let fixture: ComponentFixture<NfsFormComponent>;
21 let httpTesting: HttpTestingController;
22 let activatedRoute: ActivatedRouteStub;
26 declarations: [NfsFormComponent, NfsFormClientComponent],
28 HttpClientTestingModule,
32 ToastrModule.forRoot(),
33 TypeaheadModule.forRoot()
37 provide: ActivatedRoute,
38 useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined })
49 const summaryService = TestBed.get(SummaryService);
50 spyOn(summaryService, 'refresh').and.callFake(() => true);
51 spyOn(summaryService, 'getCurrentSummary').and.callFake(() => {
57 fixture = TestBed.createComponent(NfsFormComponent);
58 component = fixture.componentInstance;
59 httpTesting = TestBed.get(HttpTestingController);
60 activatedRoute = TestBed.get(ActivatedRoute);
61 fixture.detectChanges();
63 httpTesting.expectOne('api/summary').flush([]);
65 .expectOne('api/nfs-ganesha/daemon')
67 { daemon_id: 'node1', cluster_id: 'cluster1' },
68 { daemon_id: 'node2', cluster_id: 'cluster1' },
69 { daemon_id: 'node5', cluster_id: 'cluster2' }
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']);
80 httpTesting.expectOne('api/rgw/user/dev').flush(user_dev);
86 httpTesting.expectOne('api/rgw/user/test').flush(user_test);
90 it('should create', () => {
91 expect(component).toBeTruthy();
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' }
101 expect(component.allCephxClients).toEqual(['admin', 'fs', 'rgw']);
102 expect(component.allFsNames).toEqual([{ id: 1, name: 'a' }]);
103 expect(component.allRgwUsers).toEqual(['dev']);
106 it('should create the form', () => {
107 expect(component.nfsForm.value).toEqual({
112 fsal: { fs_name: 'a', name: '', rgw_user_id: '', user_id: '' },
117 sec_label_xattr: 'security.selinux',
118 security_label: false,
126 it('should prepare data when selecting an cluster', () => {
127 expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] });
128 expect(component.daemonsSelections).toEqual([]);
130 component.nfsForm.patchValue({ cluster_id: 'cluster1' });
131 component.onClusterChange();
133 expect(component.daemonsSelections).toEqual([
134 { description: '', name: 'node1', selected: false, enabled: true },
135 { description: '', name: 'node2', selected: false, enabled: true }
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();
144 expect(component.nfsForm.getValue('daemons')).toEqual([]);
147 describe('should submit request', () => {
149 component.nfsForm.patchValue({
152 cluster_id: 'cluster1',
154 fsal: { name: 'CEPH', user_id: 'fs', fs_name: 1, rgw_user_id: '' },
159 squash: 'no_root_squash',
166 it('should remove "pseudo" requirement when NFS v4 disabled', () => {
167 component.nfsForm.patchValue({
168 protocolNfsv4: false,
172 component.nfsForm.updateValueAndValidity({ emitEvent: false });
173 expect(component.nfsForm.valid).toBeTruthy();
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();
184 const req = httpTesting.expectOne('api/nfs-ganesha/export/cluster1/1');
185 expect(req.request.method).toBe('PUT');
186 expect(req.request.body).toEqual({
189 cluster_id: 'cluster1',
192 fsal: { fs_name: 1, name: 'CEPH', sec_label_xattr: null, user_id: 'fs' },
196 security_label: false,
197 squash: 'no_root_squash',
199 transports: ['TCP', 'UDP']
203 it('should call create', () => {
204 activatedRoute.setParams({ cluster_id: undefined, export_id: undefined });
205 component.submitAction();
207 const req = httpTesting.expectOne('api/nfs-ganesha/export');
208 expect(req.request.method).toBe('POST');
209 expect(req.request.body).toEqual({
212 cluster_id: 'cluster1',
217 sec_label_xattr: null,
223 security_label: false,
224 squash: 'no_root_squash',
226 transports: ['TCP', 'UDP']