]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/services.component.spec.ts
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / services.component.spec.ts
CommitLineData
9f95a23c
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
e306af50 3import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
9f95a23c
TL
4import { RouterTestingModule } from '@angular/router/testing';
5
6import { of } from 'rxjs';
7
8import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
9import { CoreModule } from '../../../core/core.module';
10import { CephServiceService } from '../../../shared/api/ceph-service.service';
11import { OrchestratorService } from '../../../shared/api/orchestrator.service';
12import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
13import { Permissions } from '../../../shared/models/permissions';
14import { AuthStorageService } from '../../../shared/services/auth-storage.service';
15import { SharedModule } from '../../../shared/shared.module';
16import { CephModule } from '../../ceph.module';
17import { ServicesComponent } from './services.component';
18
19describe('ServicesComponent', () => {
20 let component: ServicesComponent;
21 let fixture: ComponentFixture<ServicesComponent>;
22
23 const fakeAuthStorageService = {
24 getPermissions: () => {
25 return new Permissions({ hosts: ['read'] });
26 }
27 };
28
29 const services = [
30 {
1911f103 31 service_type: 'osd',
9f95a23c 32 service_name: 'osd',
1911f103
TL
33 status: {
34 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
35 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
36 size: 3,
37 running: 3,
38 last_refresh: '2020-02-25T04:33:26.465699'
39 }
9f95a23c
TL
40 },
41 {
1911f103 42 service_type: 'crash',
9f95a23c 43 service_name: 'crash',
1911f103
TL
44 status: {
45 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
46 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
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,
61 RouterTestingModule
62 ],
9f95a23c
TL
63 providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }, i18nProviders],
64 declarations: []
65 });
66
67 beforeEach(() => {
68 fixture = TestBed.createComponent(ServicesComponent);
69 component = fixture.componentInstance;
70 const orchService = TestBed.get(OrchestratorService);
71 const cephServiceService = TestBed.get(CephServiceService);
72 spyOn(orchService, 'status').and.returnValue(of({ available: true }));
73 spyOn(cephServiceService, 'list').and.returnValue(of(services));
74 fixture.detectChanges();
75 });
76
77 it('should create', () => {
78 expect(component).toBeTruthy();
79 });
80
81 it('should have columns that are sortable', () => {
e306af50
TL
82 expect(
83 component.columns
84 .filter((column) => !(column.cellClass === 'cd-datatable-expand-collapse'))
85 .every((column) => Boolean(column.prop))
86 ).toBeTruthy();
9f95a23c
TL
87 });
88
89 it('should return all services', () => {
90 component.getServices(new CdTableFetchDataContext(() => {}));
91 expect(component.services.length).toBe(2);
92 });
93});