1 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { RgwOverviewDashboardComponent } from './rgw-overview-dashboard.component';
4 import { of } from 'rxjs';
5 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
6 import { RgwDaemon } from '../models/rgw-daemon';
7 import { HttpClientTestingModule } from '@angular/common/http/testing';
8 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
9 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
10 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
11 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
12 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
13 import { HealthService } from '~/app/shared/api/health.service';
14 import { CardRowComponent } from '~/app/shared/components/card-row/card-row.component';
15 import { CardComponent } from '~/app/shared/components/card/card.component';
16 import { NO_ERRORS_SCHEMA } from '@angular/core';
17 import { configureTestBed } from '~/testing/unit-test-helper';
19 describe('RgwOverviewDashboardComponent', () => {
20 let component: RgwOverviewDashboardComponent;
21 let fixture: ComponentFixture<RgwOverviewDashboardComponent>;
22 const daemon: RgwDaemon = {
24 service_map_id: '4803',
25 version: 'ceph version',
26 server_hostname: 'ceph',
28 zonegroup_name: 'zg1-realm1',
29 zonegroup_id: 'zg1-id',
30 zone_name: 'zone1-zg1-realm1',
36 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
37 realms: ['realm2', 'realm1']
40 const zonegroupList = {
41 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
42 zonegroups: ['zg-1', 'zg-2', 'zg-3']
46 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
47 zones: ['zone4', 'zone5', 'zone6', 'zone7']
50 const bucketAndUserList = {
57 total_pool_bytes_used: 9338880
60 let listDaemonsSpy: jest.SpyInstance;
61 let listZonesSpy: jest.SpyInstance;
62 let listZonegroupsSpy: jest.SpyInstance;
63 let listRealmsSpy: jest.SpyInstance;
64 let listBucketsSpy: jest.SpyInstance;
65 let healthDataSpy: jest.SpyInstance;
69 RgwOverviewDashboardComponent,
74 schemas: [NO_ERRORS_SCHEMA],
75 imports: [HttpClientTestingModule]
80 .spyOn(TestBed.inject(RgwDaemonService), 'list')
81 .mockReturnValue(of([daemon]));
83 .spyOn(TestBed.inject(RgwRealmService), 'list')
84 .mockReturnValue(of(realmList));
85 listZonegroupsSpy = jest
86 .spyOn(TestBed.inject(RgwZonegroupService), 'list')
87 .mockReturnValue(of(zonegroupList));
88 listZonesSpy = jest.spyOn(TestBed.inject(RgwZoneService), 'list').mockReturnValue(of(zoneList));
90 .spyOn(TestBed.inject(RgwBucketService), 'getTotalBucketsAndUsersLength')
91 .mockReturnValue(of(bucketAndUserList));
93 .spyOn(TestBed.inject(HealthService), 'getClusterCapacity')
94 .mockReturnValue(of(healthData));
95 fixture = TestBed.createComponent(RgwOverviewDashboardComponent);
96 component = fixture.componentInstance;
97 fixture.detectChanges();
100 it('should create', () => {
101 expect(component).toBeTruthy();
104 it('should render all cards', () => {
105 fixture.detectChanges();
106 const dashboardCards = fixture.debugElement.nativeElement.querySelectorAll('cd-card');
107 expect(dashboardCards.length).toBe(5);
110 it('should get corresponding data into Daemons', () => {
111 expect(listDaemonsSpy).toHaveBeenCalled();
112 expect(component.rgwDaemonCount).toEqual(1);
115 it('should get corresponding data into Realms', () => {
116 expect(listRealmsSpy).toHaveBeenCalled();
117 expect(component.rgwRealmCount).toEqual(2);
120 it('should get corresponding data into Zonegroups', () => {
121 expect(listZonegroupsSpy).toHaveBeenCalled();
122 expect(component.rgwZonegroupCount).toEqual(3);
125 it('should get corresponding data into Zones', () => {
126 expect(listZonesSpy).toHaveBeenCalled();
127 expect(component.rgwZoneCount).toEqual(4);
130 it('should get corresponding data into Buckets', () => {
131 expect(listBucketsSpy).toHaveBeenCalled();
132 expect(component.rgwBucketCount).toEqual(2);
133 expect(component.UserCount).toEqual(2);
136 it('should get corresponding data into Objects and capacity', () => {
137 expect(healthDataSpy).toHaveBeenCalled();
138 expect(component.objectCount).toEqual('290');
139 expect(component.totalPoolUsedBytes).toEqual(9338880);