]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.spec.ts
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / rgw-user-details / rgw-user-details.component.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
e306af50 3import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
11fdf7f2 4
f67539c2 5import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
11fdf7f2 6
f67539c2
TL
7import { SharedModule } from '~/app/shared/shared.module';
8import { configureTestBed, TabHelper } from '~/testing/unit-test-helper';
9f95a23c 9import { RgwUserS3Key } from '../models/rgw-user-s3-key';
11fdf7f2
TL
10import { RgwUserDetailsComponent } from './rgw-user-details.component';
11
12describe('RgwUserDetailsComponent', () => {
13 let component: RgwUserDetailsComponent;
14 let fixture: ComponentFixture<RgwUserDetailsComponent>;
15
16 configureTestBed({
17 declarations: [RgwUserDetailsComponent],
f67539c2 18 imports: [BrowserAnimationsModule, HttpClientTestingModule, SharedModule, NgbNavModule]
11fdf7f2
TL
19 });
20
21 beforeEach(() => {
22 fixture = TestBed.createComponent(RgwUserDetailsComponent);
23 component = fixture.componentInstance;
e306af50 24 component.selection = {};
11fdf7f2
TL
25 fixture.detectChanges();
26 });
27
28 it('should create', () => {
29 expect(component).toBeTruthy();
9f95a23c 30
f67539c2
TL
31 const tabs = TabHelper.getTextContents(fixture);
32 expect(tabs).toContain('Details');
33 expect(tabs).not.toContain('Keys');
9f95a23c
TL
34 });
35
36 it('should show "Details" tab', () => {
e306af50 37 component.selection = { uid: 'myUsername' };
9f95a23c
TL
38 fixture.detectChanges();
39
f67539c2
TL
40 const tabs = TabHelper.getTextContents(fixture);
41 expect(tabs).toContain('Details');
42 expect(tabs).not.toContain('Keys');
9f95a23c
TL
43 });
44
45 it('should show "Keys" tab', () => {
46 const s3Key = new RgwUserS3Key();
e306af50 47 component.selection = { keys: [s3Key] };
9f95a23c
TL
48 component.ngOnChanges();
49 fixture.detectChanges();
50
f67539c2
TL
51 const tabs = TabHelper.getTextContents(fixture);
52 expect(tabs).toContain('Details');
53 expect(tabs).toContain('Keys');
9f95a23c
TL
54 });
55
56 it('should show correct "System" info', () => {
e306af50
TL
57 component.selection = { uid: '', email: '', system: 'true', keys: [], swift_keys: [] };
58
9f95a23c
TL
59 component.ngOnChanges();
60 fixture.detectChanges();
61
62 const detailsTab = fixture.debugElement.nativeElement.querySelectorAll(
63 '.table.table-striped.table-bordered tr td'
64 );
f67539c2
TL
65 expect(detailsTab[10].textContent).toEqual('System');
66 expect(detailsTab[11].textContent).toEqual('Yes');
9f95a23c 67
e306af50 68 component.selection.system = 'false';
9f95a23c
TL
69 component.ngOnChanges();
70 fixture.detectChanges();
71
f67539c2 72 expect(detailsTab[11].textContent).toEqual('No');
11fdf7f2 73 });
a4b75251
TL
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 });
11fdf7f2 94});