]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
62519cdf478c975e4e88d5b970c418fce53a6235
[ceph-ci.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, TabHelper } from '~/testing/unit-test-helper';
9 import { RgwUserS3Key } from '../models/rgw-user-s3-key';
10 import { RgwUserDetailsComponent } from './rgw-user-details.component';
11
12 describe('RgwUserDetailsComponent', () => {
13   let component: RgwUserDetailsComponent;
14   let fixture: ComponentFixture<RgwUserDetailsComponent>;
15
16   configureTestBed({
17     declarations: [RgwUserDetailsComponent],
18     imports: [BrowserAnimationsModule, HttpClientTestingModule, SharedModule, NgbNavModule]
19   });
20
21   beforeEach(() => {
22     fixture = TestBed.createComponent(RgwUserDetailsComponent);
23     component = fixture.componentInstance;
24     component.selection = {};
25     fixture.detectChanges();
26   });
27
28   it('should create', () => {
29     expect(component).toBeTruthy();
30
31     const tabs = TabHelper.getTextContents(fixture);
32     expect(tabs).toContain('Details');
33     expect(tabs).not.toContain('Keys');
34   });
35
36   it('should show "Details" tab', () => {
37     component.selection = { uid: 'myUsername' };
38     fixture.detectChanges();
39
40     const tabs = TabHelper.getTextContents(fixture);
41     expect(tabs).toContain('Details');
42     expect(tabs).not.toContain('Keys');
43   });
44
45   it('should show "Keys" tab', () => {
46     const s3Key = new RgwUserS3Key();
47     component.selection = { keys: [s3Key] };
48     component.ngOnChanges();
49     fixture.detectChanges();
50
51     const tabs = TabHelper.getTextContents(fixture);
52     expect(tabs).toContain('Details');
53     expect(tabs).toContain('Keys');
54   });
55
56   it('should show correct "System" info', () => {
57     component.selection = { uid: '', email: '', system: 'true', keys: [], swift_keys: [] };
58
59     component.ngOnChanges();
60     fixture.detectChanges();
61
62     const detailsTab = fixture.debugElement.nativeElement.querySelectorAll(
63       '.table.table-striped.table-bordered tr td'
64     );
65     expect(detailsTab[10].textContent).toEqual('System');
66     expect(detailsTab[11].textContent).toEqual('Yes');
67
68     component.selection.system = 'false';
69     component.ngOnChanges();
70     fixture.detectChanges();
71
72     expect(detailsTab[11].textContent).toEqual('No');
73   });
74
75   it('should show mfa ids only if length > 0', () => {
76     component.selection = {
77       uid: 'dashboard',
78       email: '',
79       system: 'true',
80       keys: [],
81       swift_keys: [],
82       mfa_ids: ['testMFA1', 'testMFA2']
83     };
84
85     component.ngOnChanges();
86     fixture.detectChanges();
87
88     const detailsTab = fixture.debugElement.nativeElement.querySelectorAll(
89       '.table.table-striped.table-bordered tr td'
90     );
91     expect(detailsTab[14].textContent).toEqual('MFAs(Id)');
92     expect(detailsTab[15].textContent).toEqual('testMFA1, testMFA2');
93   });
94 });