]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/services.component.spec.ts
import ceph quincy 17.2.6
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / services.component.spec.ts
CommitLineData
39ae355f 1import { HttpHeaders } from '@angular/common/http';
9f95a23c
TL
2import { HttpClientTestingModule } from '@angular/common/http/testing';
3import { ComponentFixture, TestBed } from '@angular/core/testing';
e306af50 4import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
9f95a23c
TL
5import { RouterTestingModule } from '@angular/router/testing';
6
adb31ebb 7import { ToastrModule } from 'ngx-toastr';
9f95a23c
TL
8import { of } from 'rxjs';
9
f67539c2
TL
10import { CephModule } from '~/app/ceph/ceph.module';
11import { CoreModule } from '~/app/core/core.module';
12import { CephServiceService } from '~/app/shared/api/ceph-service.service';
13import { OrchestratorService } from '~/app/shared/api/orchestrator.service';
39ae355f 14import { PaginateObservable } from '~/app/shared/api/paginate.model';
f67539c2
TL
15import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
16import { Permissions } from '~/app/shared/models/permissions';
17import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
18import { SharedModule } from '~/app/shared/shared.module';
19import { configureTestBed } from '~/testing/unit-test-helper';
9f95a23c
TL
20import { ServicesComponent } from './services.component';
21
22describe('ServicesComponent', () => {
23 let component: ServicesComponent;
24 let fixture: ComponentFixture<ServicesComponent>;
39ae355f 25 let headers: HttpHeaders;
9f95a23c
TL
26
27 const fakeAuthStorageService = {
28 getPermissions: () => {
29 return new Permissions({ hosts: ['read'] });
30 }
31 };
32
33 const services = [
34 {
1911f103 35 service_type: 'osd',
9f95a23c 36 service_name: 'osd',
1911f103 37 status: {
1911f103
TL
38 size: 3,
39 running: 3,
40 last_refresh: '2020-02-25T04:33:26.465699'
41 }
9f95a23c
TL
42 },
43 {
1911f103 44 service_type: 'crash',
9f95a23c 45 service_name: 'crash',
1911f103 46 status: {
1911f103
TL
47 size: 1,
48 running: 1,
49 last_refresh: '2020-02-25T04:33:26.465766'
50 }
9f95a23c
TL
51 }
52 ];
53
54 configureTestBed({
e306af50
TL
55 imports: [
56 BrowserAnimationsModule,
57 CephModule,
58 CoreModule,
59 SharedModule,
60 HttpClientTestingModule,
adb31ebb
TL
61 RouterTestingModule,
62 ToastrModule.forRoot()
e306af50 63 ],
f67539c2 64 providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }]
9f95a23c
TL
65 });
66
67 beforeEach(() => {
68 fixture = TestBed.createComponent(ServicesComponent);
69 component = fixture.componentInstance;
f67539c2
TL
70 const orchService = TestBed.inject(OrchestratorService);
71 const cephServiceService = TestBed.inject(CephServiceService);
9f95a23c 72 spyOn(orchService, 'status').and.returnValue(of({ available: true }));
39ae355f
TL
73 headers = new HttpHeaders().set('X-Total-Count', '2');
74 const paginate_obs = new PaginateObservable<any>(of({ body: services, headers: headers }));
75
76 spyOn(cephServiceService, 'list').and.returnValue(paginate_obs);
9f95a23c
TL
77 });
78
79 it('should create', () => {
80 expect(component).toBeTruthy();
81 });
82
83 it('should have columns that are sortable', () => {
e306af50
TL
84 expect(
85 component.columns
adb31ebb 86 // Filter the 'Expand/Collapse Row' column.
e306af50 87 .filter((column) => !(column.cellClass === 'cd-datatable-expand-collapse'))
adb31ebb
TL
88 // Filter the 'Placement' column.
89 .filter((column) => !(column.prop === ''))
e306af50
TL
90 .every((column) => Boolean(column.prop))
91 ).toBeTruthy();
9f95a23c
TL
92 });
93
94 it('should return all services', () => {
39ae355f
TL
95 const context = new CdTableFetchDataContext(() => undefined);
96 context.pageInfo.offset = 0;
97 context.pageInfo.limit = -1;
98 component.getServices(context);
9f95a23c
TL
99 expect(component.services.length).toBe(2);
100 });
adb31ebb
TL
101
102 it('should not display doc panel if orchestrator is available', () => {
103 expect(component.showDocPanel).toBeFalsy();
104 });
9f95a23c 105});