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';
6 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
7 import { of } from 'rxjs';
9 import { PerformanceCounterModule } from '~/app/ceph/performance-counter/performance-counter.module';
10 import { RgwSiteService } from '~/app/shared/api/rgw-site.service';
11 import { Permissions } from '~/app/shared/models/permissions';
12 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
13 import { SharedModule } from '~/app/shared/shared.module';
14 import { configureTestBed, TabHelper } from '~/testing/unit-test-helper';
15 import { RgwDaemonDetailsComponent } from '../rgw-daemon-details/rgw-daemon-details.component';
16 import { RgwDaemonListComponent } from './rgw-daemon-list.component';
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'] });
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);
32 declarations: [RgwDaemonListComponent, RgwDaemonDetailsComponent],
34 BrowserAnimationsModule,
35 HttpClientTestingModule,
37 PerformanceCounterModule,
44 getPermissionsSpy = spyOn(TestBed.inject(AuthStorageService), 'getPermissions');
45 getPermissionsSpy.and.returnValue(new Permissions({}));
46 getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get');
47 getRealmsSpy.and.returnValue(of([]));
48 fixture = TestBed.createComponent(RgwDaemonListComponent);
49 component = fixture.componentInstance;
52 it('should create', () => {
53 fixture.detectChanges();
54 expect(component).toBeTruthy();
57 it('should only show Daemons List tab', () => {
58 fixture.detectChanges();
60 expectTabsAndHeading(1, 'Daemons List');
63 it('should show Overall Performance tab', () => {
64 getPermissionsSpy.and.returnValue(permissions);
65 fixture.detectChanges();
67 expectTabsAndHeading(2, 'Overall Performance');
70 it('should show Sync Performance tab', () => {
71 getPermissionsSpy.and.returnValue(permissions);
72 getRealmsSpy.and.returnValue(of(['realm1']));
73 fixture.detectChanges();
75 expectTabsAndHeading(3, 'Sync Performance');