]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
ada6da551df22c64c7eb8d0b2f49a6e62cb229b9
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormControl, ReactiveFormsModule } from '@angular/forms';
4
5 import { configureTestBed } from '~/testing/unit-test-helper';
6 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
7 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
8 import { SharedModule } from '~/app/shared/shared.module';
9 import { NfsFormClientComponent } from './nfs-form-client.component';
10
11 describe('NfsFormClientComponent', () => {
12   let component: NfsFormClientComponent;
13   let fixture: ComponentFixture<NfsFormClientComponent>;
14
15   configureTestBed({
16     declarations: [NfsFormClientComponent],
17     imports: [ReactiveFormsModule, SharedModule, HttpClientTestingModule]
18   });
19
20   beforeEach(() => {
21     fixture = TestBed.createComponent(NfsFormClientComponent);
22     const formBuilder = TestBed.inject(CdFormBuilder);
23     component = fixture.componentInstance;
24
25     component.form = new CdFormGroup({
26       access_type: new FormControl(''),
27       clients: formBuilder.array([]),
28       squash: new FormControl('')
29     });
30
31     fixture.detectChanges();
32   });
33
34   it('should create', () => {
35     expect(component).toBeTruthy();
36   });
37
38   it('should add a client', () => {
39     expect(component.form.getValue('clients')).toEqual([]);
40     component.addClient();
41     expect(component.form.getValue('clients')).toEqual([
42       { access_type: '', addresses: '', squash: '' }
43     ]);
44   });
45
46   it('should return form access_type', () => {
47     expect(component.getNoAccessTypeDescr()).toBe('-- Select the access type --');
48
49     component.form.patchValue({ access_type: 'RW' });
50     expect(component.getNoAccessTypeDescr()).toBe('RW (inherited from global config)');
51   });
52
53   it('should return form squash', () => {
54     expect(component.getNoSquashDescr()).toBe(
55       '-- Select what kind of user id squashing is performed --'
56     );
57
58     component.form.patchValue({ squash: 'root_id_squash' });
59     expect(component.getNoSquashDescr()).toBe('root_id_squash (inherited from global config)');
60   });
61
62   it('should remove client', () => {
63     component.addClient();
64     expect(component.form.getValue('clients')).toEqual([
65       { access_type: '', addresses: '', squash: '' }
66     ]);
67
68     component.removeClient(0);
69     expect(component.form.getValue('clients')).toEqual([]);
70   });
71 });