]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
aae0d74924a1f2c3339e36262f1d7fc4c8727a05
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2
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';
16
17 describe('RgwOverviewDashboardComponent', () => {
18   let component: RgwOverviewDashboardComponent;
19   let fixture: ComponentFixture<RgwOverviewDashboardComponent>;
20   const daemon: RgwDaemon = {
21     id: '8000',
22     service_map_id: '4803',
23     version: 'ceph version',
24     server_hostname: 'ceph',
25     realm_name: 'realm1',
26     zonegroup_name: 'zg1-realm1',
27     zone_name: 'zone1-zg1-realm1',
28     default: true,
29     port: 80
30   };
31
32   const realmList = {
33     default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
34     realms: ['realm2', 'realm1']
35   };
36
37   const zonegroupList = {
38     default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
39     zonegroups: ['zg-1', 'zg-2', 'zg-3']
40   };
41
42   const zoneList = {
43     default_info: '20f61d29-7e45-4418-8e19-b7e962e4860b',
44     zones: ['zone4', 'zone5', 'zone6', 'zone7']
45   };
46
47   const bucketAndUserList = {
48     buckets_count: 2,
49     users_count: 2
50   };
51
52   const healthData = {
53     total_objects: '290',
54     total_pool_bytes_used: 9338880
55   };
56
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;
63
64   beforeEach(async () => {
65     await TestBed.configureTestingModule({
66       declarations: [
67         RgwOverviewDashboardComponent,
68         CardComponent,
69         CardRowComponent,
70         DimlessBinaryPipe
71       ],
72       imports: [HttpClientTestingModule]
73     }).compileComponents();
74   });
75
76   beforeEach(() => {
77     listDaemonsSpy = jest
78       .spyOn(TestBed.inject(RgwDaemonService), 'list')
79       .mockReturnValue(of([daemon]));
80     listRealmsSpy = jest
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));
87     listBucketsSpy = jest
88       .spyOn(TestBed.inject(RgwBucketService), 'getTotalBucketsAndUsersLength')
89       .mockReturnValue(of(bucketAndUserList));
90     healthDataSpy = jest
91       .spyOn(TestBed.inject(HealthService), 'getClusterCapacity')
92       .mockReturnValue(of(healthData));
93     fixture = TestBed.createComponent(RgwOverviewDashboardComponent);
94     component = fixture.componentInstance;
95     fixture.detectChanges();
96   });
97
98   it('should create', () => {
99     expect(component).toBeTruthy();
100   });
101
102   it('should render all cards', () => {
103     fixture.detectChanges();
104     const dashboardCards = fixture.debugElement.nativeElement.querySelectorAll('cd-card');
105     expect(dashboardCards.length).toBe(5);
106   });
107
108   it('should get corresponding data into Daemons', () => {
109     expect(listDaemonsSpy).toHaveBeenCalled();
110     expect(component.rgwDaemonCount).toEqual(1);
111   });
112
113   it('should get corresponding data into Realms', () => {
114     expect(listRealmsSpy).toHaveBeenCalled();
115     expect(component.rgwRealmCount).toEqual(2);
116   });
117
118   it('should get corresponding data into Zonegroups', () => {
119     expect(listZonegroupsSpy).toHaveBeenCalled();
120     expect(component.rgwZonegroupCount).toEqual(3);
121   });
122
123   it('should get corresponding data into Zones', () => {
124     expect(listZonesSpy).toHaveBeenCalled();
125     expect(component.rgwZoneCount).toEqual(4);
126   });
127
128   it('should get corresponding data into Buckets', () => {
129     expect(listBucketsSpy).toHaveBeenCalled();
130     expect(component.rgwBucketCount).toEqual(2);
131     expect(component.UserCount).toEqual(2);
132   });
133
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);
138   });
139 });