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 { 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';
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,
41 providers: i18nProviders
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;
53 it('should create', () => {
54 fixture.detectChanges();
55 expect(component).toBeTruthy();
58 it('should only show Daemons List tab', () => {
59 fixture.detectChanges();
61 expectTabsAndHeading(1, 'Daemons List');
64 it('should show Overall Performance tab', () => {
65 getPermissionsSpy.and.returnValue(permissions);
66 fixture.detectChanges();
68 expectTabsAndHeading(2, 'Overall Performance');
71 it('should show Sync Performance tab', () => {
72 getPermissionsSpy.and.returnValue(permissions);
73 getRealmsSpy.and.returnValue(of(['realm1']));
74 fixture.detectChanges();
76 expectTabsAndHeading(3, 'Sync Performance');