]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/crushmap/crushmap.component.spec.ts
import 15.2.0 Octopus source
[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 { TreeModule } from 'angular-tree-component';
6 import { TabsModule } from 'ngx-bootstrap/tabs';
7 import { of } from 'rxjs';
8
9 import { configureTestBed } from '../../../../testing/unit-test-helper';
10 import { HealthService } from '../../../shared/api/health.service';
11 import { SharedModule } from '../../../shared/shared.module';
12 import { CrushmapComponent } from './crushmap.component';
13
14 describe('CrushmapComponent', () => {
15 let component: CrushmapComponent;
16 let fixture: ComponentFixture<CrushmapComponent>;
17 let debugElement: DebugElement;
18 configureTestBed({
19 imports: [HttpClientTestingModule, TreeModule.forRoot(), TabsModule.forRoot(), SharedModule],
20 declarations: [CrushmapComponent],
21 providers: [HealthService]
22 });
23
24 beforeEach(() => {
25 fixture = TestBed.createComponent(CrushmapComponent);
26 component = fixture.componentInstance;
27 debugElement = fixture.debugElement;
28 });
29
30 it('should create', () => {
31 expect(component).toBeTruthy();
32 });
33
34 it('should display right title', () => {
35 fixture.detectChanges();
36 const span = debugElement.nativeElement.querySelector('.card-header');
37 expect(span.textContent).toBe('CRUSH map viewer');
38 });
39
40 describe('test tree', () => {
41 let healthService: HealthService;
42 const prepareGetHealth = (nodes: object[]) => {
43 spyOn(healthService, 'getFullHealth').and.returnValue(
44 of({ osd_map: { tree: { nodes: nodes } } })
45 );
46 fixture.detectChanges();
47 };
48
49 beforeEach(() => {
50 healthService = debugElement.injector.get(HealthService);
51 });
52
53 it('should display "No nodes!" if ceph tree nodes is empty array', () => {
54 prepareGetHealth([]);
55 expect(healthService.getFullHealth).toHaveBeenCalled();
56 expect(component.nodes[0].name).toEqual('No nodes!');
57 });
58
59 describe('nodes not empty', () => {
60 beforeEach(() => {
61 prepareGetHealth([
62 { children: [-2], type: 'root', name: 'default', id: -1 },
63 { children: [1, 0, 2], type: 'host', name: 'my-host', id: -2 },
64 { status: 'up', type: 'osd', name: 'osd.0', id: 0 },
65 { status: 'down', type: 'osd', name: 'osd.1', id: 1 },
66 { status: 'up', type: 'osd', name: 'osd.2', id: 2 },
67 { children: [-4], type: 'root', name: 'default-2', id: -3 },
68 { children: [4], type: 'host', name: 'my-host-2', id: -4 },
69 { status: 'up', type: 'osd', name: 'osd.0-2', id: 4 }
70 ]);
71 });
72
73 it('should have two root nodes', () => {
74 expect(component.nodes).toEqual([
75 {
76 cdId: -3,
77 children: [
78 {
79 children: [
80 {
81 id: component.nodes[0].children[0].children[0].id,
82 cdId: 4,
83 status: 'up',
84 type: 'osd',
85 name: 'osd.0-2 (osd)'
86 }
87 ],
88 id: component.nodes[0].children[0].id,
89 cdId: -4,
90 status: undefined,
91 type: 'host',
92 name: 'my-host-2 (host)'
93 }
94 ],
95 id: component.nodes[0].id,
96 status: undefined,
97 type: 'root',
98 name: 'default-2 (root)'
99 },
100 {
101 children: [
102 {
103 children: [
104 {
105 id: component.nodes[1].children[0].children[0].id,
106 cdId: 0,
107 status: 'up',
108 type: 'osd',
109 name: 'osd.0 (osd)'
110 },
111 {
112 id: component.nodes[1].children[0].children[1].id,
113 cdId: 1,
114 status: 'down',
115 type: 'osd',
116 name: 'osd.1 (osd)'
117 },
118 {
119 id: component.nodes[1].children[0].children[2].id,
120 cdId: 2,
121 status: 'up',
122 type: 'osd',
123 name: 'osd.2 (osd)'
124 }
125 ],
126 id: component.nodes[1].children[0].id,
127 cdId: -2,
128 status: undefined,
129 type: 'host',
130 name: 'my-host (host)'
131 }
132 ],
133 id: component.nodes[1].id,
134 cdId: -1,
135 status: undefined,
136 type: 'root',
137 name: 'default (root)'
138 }
139 ]);
140 });
141 });
142 });
143 });