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