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 { CardComponent } from '../../dashboard-v3/card/card.component';
9 import { CardRowComponent } from '../../dashboard-v3/card-row/card-row.component';
10 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
11 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
12 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
13 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
14 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
15 import { RgwUserService } from '~/app/shared/api/rgw-user.service';
16 import { HealthService } from '~/app/shared/api/health.service';
18 describe('RgwOverviewDashboardComponent', () => {
19 let component: RgwOverviewDashboardComponent;
20 let fixture: ComponentFixture<RgwOverviewDashboardComponent>;
21 const daemon: RgwDaemon = {
23 service_map_id: '4803',
24 version: 'ceph version',
25 server_hostname: 'ceph',
27 zonegroup_name: 'zg1-realm1',
28 zone_name: 'zone1-zg1-realm1',
34 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
35 realms: ['realm2', 'realm1']
38 const zonegroupList = {
39 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
40 zonegroups: ['zg-1', 'zg-2', 'zg-3']
44 default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
45 zones: ['zone4', 'zone5', 'zone6', 'zone7']
117 total_objects: '290',
118 total_pool_bytes_used: 9338880
121 let listDaemonsSpy: jest.SpyInstance;
122 let listZonesSpy: jest.SpyInstance;
123 let listZonegroupsSpy: jest.SpyInstance;
124 let listRealmsSpy: jest.SpyInstance;
125 let listBucketsSpy: jest.SpyInstance;
126 let listUsersSpy: jest.SpyInstance;
127 let healthDataSpy: jest.SpyInstance;
129 beforeEach(async () => {
130 await TestBed.configureTestingModule({
132 RgwOverviewDashboardComponent,
137 imports: [HttpClientTestingModule]
138 }).compileComponents();
142 listDaemonsSpy = jest
143 .spyOn(TestBed.inject(RgwDaemonService), 'list')
144 .mockReturnValue(of([daemon]));
146 .spyOn(TestBed.inject(RgwRealmService), 'list')
147 .mockReturnValue(of(realmList));
148 listZonegroupsSpy = jest
149 .spyOn(TestBed.inject(RgwZonegroupService), 'list')
150 .mockReturnValue(of(zonegroupList));
151 listZonesSpy = jest.spyOn(TestBed.inject(RgwZoneService), 'list').mockReturnValue(of(zoneList));
152 listBucketsSpy = jest
153 .spyOn(TestBed.inject(RgwBucketService), 'list')
154 .mockReturnValue(of(bucketList));
155 listUsersSpy = jest.spyOn(TestBed.inject(RgwUserService), 'list').mockReturnValue(of(userList));
157 .spyOn(TestBed.inject(HealthService), 'getClusterCapacity')
158 .mockReturnValue(of(healthData));
159 fixture = TestBed.createComponent(RgwOverviewDashboardComponent);
160 component = fixture.componentInstance;
161 fixture.detectChanges();
164 it('should create', () => {
165 expect(component).toBeTruthy();
168 it('should render all cards', () => {
169 fixture.detectChanges();
170 const dashboardCards = fixture.debugElement.nativeElement.querySelectorAll('cd-card');
171 expect(dashboardCards.length).toBe(6);
174 it('should get corresponding data into Daemons', () => {
175 expect(listDaemonsSpy).toHaveBeenCalled();
176 expect(component.rgwDaemonCount).toEqual(1);
179 it('should get corresponding data into Realms', () => {
180 expect(listRealmsSpy).toHaveBeenCalled();
181 expect(component.rgwRealmCount).toEqual(2);
184 it('should get corresponding data into Zonegroups', () => {
185 expect(listZonegroupsSpy).toHaveBeenCalled();
186 expect(component.rgwZonegroupCount).toEqual(3);
189 it('should get corresponding data into Zones', () => {
190 expect(listZonesSpy).toHaveBeenCalled();
191 expect(component.rgwZoneCount).toEqual(4);
194 it('should get corresponding data into Buckets', () => {
195 expect(listBucketsSpy).toHaveBeenCalled();
196 expect(component.rgwBucketCount).toEqual(2);
199 it('should get corresponding data into Users', () => {
200 expect(listUsersSpy).toHaveBeenCalled();
201 expect(component.UserCount).toEqual(2);
204 it('should get corresponding data into Objects and capacity', () => {
205 expect(healthDataSpy).toHaveBeenCalled();
206 expect(component.objectCount).toEqual('290');
207 expect(component.totalPoolUsedBytes).toEqual(9338880);