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