]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
1b29228c38cabc511e98c849b4816d134e654714
[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 { BsModalService } from 'ngx-bootstrap/modal';
6 import { TabsModule } from 'ngx-bootstrap/tabs';
7
8 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
9 import { SharedModule } from '../../../shared/shared.module';
10 import { RgwUserS3Key } from '../models/rgw-user-s3-key';
11 import { RgwUserDetailsComponent } from './rgw-user-details.component';
12
13 describe('RgwUserDetailsComponent', () => {
14   let component: RgwUserDetailsComponent;
15   let fixture: ComponentFixture<RgwUserDetailsComponent>;
16
17   configureTestBed({
18     declarations: [RgwUserDetailsComponent],
19     imports: [BrowserAnimationsModule, HttpClientTestingModule, SharedModule, TabsModule.forRoot()],
20     providers: [BsModalService, i18nProviders]
21   });
22
23   beforeEach(() => {
24     fixture = TestBed.createComponent(RgwUserDetailsComponent);
25     component = fixture.componentInstance;
26     component.selection = {};
27     fixture.detectChanges();
28   });
29
30   it('should create', () => {
31     expect(component).toBeTruthy();
32
33     const detailsTab = fixture.debugElement.nativeElement.querySelector('tab[heading="Details"]');
34     expect(detailsTab).toBeTruthy();
35     const keysTab = fixture.debugElement.nativeElement.querySelector('tab[heading="Keys"]');
36     expect(keysTab).toBeFalsy();
37   });
38
39   it('should show "Details" tab', () => {
40     component.selection = { uid: 'myUsername' };
41     fixture.detectChanges();
42
43     const detailsTab = fixture.debugElement.nativeElement.querySelector('tab[heading="Details"]');
44     expect(detailsTab).toBeTruthy();
45     const keysTab = fixture.debugElement.nativeElement.querySelector('tab[heading="Keys"]');
46     expect(keysTab).toBeFalsy();
47   });
48
49   it('should show "Keys" tab', () => {
50     const s3Key = new RgwUserS3Key();
51     component.selection = { keys: [s3Key] };
52     component.ngOnChanges();
53     fixture.detectChanges();
54
55     const detailsTab = fixture.debugElement.nativeElement.querySelector('tab[heading="Details"]');
56     expect(detailsTab).toBeTruthy();
57     const keysTab = fixture.debugElement.nativeElement.querySelector('tab[heading="Keys"]');
58     expect(keysTab).toBeTruthy();
59   });
60
61   it('should show correct "System" info', () => {
62     component.selection = { uid: '', email: '', system: 'true', keys: [], swift_keys: [] };
63
64     component.ngOnChanges();
65     fixture.detectChanges();
66
67     const detailsTab = fixture.debugElement.nativeElement.querySelectorAll(
68       '.table.table-striped.table-bordered tr td'
69     );
70     expect(detailsTab[6].textContent).toEqual('System');
71     expect(detailsTab[7].textContent).toEqual('Yes');
72
73     component.selection.system = 'false';
74     component.ngOnChanges();
75     fixture.detectChanges();
76
77     expect(detailsTab[7].textContent).toEqual('No');
78   });
79 });