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 zone_name: 'zone1-zg1-realm1',
35 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
36 realms: ['realm2', 'realm1']
39 const zonegroupList = {
40 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
41 zonegroups: ['zg-1', 'zg-2', 'zg-3']
45 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
46 zones: ['zone4', 'zone5', 'zone6', 'zone7']
49 const bucketAndUserList = {
56 total_pool_bytes_used: 9338880
59 let listDaemonsSpy: jest.SpyInstance;
60 let listZonesSpy: jest.SpyInstance;
61 let listZonegroupsSpy: jest.SpyInstance;
62 let listRealmsSpy: jest.SpyInstance;
63 let listBucketsSpy: jest.SpyInstance;
64 let healthDataSpy: jest.SpyInstance;
68 RgwOverviewDashboardComponent,
73 schemas: [NO_ERRORS_SCHEMA],
74 imports: [HttpClientTestingModule]
79 .spyOn(TestBed.inject(RgwDaemonService), 'list')
80 .mockReturnValue(of([daemon]));
82 .spyOn(TestBed.inject(RgwRealmService), 'list')
83 .mockReturnValue(of(realmList));
84 listZonegroupsSpy = jest
85 .spyOn(TestBed.inject(RgwZonegroupService), 'list')
86 .mockReturnValue(of(zonegroupList));
87 listZonesSpy = jest.spyOn(TestBed.inject(RgwZoneService), 'list').mockReturnValue(of(zoneList));
89 .spyOn(TestBed.inject(RgwBucketService), 'getTotalBucketsAndUsersLength')
90 .mockReturnValue(of(bucketAndUserList));
92 .spyOn(TestBed.inject(HealthService), 'getClusterCapacity')
93 .mockReturnValue(of(healthData));
94 fixture = TestBed.createComponent(RgwOverviewDashboardComponent);
95 component = fixture.componentInstance;
96 fixture.detectChanges();
99 it('should create', () => {
100 expect(component).toBeTruthy();
103 it('should render all cards', () => {
104 fixture.detectChanges();
105 const dashboardCards = fixture.debugElement.nativeElement.querySelectorAll('cd-card');
106 expect(dashboardCards.length).toBe(5);
109 it('should get corresponding data into Daemons', () => {
110 expect(listDaemonsSpy).toHaveBeenCalled();
111 expect(component.rgwDaemonCount).toEqual(1);
114 it('should get corresponding data into Realms', () => {
115 expect(listRealmsSpy).toHaveBeenCalled();
116 expect(component.rgwRealmCount).toEqual(2);
119 it('should get corresponding data into Zonegroups', () => {
120 expect(listZonegroupsSpy).toHaveBeenCalled();
121 expect(component.rgwZonegroupCount).toEqual(3);
124 it('should get corresponding data into Zones', () => {
125 expect(listZonesSpy).toHaveBeenCalled();
126 expect(component.rgwZoneCount).toEqual(4);
129 it('should get corresponding data into Buckets', () => {
130 expect(listBucketsSpy).toHaveBeenCalled();
131 expect(component.rgwBucketCount).toEqual(2);
132 expect(component.UserCount).toEqual(2);
135 it('should get corresponding data into Objects and capacity', () => {
136 expect(healthDataSpy).toHaveBeenCalled();
137 expect(component.objectCount).toEqual('290');
138 expect(component.totalPoolUsedBytes).toEqual(9338880);