]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
8dce412135a8798efbb7f4c848febdf8be26c6e8
[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 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
7 import { of } from 'rxjs';
8
9 import { configureTestBed, i18nProviders, TabHelper } from '../../../../testing/unit-test-helper';
10 import { RgwSiteService } from '../../../shared/api/rgw-site.service';
11 import { Permissions } from '../../../shared/models/permissions';
12 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
13 import { SharedModule } from '../../../shared/shared.module';
14 import { PerformanceCounterModule } from '../../performance-counter/performance-counter.module';
15 import { RgwDaemonDetailsComponent } from '../rgw-daemon-details/rgw-daemon-details.component';
16 import { RgwDaemonListComponent } from './rgw-daemon-list.component';
17
18 describe('RgwDaemonListComponent', () => {
19   let component: RgwDaemonListComponent;
20   let fixture: ComponentFixture<RgwDaemonListComponent>;
21   let getPermissionsSpy: jasmine.Spy;
22   let getRealmsSpy: jasmine.Spy;
23   const permissions = new Permissions({ grafana: ['read'] });
24
25   const expectTabsAndHeading = (length: number, heading: string) => {
26     const tabs = TabHelper.getTextContents(fixture);
27     expect(tabs.length).toEqual(length);
28     expect(tabs[length - 1]).toEqual(heading);
29   };
30
31   configureTestBed({
32     declarations: [RgwDaemonListComponent, RgwDaemonDetailsComponent],
33     imports: [
34       BrowserAnimationsModule,
35       HttpClientTestingModule,
36       NgbNavModule,
37       PerformanceCounterModule,
38       SharedModule,
39       RouterTestingModule
40     ],
41     providers: i18nProviders
42   });
43
44   beforeEach(() => {
45     getPermissionsSpy = spyOn(TestBed.inject(AuthStorageService), 'getPermissions');
46     getPermissionsSpy.and.returnValue(new Permissions({}));
47     getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get');
48     getRealmsSpy.and.returnValue(of([]));
49     fixture = TestBed.createComponent(RgwDaemonListComponent);
50     component = fixture.componentInstance;
51   });
52
53   it('should create', () => {
54     fixture.detectChanges();
55     expect(component).toBeTruthy();
56   });
57
58   it('should only show Daemons List tab', () => {
59     fixture.detectChanges();
60
61     expectTabsAndHeading(1, 'Daemons List');
62   });
63
64   it('should show Overall Performance tab', () => {
65     getPermissionsSpy.and.returnValue(permissions);
66     fixture.detectChanges();
67
68     expectTabsAndHeading(2, 'Overall Performance');
69   });
70
71   it('should show Sync Performance tab', () => {
72     getPermissionsSpy.and.returnValue(permissions);
73     getRealmsSpy.and.returnValue(of(['realm1']));
74     fixture.detectChanges();
75
76     expectTabsAndHeading(3, 'Sync Performance');
77   });
78 });