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