]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
3c8e0bb502de75e4914d6d2e6b97c50e24390a21
[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, i18nProviders } from '../../../../testing/unit-test-helper';
6 import { CdFormBuilder } from '../../../shared/forms/cd-form-builder';
7 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
8 import { SharedModule } from '../../../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     providers: i18nProviders
19   });
20
21   beforeEach(() => {
22     fixture = TestBed.createComponent(NfsFormClientComponent);
23     const formBuilder = TestBed.get(CdFormBuilder);
24     component = fixture.componentInstance;
25
26     component.form = this.nfsForm = new CdFormGroup({
27       access_type: new FormControl(''),
28       clients: formBuilder.array([]),
29       squash: new FormControl('')
30     });
31
32     fixture.detectChanges();
33   });
34
35   it('should create', () => {
36     expect(component).toBeTruthy();
37   });
38
39   it('should add a client', () => {
40     expect(component.form.getValue('clients')).toEqual([]);
41     component.addClient();
42     expect(component.form.getValue('clients')).toEqual([
43       { access_type: '', addresses: '', squash: '' }
44     ]);
45   });
46
47   it('should return form access_type', () => {
48     expect(component.getNoAccessTypeDescr()).toBe('-- Select the access type --');
49
50     component.form.patchValue({ access_type: 'RW' });
51     expect(component.getNoAccessTypeDescr()).toBe('RW (inherited from global config)');
52   });
53
54   it('should return form squash', () => {
55     expect(component.getNoSquashDescr()).toBe(
56       '-- Select what kind of user id squashing is performed --'
57     );
58
59     component.form.patchValue({ squash: 'root_id_squash' });
60     expect(component.getNoSquashDescr()).toBe('root_id_squash (inherited from global config)');
61   });
62
63   it('should remove client', () => {
64     component.addClient();
65     expect(component.form.getValue('clients')).toEqual([
66       { access_type: '', addresses: '', squash: '' }
67     ]);
68
69     component.removeClient(0);
70     expect(component.form.getValue('clients')).toEqual([]);
71   });
72 });