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