]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.spec.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / crushmap / crushmap.component.spec.ts
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { DebugElement } from '@angular/core';
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
4
5 import { of } from 'rxjs';
6
7 import { TreeModule } from 'ng2-tree';
8 import { TabsModule } from 'ngx-bootstrap/tabs';
9
10 import { configureTestBed } from '../../../../testing/unit-test-helper';
11 import { HealthService } from '../../../shared/api/health.service';
12 import { SharedModule } from '../../../shared/shared.module';
13 import { CrushmapComponent } from './crushmap.component';
14
15 describe('CrushmapComponent', () => {
16 let component: CrushmapComponent;
17 let fixture: ComponentFixture<CrushmapComponent>;
18 let debugElement: DebugElement;
19 configureTestBed({
20 imports: [HttpClientTestingModule, TreeModule, TabsModule.forRoot(), SharedModule],
21 declarations: [CrushmapComponent],
22 providers: [HealthService]
23 });
24
25 beforeEach(() => {
26 fixture = TestBed.createComponent(CrushmapComponent);
27 component = fixture.componentInstance;
28 debugElement = fixture.debugElement;
29 });
30
31 it('should create', () => {
32 expect(component).toBeTruthy();
33 });
34
35 it('should display right title', () => {
36 fixture.detectChanges();
37 const span = debugElement.nativeElement.querySelector('span');
38 expect(span.textContent).toBe('CRUSH map viewer');
39 });
40
41 describe('test tree', () => {
42 let healthService: HealthService;
43 const prepareGetHealth = (nodes: object[]) => {
44 spyOn(healthService, 'getFullHealth').and.returnValue(
45 of({ osd_map: { tree: { nodes: nodes } } })
46 );
47 fixture.detectChanges();
48 };
49
50 beforeEach(() => {
51 healthService = debugElement.injector.get(HealthService);
52 });
53
54 it('should display "No nodes!" if ceph tree nodes is empty array', () => {
55 prepareGetHealth([]);
56 expect(healthService.getFullHealth).toHaveBeenCalled();
57 expect(component.tree.value).toEqual('No nodes!');
58 });
59
60 describe('nodes not empty', () => {
61 beforeEach(() => {
62 prepareGetHealth([
63 { children: [-2], type: 'root', name: 'default', id: -1 },
64 { children: [1, 0, 2], type: 'host', name: 'my-host', id: -2 },
65 { status: 'up', type: 'osd', name: 'osd.0', id: 0 },
66 { status: 'down', type: 'osd', name: 'osd.1', id: 1 },
67 { status: 'up', type: 'osd', name: 'osd.2', id: 2 }
68 ]);
69 });
70
71 it('should have tree structure derived from a root', () => {
72 expect(component.tree.value).toBe('default (root)');
73 });
74
75 it('should have one host child with 3 osd children', () => {
76 expect(component.tree.children.length).toBe(1);
77 expect(component.tree.children[0].value).toBe('my-host (host)');
78 expect(component.tree.children[0].children.length).toBe(3);
79 });
80
81 it('should have 3 osds in orderd', () => {
82 expect(component.tree.children[0].children[0].value).toBe('osd.0 (osd)');
83 expect(component.tree.children[0].children[1].value).toBe('osd.1 (osd)');
84 expect(component.tree.children[0].children[2].value).toBe('osd.2 (osd)');
85 });
86 });
87 });
88 });