1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { DebugElement } from '@angular/core';
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
5 import { TreeModule } from 'angular-tree-component';
6 import { TabsModule } from 'ngx-bootstrap/tabs';
7 import { of } from 'rxjs';
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';
14 describe('CrushmapComponent', () => {
15 let component: CrushmapComponent;
16 let fixture: ComponentFixture<CrushmapComponent>;
17 let debugElement: DebugElement;
19 imports: [HttpClientTestingModule, TreeModule.forRoot(), TabsModule.forRoot(), SharedModule],
20 declarations: [CrushmapComponent],
21 providers: [HealthService]
25 fixture = TestBed.createComponent(CrushmapComponent);
26 component = fixture.componentInstance;
27 debugElement = fixture.debugElement;
30 it('should create', () => {
31 expect(component).toBeTruthy();
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');
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 } } })
46 fixture.detectChanges();
50 healthService = debugElement.injector.get(HealthService);
53 it('should display "No nodes!" if ceph tree nodes is empty array', () => {
55 expect(healthService.getFullHealth).toHaveBeenCalled();
56 expect(component.nodes[0].name).toEqual('No nodes!');
59 describe('nodes not empty', () => {
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 }
73 it('should have two root nodes', () => {
74 expect(component.nodes).toEqual([
81 id: component.nodes[0].children[0].children[0].id,
88 id: component.nodes[0].children[0].id,
92 name: 'my-host-2 (host)'
95 id: component.nodes[0].id,
98 name: 'default-2 (root)'
105 id: component.nodes[1].children[0].children[0].id,
112 id: component.nodes[1].children[0].children[1].id,
119 id: component.nodes[1].children[0].children[2].id,
126 id: component.nodes[1].children[0].id,
130 name: 'my-host (host)'
133 id: component.nodes[1].id,
137 name: 'default (root)'