1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
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';
12 describe('RgwUserDetailsComponent', () => {
13 let component: RgwUserDetailsComponent;
14 let fixture: ComponentFixture<RgwUserDetailsComponent>;
17 declarations: [RgwUserDetailsComponent],
18 imports: [BrowserAnimationsModule, HttpClientTestingModule, SharedModule, NgbNavModule],
19 provider: [ModalService]
23 fixture = TestBed.createComponent(RgwUserDetailsComponent);
24 component = fixture.componentInstance;
25 component.selection = {};
26 fixture.detectChanges();
29 it('should create', () => {
30 expect(component).toBeTruthy();
33 it('should show correct "System" info', () => {
34 component.selection = { uid: '', email: '', system: true, keys: [], swift_keys: [] };
36 component.ngOnChanges();
37 fixture.detectChanges();
39 const detailsTab = fixture.debugElement.nativeElement.querySelectorAll(
40 '.cds--data-table--sort.cds--data-table--no-border tr td'
42 expect(detailsTab[10].textContent).toEqual('System user');
43 expect(detailsTab[11].textContent).toEqual('Yes');
45 component.selection.system = false;
46 component.ngOnChanges();
47 fixture.detectChanges();
49 expect(detailsTab[11].textContent).toEqual('No');
52 it('should show mfa ids only if length > 0', () => {
53 component.selection = {
59 mfa_ids: ['testMFA1', 'testMFA2']
62 component.ngOnChanges();
63 fixture.detectChanges();
65 const detailsTab = fixture.debugElement.nativeElement.querySelectorAll(
66 '.cds--data-table--sort.cds--data-table--no-border tr td'
68 expect(detailsTab[14].textContent).toEqual('MFAs(Id)');
69 expect(detailsTab[15].textContent).toEqual('testMFA1, testMFA2');
71 it('should test updateKeysSelection', () => {
72 component.selection = {
73 hasMultiSelection: false,
75 hasSingleSelection: false,
78 component.updateKeysSelection(component.selection);
79 expect(component.keysSelection).toEqual(component.selection);
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: '' } };
85 const modalShowSpy = spyOn(component['cdsModalService'], 'show').and.callFake(() => {
92 component.showKeyModal();
93 expect(modalShowSpy).toHaveBeenCalled();
94 // expect(s).toHaveBeenCalledWith( modalRef.componentInstance.setViewing);
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: '' } };
100 const modalShowSpy = spyOn(component['cdsModalService'], 'show').and.callFake(() => {
102 setValues: jest.fn(),
103 setViewing: jest.fn()
107 component.showKeyModal();
108 expect(modalShowSpy).toHaveBeenCalled();
109 // expect(s).toHaveBeenCalledWith( modalRef.componentInstance.setViewing);