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';
20 import { TableComponent } from '~/app/shared/datatable/table/table.component';
22 describe('RgwDaemonListComponent', () => {
23 let component: RgwDaemonListComponent;
24 let fixture: ComponentFixture<RgwDaemonListComponent>;
25 let getPermissionsSpy: jasmine.Spy;
26 let getRealmsSpy: jasmine.Spy;
27 let listDaemonsSpy: jest.SpyInstance;
28 const permissions = new Permissions({ grafana: ['read'] });
29 const daemon: RgwDaemon = {
31 service_map_id: '4803',
32 version: 'ceph version',
33 server_hostname: 'ceph',
35 zonegroup_name: 'zg1-realm1',
36 zonegroup_id: 'zg1-id',
37 zone_name: 'zone1-zg1-realm1',
42 const expectTabsAndHeading = (length: number, heading: string) => {
43 const tabs = TabHelper.getTextContents(fixture);
44 expect(tabs.length).toEqual(length);
45 expect(tabs[length - 1]).toEqual(heading);
49 declarations: [RgwDaemonListComponent, RgwDaemonDetailsComponent, TableComponent],
51 BrowserAnimationsModule,
52 HttpClientTestingModule,
54 PerformanceCounterModule,
61 getPermissionsSpy = spyOn(TestBed.inject(AuthStorageService), 'getPermissions');
62 getPermissionsSpy.and.returnValue(new Permissions({}));
63 getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get');
64 getRealmsSpy.and.returnValue(of([]));
66 .spyOn(TestBed.inject(RgwDaemonService), 'list')
67 .mockReturnValue(of([daemon]));
68 fixture = TestBed.createComponent(RgwDaemonListComponent);
69 component = fixture.componentInstance;
72 it('should create', () => {
73 fixture.detectChanges();
74 expect(component).toBeTruthy();
77 it('should show a row with daemon info', fakeAsync(() => {
78 fixture.detectChanges();
80 expect(listDaemonsSpy).toHaveBeenCalledTimes(1);
81 expect(component.daemons).toEqual([daemon]);
82 const cdTableEl = fixture.debugElement.query(By.directive(TableComponent));
83 const cdTableComponent: TableComponent = cdTableEl.componentInstance;
84 cdTableComponent.ngAfterViewInit();
85 fixture.detectChanges();
86 expect(fixture.debugElement.query(By.css('cd-table')).nativeElement.textContent).toContain(
93 it('should only show Gateways List tab', () => {
94 fixture.detectChanges();
96 expectTabsAndHeading(1, 'Gateways List');
99 it('should show Overall Performance tab', () => {
100 getPermissionsSpy.and.returnValue(permissions);
101 fixture.detectChanges();
103 expectTabsAndHeading(2, 'Overall Performance');
106 it('should show Sync Performance tab', () => {
107 getPermissionsSpy.and.returnValue(permissions);
108 getRealmsSpy.and.returnValue(of(['realm1']));
109 fixture.detectChanges();
111 expectTabsAndHeading(3, 'Sync Performance');