]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / rgw-daemon-list / rgw-daemon-list.component.spec.ts
CommitLineData
11fdf7f2 1import { HttpClientTestingModule } from '@angular/common/http/testing';
a4b75251
TL
2import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
3import { By } from '@angular/platform-browser';
e306af50 4import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
11fdf7f2
TL
5import { RouterTestingModule } from '@angular/router/testing';
6
f67539c2 7import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
e306af50 8import { of } from 'rxjs';
11fdf7f2 9
f67539c2 10import { PerformanceCounterModule } from '~/app/ceph/performance-counter/performance-counter.module';
a4b75251
TL
11import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon';
12import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
f67539c2
TL
13import { RgwSiteService } from '~/app/shared/api/rgw-site.service';
14import { Permissions } from '~/app/shared/models/permissions';
15import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
16import { SharedModule } from '~/app/shared/shared.module';
17import { configureTestBed, TabHelper } from '~/testing/unit-test-helper';
11fdf7f2
TL
18import { RgwDaemonDetailsComponent } from '../rgw-daemon-details/rgw-daemon-details.component';
19import { RgwDaemonListComponent } from './rgw-daemon-list.component';
20
21describe('RgwDaemonListComponent', () => {
22 let component: RgwDaemonListComponent;
23 let fixture: ComponentFixture<RgwDaemonListComponent>;
e306af50
TL
24 let getPermissionsSpy: jasmine.Spy;
25 let getRealmsSpy: jasmine.Spy;
a4b75251 26 let listDaemonsSpy: jest.SpyInstance;
e306af50 27 const permissions = new Permissions({ grafana: ['read'] });
a4b75251
TL
28 const daemon: RgwDaemon = {
29 id: '8000',
30 service_map_id: '4803',
31 version: 'ceph version',
32 server_hostname: 'ceph',
33 realm_name: 'realm1',
34 zonegroup_name: 'zg1-realm1',
35 zone_name: 'zone1-zg1-realm1',
1e59de90
TL
36 default: true,
37 port: 80
a4b75251 38 };
e306af50 39
f67539c2
TL
40 const expectTabsAndHeading = (length: number, heading: string) => {
41 const tabs = TabHelper.getTextContents(fixture);
e306af50 42 expect(tabs.length).toEqual(length);
f67539c2 43 expect(tabs[length - 1]).toEqual(heading);
e306af50 44 };
11fdf7f2
TL
45
46 configureTestBed({
47 declarations: [RgwDaemonListComponent, RgwDaemonDetailsComponent],
48 imports: [
e306af50 49 BrowserAnimationsModule,
11fdf7f2 50 HttpClientTestingModule,
f67539c2 51 NgbNavModule,
11fdf7f2
TL
52 PerformanceCounterModule,
53 SharedModule,
54 RouterTestingModule
f67539c2 55 ]
11fdf7f2
TL
56 });
57
58 beforeEach(() => {
f67539c2 59 getPermissionsSpy = spyOn(TestBed.inject(AuthStorageService), 'getPermissions');
e306af50 60 getPermissionsSpy.and.returnValue(new Permissions({}));
f67539c2 61 getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get');
e306af50 62 getRealmsSpy.and.returnValue(of([]));
a4b75251
TL
63 listDaemonsSpy = jest
64 .spyOn(TestBed.inject(RgwDaemonService), 'list')
65 .mockReturnValue(of([daemon]));
11fdf7f2
TL
66 fixture = TestBed.createComponent(RgwDaemonListComponent);
67 component = fixture.componentInstance;
11fdf7f2
TL
68 });
69
70 it('should create', () => {
e306af50 71 fixture.detectChanges();
11fdf7f2
TL
72 expect(component).toBeTruthy();
73 });
e306af50 74
a4b75251
TL
75 it('should show a row with daemon info', fakeAsync(() => {
76 fixture.detectChanges();
77 tick();
78 expect(listDaemonsSpy).toHaveBeenCalledTimes(1);
79 expect(component.daemons).toEqual([daemon]);
80 expect(fixture.debugElement.query(By.css('cd-table')).nativeElement.textContent).toContain(
39ae355f 81 'total of 1'
a4b75251
TL
82 );
83
84 fixture.destroy();
85 }));
86
1e59de90 87 it('should only show Gateways List tab', () => {
e306af50
TL
88 fixture.detectChanges();
89
1e59de90 90 expectTabsAndHeading(1, 'Gateways List');
e306af50
TL
91 });
92
93 it('should show Overall Performance tab', () => {
94 getPermissionsSpy.and.returnValue(permissions);
95 fixture.detectChanges();
96
97 expectTabsAndHeading(2, 'Overall Performance');
98 });
99
100 it('should show Sync Performance tab', () => {
101 getPermissionsSpy.and.returnValue(permissions);
102 getRealmsSpy.and.returnValue(of(['realm1']));
103 fixture.detectChanges();
104
105 expectTabsAndHeading(3, 'Sync Performance');
106 });
11fdf7f2 107});