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 { CardComponent } from '~/app/shared/components/card/card.component';
15 import { CardRowComponent } from '~/app/shared/components/card-row/card-row.component';
17 describe('RgwOverviewDashboardComponent', () => {
18 let component: RgwOverviewDashboardComponent;
19 let fixture: ComponentFixture<RgwOverviewDashboardComponent>;
20 const daemon: RgwDaemon = {
22 service_map_id: '4803',
23 version: 'ceph version',
24 server_hostname: 'ceph',
26 zonegroup_name: 'zg1-realm1',
27 zone_name: 'zone1-zg1-realm1',
33 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
34 realms: ['realm2', 'realm1']
37 const zonegroupList = {
38 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
39 zonegroups: ['zg-1', 'zg-2', 'zg-3']
43 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
44 zones: ['zone4', 'zone5', 'zone6', 'zone7']
47 const bucketAndUserList = {
54 total_pool_bytes_used: 9338880
57 let listDaemonsSpy: jest.SpyInstance;
58 let listZonesSpy: jest.SpyInstance;
59 let listZonegroupsSpy: jest.SpyInstance;
60 let listRealmsSpy: jest.SpyInstance;
61 let listBucketsSpy: jest.SpyInstance;
62 let healthDataSpy: jest.SpyInstance;
64 beforeEach(async () => {
65 await TestBed.configureTestingModule({
67 RgwOverviewDashboardComponent,
72 imports: [HttpClientTestingModule]
73 }).compileComponents();
78 .spyOn(TestBed.inject(RgwDaemonService), 'list')
79 .mockReturnValue(of([daemon]));
81 .spyOn(TestBed.inject(RgwRealmService), 'list')
82 .mockReturnValue(of(realmList));
83 listZonegroupsSpy = jest
84 .spyOn(TestBed.inject(RgwZonegroupService), 'list')
85 .mockReturnValue(of(zonegroupList));
86 listZonesSpy = jest.spyOn(TestBed.inject(RgwZoneService), 'list').mockReturnValue(of(zoneList));
88 .spyOn(TestBed.inject(RgwBucketService), 'getTotalBucketsAndUsersLength')
89 .mockReturnValue(of(bucketAndUserList));
91 .spyOn(TestBed.inject(HealthService), 'getClusterCapacity')
92 .mockReturnValue(of(healthData));
93 fixture = TestBed.createComponent(RgwOverviewDashboardComponent);
94 component = fixture.componentInstance;
95 fixture.detectChanges();
98 it('should create', () => {
99 expect(component).toBeTruthy();
102 it('should render all cards', () => {
103 fixture.detectChanges();
104 const dashboardCards = fixture.debugElement.nativeElement.querySelectorAll('cd-card');
105 expect(dashboardCards.length).toBe(5);
108 it('should get corresponding data into Daemons', () => {
109 expect(listDaemonsSpy).toHaveBeenCalled();
110 expect(component.rgwDaemonCount).toEqual(1);
113 it('should get corresponding data into Realms', () => {
114 expect(listRealmsSpy).toHaveBeenCalled();
115 expect(component.rgwRealmCount).toEqual(2);
118 it('should get corresponding data into Zonegroups', () => {
119 expect(listZonegroupsSpy).toHaveBeenCalled();
120 expect(component.rgwZonegroupCount).toEqual(3);
123 it('should get corresponding data into Zones', () => {
124 expect(listZonesSpy).toHaveBeenCalled();
125 expect(component.rgwZoneCount).toEqual(4);
128 it('should get corresponding data into Buckets', () => {
129 expect(listBucketsSpy).toHaveBeenCalled();
130 expect(component.rgwBucketCount).toEqual(2);
131 expect(component.UserCount).toEqual(2);
134 it('should get corresponding data into Objects and capacity', () => {
135 expect(healthDataSpy).toHaveBeenCalled();
136 expect(component.objectCount).toEqual('290');
137 expect(component.totalPoolUsedBytes).toEqual(9338880);