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';
9 import { of } from 'rxjs';
11 import { ActivatedRouteStub } from '../../../../testing/activated-route-stub';
12 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
13 import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe';
14 import { SummaryService } from '../../../shared/services/summary.service';
15 import { SharedModule } from '../../../shared/shared.module';
16 import { NfsFormClientComponent } from '../nfs-form-client/nfs-form-client.component';
17 import { NfsFormComponent } from './nfs-form.component';
19 describe('NfsFormComponent', () => {
20 let component: NfsFormComponent;
21 let fixture: ComponentFixture<NfsFormComponent>;
22 let httpTesting: HttpTestingController;
23 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 })
47 const summaryService = TestBed.get(SummaryService);
48 spyOn(summaryService, 'refresh').and.callFake(() => true);
49 spyOn(summaryService, 'subscribeOnce').and.callFake(() =>
55 fixture = TestBed.createComponent(NfsFormComponent);
56 component = fixture.componentInstance;
57 httpTesting = TestBed.get(HttpTestingController);
58 activatedRoute = TestBed.get(ActivatedRoute);
59 fixture.detectChanges();
61 httpTesting.expectOne('api/nfs-ganesha/daemon').flush([
62 { daemon_id: 'node1', cluster_id: 'cluster1' },
63 { daemon_id: 'node2', cluster_id: 'cluster1' },
64 { daemon_id: 'node5', cluster_id: 'cluster2' }
66 httpTesting.expectOne('ui-api/nfs-ganesha/fsals').flush(['CEPH', 'RGW']);
67 httpTesting.expectOne('ui-api/nfs-ganesha/cephx/clients').flush(['admin', 'fs', 'rgw']);
68 httpTesting.expectOne('ui-api/nfs-ganesha/cephfs/filesystems').flush([{ id: 1, name: 'a' }]);
69 httpTesting.expectOne('api/rgw/user').flush(['test', 'dev']);
75 httpTesting.expectOne('api/rgw/user/dev').flush(user_dev);
81 httpTesting.expectOne('api/rgw/user/test').flush(user_test);
85 it('should create', () => {
86 expect(component).toBeTruthy();
89 it('should process all data', () => {
90 expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] });
91 expect(component.isDefaultCluster).toEqual(false);
92 expect(component.allFsals).toEqual([
93 { descr: 'CephFS', value: 'CEPH' },
94 { descr: 'Object Gateway', value: 'RGW' }
96 expect(component.allCephxClients).toEqual(['admin', 'fs', 'rgw']);
97 expect(component.allFsNames).toEqual([{ id: 1, name: 'a' }]);
98 expect(component.allRgwUsers).toEqual(['dev']);
101 it('should create the form', () => {
102 expect(component.nfsForm.value).toEqual({
107 fsal: { fs_name: 'a', name: '', rgw_user_id: '', user_id: '' },
112 sec_label_xattr: 'security.selinux',
113 security_label: false,
121 it('should prepare data when selecting an cluster', () => {
122 expect(component.allDaemons).toEqual({ cluster1: ['node1', 'node2'], cluster2: ['node5'] });
123 expect(component.daemonsSelections).toEqual([]);
125 component.nfsForm.patchValue({ cluster_id: 'cluster1' });
126 component.onClusterChange();
128 expect(component.daemonsSelections).toEqual([
129 { description: '', name: 'node1', selected: false, enabled: true },
130 { description: '', name: 'node2', selected: false, enabled: true }
134 it('should clean data when changing cluster', () => {
135 component.nfsForm.patchValue({ cluster_id: 'cluster1', daemons: ['node1'] });
136 component.nfsForm.patchValue({ cluster_id: 'node2' });
137 component.onClusterChange();
139 expect(component.nfsForm.getValue('daemons')).toEqual([]);
142 describe('should submit request', () => {
144 component.nfsForm.patchValue({
147 cluster_id: 'cluster1',
149 fsal: { name: 'CEPH', user_id: 'fs', fs_name: 1, rgw_user_id: '' },
154 squash: 'no_root_squash',
161 it('should remove "pseudo" requirement when NFS v4 disabled', () => {
162 component.nfsForm.patchValue({
163 protocolNfsv4: false,
167 component.nfsForm.updateValueAndValidity({ emitEvent: false });
168 expect(component.nfsForm.valid).toBeTruthy();
171 it('should call update', () => {
172 activatedRoute.setParams({ cluster_id: 'cluster1', export_id: '1' });
173 component.isEdit = true;
174 component.cluster_id = 'cluster1';
175 component.export_id = '1';
176 component.nfsForm.patchValue({ export_id: 1 });
177 component.submitAction();
179 const req = httpTesting.expectOne('api/nfs-ganesha/export/cluster1/1');
180 expect(req.request.method).toBe('PUT');
181 expect(req.request.body).toEqual({
184 cluster_id: 'cluster1',
187 fsal: { fs_name: 1, name: 'CEPH', sec_label_xattr: null, user_id: 'fs' },
191 security_label: false,
192 squash: 'no_root_squash',
194 transports: ['TCP', 'UDP']
198 it('should call create', () => {
199 activatedRoute.setParams({ cluster_id: undefined, export_id: undefined });
200 component.submitAction();
202 const req = httpTesting.expectOne('api/nfs-ganesha/export');
203 expect(req.request.method).toBe('POST');
204 expect(req.request.body).toEqual({
207 cluster_id: 'cluster1',
212 sec_label_xattr: null,
218 security_label: false,
219 squash: 'no_root_squash',
221 transports: ['TCP', 'UDP']