summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-subuser-modal/rgw-user-subuser-modal.component.spec.ts
blob: d4843aa9dd2012998ef71967f08ff5432a1dbd75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';

import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { RgwUserSubuserModalComponent } from './rgw-user-subuser-modal.component';

describe('RgwUserSubuserModalComponent', () => {
  let component: RgwUserSubuserModalComponent;
  let fixture: ComponentFixture<RgwUserSubuserModalComponent>;

  configureTestBed({
    declarations: [RgwUserSubuserModalComponent],
    imports: [ReactiveFormsModule, SharedModule, RouterTestingModule],
    providers: [NgbActiveModal]
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(RgwUserSubuserModalComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  describe('subuserValidator', () => {
    beforeEach(() => {
      component.editing = false;
      component.subusers = [
        { id: 'Edith', permissions: 'full-control' },
        { id: 'Edith:images', permissions: 'read-write' }
      ];
    });

    it('should validate subuser (1/5)', () => {
      component.editing = true;
      const validatorFn = component.subuserValidator();
      const resp = validatorFn(new FormControl());
      expect(resp).toBe(null);
    });

    it('should validate subuser (2/5)', () => {
      const validatorFn = component.subuserValidator();
      const resp = validatorFn(new FormControl(''));
      expect(resp).toBe(null);
    });

    it('should validate subuser (3/5)', () => {
      const validatorFn = component.subuserValidator();
      const resp = validatorFn(new FormControl('Melissa'));
      expect(resp).toBe(null);
    });

    it('should validate subuser (4/5)', () => {
      const validatorFn = component.subuserValidator();
      const resp = validatorFn(new FormControl('Edith'));
      expect(resp.subuserIdExists).toBeTruthy();
    });

    it('should validate subuser (5/5)', () => {
      const validatorFn = component.subuserValidator();
      const resp = validatorFn(new FormControl('images'));
      expect(resp.subuserIdExists).toBeTruthy();
    });
  });
});