]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
c308bc6d94b161011dc42be3790c14aef05dc6f6
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4
5 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
6
7 import { SharedModule } from '~/app/shared/shared.module';
8 import { configureTestBed } from '~/testing/unit-test-helper';
9 import { RgwUserDetailsComponent } from './rgw-user-details.component';
10 import { ModalService } from 'carbon-components-angular';
11
12 describe('RgwUserDetailsComponent', () => {
13   let component: RgwUserDetailsComponent;
14   let fixture: ComponentFixture<RgwUserDetailsComponent>;
15   let modalRef: any;
16   configureTestBed({
17     declarations: [RgwUserDetailsComponent],
18     imports: [BrowserAnimationsModule, HttpClientTestingModule, SharedModule, NgbNavModule],
19     provider: [ModalService]
20   });
21
22   beforeEach(() => {
23     fixture = TestBed.createComponent(RgwUserDetailsComponent);
24     component = fixture.componentInstance;
25     component.selection = {};
26     fixture.detectChanges();
27   });
28
29   it('should create', () => {
30     expect(component).toBeTruthy();
31   });
32
33   it('should show correct "System" info', () => {
34     component.selection = { uid: '', email: '', system: true, keys: [], swift_keys: [] };
35
36     component.ngOnChanges();
37     fixture.detectChanges();
38
39     const detailsTab = fixture.debugElement.nativeElement.querySelectorAll(
40       '.cds--data-table--sort.cds--data-table--no-border tr td'
41     );
42     expect(detailsTab[10].textContent).toEqual('System user');
43     expect(detailsTab[11].textContent).toEqual('Yes');
44
45     component.selection.system = false;
46     component.ngOnChanges();
47     fixture.detectChanges();
48
49     expect(detailsTab[11].textContent).toEqual('No');
50   });
51
52   it('should show mfa ids only if length > 0', () => {
53     component.selection = {
54       uid: 'dashboard',
55       email: '',
56       system: 'true',
57       keys: [],
58       swift_keys: [],
59       mfa_ids: ['testMFA1', 'testMFA2']
60     };
61
62     component.ngOnChanges();
63     fixture.detectChanges();
64
65     const detailsTab = fixture.debugElement.nativeElement.querySelectorAll(
66       '.cds--data-table--sort.cds--data-table--no-border tr td'
67     );
68     expect(detailsTab[14].textContent).toEqual('MFAs(Id)');
69     expect(detailsTab[15].textContent).toEqual('testMFA1, testMFA2');
70   });
71   it('should test updateKeysSelection', () => {
72     component.selection = {
73       hasMultiSelection: false,
74       hasSelection: false,
75       hasSingleSelection: false,
76       _selected: []
77     };
78     component.updateKeysSelection(component.selection);
79     expect(component.keysSelection).toEqual(component.selection);
80   });
81   it('should call showKeyModal when key selection is of type S3', () => {
82     component.keysSelection.first = () => {
83       return { type: 'S3', ref: { user: '', access_key: '', secret_key: '' } };
84     };
85     const modalShowSpy = spyOn(component['cdsModalService'], 'show').and.callFake(() => {
86       modalRef = {
87         setValues: jest.fn(),
88         setViewing: jest.fn()
89       };
90       return modalRef;
91     });
92     component.showKeyModal();
93     expect(modalShowSpy).toHaveBeenCalled();
94     // expect(s).toHaveBeenCalledWith( modalRef.componentInstance.setViewing);
95   });
96   it('should call showKeyModal when key selection is of type Swift', () => {
97     component.keysSelection.first = () => {
98       return { type: 'Swift', ref: { user: '', access_key: '', secret_key: '' } };
99     };
100     const modalShowSpy = spyOn(component['cdsModalService'], 'show').and.callFake(() => {
101       modalRef = {
102         setValues: jest.fn(),
103         setViewing: jest.fn()
104       };
105       return modalRef;
106     });
107     component.showKeyModal();
108     expect(modalShowSpy).toHaveBeenCalled();
109     // expect(s).toHaveBeenCalledWith( modalRef.componentInstance.setViewing);
110   });
111 });