1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
3 import { By } from '@angular/platform-browser';
4 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5 import { RouterTestingModule } from '@angular/router/testing';
7 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
8 import { of } from 'rxjs';
10 import { PerformanceCounterModule } from '~/app/ceph/performance-counter/performance-counter.module';
11 import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon';
12 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
13 import { RgwSiteService } from '~/app/shared/api/rgw-site.service';
14 import { Permissions } from '~/app/shared/models/permissions';
15 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
16 import { SharedModule } from '~/app/shared/shared.module';
17 import { configureTestBed, TabHelper } from '~/testing/unit-test-helper';
18 import { RgwDaemonDetailsComponent } from '../rgw-daemon-details/rgw-daemon-details.component';
19 import { RgwDaemonListComponent } from './rgw-daemon-list.component';
21 describe('RgwDaemonListComponent', () => {
22 let component: RgwDaemonListComponent;
23 let fixture: ComponentFixture<RgwDaemonListComponent>;
24 let getPermissionsSpy: jasmine.Spy;
25 let getRealmsSpy: jasmine.Spy;
26 let listDaemonsSpy: jest.SpyInstance;
27 const permissions = new Permissions({ grafana: ['read'] });
28 const daemon: RgwDaemon = {
30 service_map_id: '4803',
31 version: 'ceph version',
32 server_hostname: 'ceph',
34 zonegroup_name: 'zg1-realm1',
35 zone_name: 'zone1-zg1-realm1',
40 const expectTabsAndHeading = (length: number, heading: string) => {
41 const tabs = TabHelper.getTextContents(fixture);
42 expect(tabs.length).toEqual(length);
43 expect(tabs[length - 1]).toEqual(heading);
47 declarations: [RgwDaemonListComponent, RgwDaemonDetailsComponent],
49 BrowserAnimationsModule,
50 HttpClientTestingModule,
52 PerformanceCounterModule,
59 getPermissionsSpy = spyOn(TestBed.inject(AuthStorageService), 'getPermissions');
60 getPermissionsSpy.and.returnValue(new Permissions({}));
61 getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get');
62 getRealmsSpy.and.returnValue(of([]));
64 .spyOn(TestBed.inject(RgwDaemonService), 'list')
65 .mockReturnValue(of([daemon]));
66 fixture = TestBed.createComponent(RgwDaemonListComponent);
67 component = fixture.componentInstance;
70 it('should create', () => {
71 fixture.detectChanges();
72 expect(component).toBeTruthy();
75 it('should show a row with daemon info', fakeAsync(() => {
76 fixture.detectChanges();
78 expect(listDaemonsSpy).toHaveBeenCalledTimes(1);
79 expect(component.daemons).toEqual([daemon]);
80 expect(fixture.debugElement.query(By.css('cd-table')).nativeElement.textContent).toContain(
87 it('should only show Gateways List tab', () => {
88 fixture.detectChanges();
90 expectTabsAndHeading(1, 'Gateways List');
93 it('should show Overall Performance tab', () => {
94 getPermissionsSpy.and.returnValue(permissions);
95 fixture.detectChanges();
97 expectTabsAndHeading(2, 'Overall Performance');
100 it('should show Sync Performance tab', () => {
101 getPermissionsSpy.and.returnValue(permissions);
102 getRealmsSpy.and.returnValue(of(['realm1']));
103 fixture.detectChanges();
105 expectTabsAndHeading(3, 'Sync Performance');