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