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