1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { DebugElement, Type } from '@angular/core';
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
5 import { TreeModule } from '@circlon/angular-tree-component';
6 import { of } from 'rxjs';
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';
13 describe('CrushmapComponent', () => {
14 let component: CrushmapComponent;
15 let fixture: ComponentFixture<CrushmapComponent>;
16 let debugElement: DebugElement;
18 imports: [HttpClientTestingModule, TreeModule, SharedModule],
19 declarations: [CrushmapComponent],
20 providers: [HealthService]
24 fixture = TestBed.createComponent(CrushmapComponent);
25 component = fixture.componentInstance;
26 debugElement = fixture.debugElement;
29 it('should create', () => {
30 expect(component).toBeTruthy();
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');
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 } } })
45 fixture.detectChanges();
49 healthService = debugElement.injector.get(HealthService as Type<HealthService>);
52 it('should display "No nodes!" if ceph tree nodes is empty array', () => {
54 expect(healthService.getFullHealth).toHaveBeenCalled();
55 expect(component.nodes[0].name).toEqual('No nodes!');
58 describe('nodes not empty', () => {
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 }
72 it('should have two root nodes', () => {
73 expect(component.nodes).toEqual([
80 id: component.nodes[0].children[0].children[0].id,
87 id: component.nodes[0].children[0].id,
91 name: 'my-host-2 (host)'
94 id: component.nodes[0].id,
97 name: 'default-2 (root)'
104 id: component.nodes[1].children[0].children[0].id,
111 id: component.nodes[1].children[0].children[1].id,
118 id: component.nodes[1].children[0].children[2].id,
125 id: component.nodes[1].children[0].id,
129 name: 'my-host (host)'
132 id: component.nodes[1].id,
136 name: 'default (root)'