]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
e721c8160c3272c3e436d08f958fdf3ddc3b5953
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { FormControl, ReactiveFormsModule } from '@angular/forms';
3
4 import { BsModalRef } from 'ngx-bootstrap/modal';
5
6 import { SharedModule } from '../../../shared/shared.module';
7 import { configureTestBed } from '../../../shared/unit-test-helper';
8 import { RgwUserSubuserModalComponent } from './rgw-user-subuser-modal.component';
9
10 describe('RgwUserSubuserModalComponent', () => {
11   let component: RgwUserSubuserModalComponent;
12   let fixture: ComponentFixture<RgwUserSubuserModalComponent>;
13
14   configureTestBed({
15     declarations: [ RgwUserSubuserModalComponent ],
16     imports: [
17       ReactiveFormsModule,
18       SharedModule
19     ],
20     providers: [ BsModalRef ]
21   });
22
23   beforeEach(() => {
24     fixture = TestBed.createComponent(RgwUserSubuserModalComponent);
25     component = fixture.componentInstance;
26     fixture.detectChanges();
27   });
28
29   it('should create', () => {
30     expect(component).toBeTruthy();
31   });
32
33   describe('subuserValidator', () => {
34     beforeEach(() => {
35       component.editing = false;
36       component.subusers = [
37         { id: 'Edith', permissions: 'full-control' },
38         { id: 'Edith:images', permissions: 'read-write' }
39       ];
40     });
41
42     it('should validate subuser (1/5)', () => {
43       component.editing = true;
44       const validatorFn = component.subuserValidator();
45       const resp = validatorFn(new FormControl());
46       expect(resp).toBe(null);
47     });
48
49     it('should validate subuser (2/5)', () => {
50       const validatorFn = component.subuserValidator();
51       const resp = validatorFn(new FormControl(''));
52       expect(resp).toBe(null);
53     });
54
55     it('should validate subuser (3/5)', () => {
56       const validatorFn = component.subuserValidator();
57       const resp = validatorFn(new FormControl('Melissa'));
58       expect(resp).toBe(null);
59     });
60
61     it('should validate subuser (4/5)', () => {
62       const validatorFn = component.subuserValidator();
63       const resp = validatorFn(new FormControl('Edith'));
64       expect(resp.subuserIdExists).toBeTruthy();
65     });
66
67     it('should validate subuser (5/5)', () => {
68       const validatorFn = component.subuserValidator();
69       const resp = validatorFn(new FormControl('images'));
70       expect(resp.subuserIdExists).toBeTruthy();
71     });
72   });
73 });