]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/services.component.spec.ts
import 15.2.0 Octopus source
[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 { RouterTestingModule } from '@angular/router/testing';
4
5 import { of } from 'rxjs';
6
7 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
8 import { CoreModule } from '../../../core/core.module';
9 import { CephServiceService } from '../../../shared/api/ceph-service.service';
10 import { OrchestratorService } from '../../../shared/api/orchestrator.service';
11 import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
12 import { Permissions } from '../../../shared/models/permissions';
13 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
14 import { SharedModule } from '../../../shared/shared.module';
15 import { CephModule } from '../../ceph.module';
16 import { ServicesComponent } from './services.component';
17
18 describe('ServicesComponent', () => {
19 let component: ServicesComponent;
20 let fixture: ComponentFixture<ServicesComponent>;
21
22 const fakeAuthStorageService = {
23 getPermissions: () => {
24 return new Permissions({ hosts: ['read'] });
25 }
26 };
27
28 const services = [
29 {
30 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
31 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
32 service_name: 'osd',
33 size: 3,
34 running: 3,
35 last_refresh: '2020-02-25T04:33:26.465699'
36 },
37 {
38 container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
39 container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
40 service_name: 'crash',
41 size: 1,
42 running: 1,
43 last_refresh: '2020-02-25T04:33:26.465766'
44 }
45 ];
46
47 configureTestBed({
48 imports: [CephModule, CoreModule, SharedModule, HttpClientTestingModule, RouterTestingModule],
49 providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }, i18nProviders],
50 declarations: []
51 });
52
53 beforeEach(() => {
54 fixture = TestBed.createComponent(ServicesComponent);
55 component = fixture.componentInstance;
56 const orchService = TestBed.get(OrchestratorService);
57 const cephServiceService = TestBed.get(CephServiceService);
58 spyOn(orchService, 'status').and.returnValue(of({ available: true }));
59 spyOn(cephServiceService, 'list').and.returnValue(of(services));
60 fixture.detectChanges();
61 });
62
63 it('should create', () => {
64 expect(component).toBeTruthy();
65 });
66
67 it('should have columns that are sortable', () => {
68 expect(component.columns.every((column) => Boolean(column.prop))).toBeTruthy();
69 });
70
71 it('should return all services', () => {
72 component.getServices(new CdTableFetchDataContext(() => {}));
73 expect(component.services.length).toBe(2);
74 });
75 });