]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health-pie/health-pie.component.spec.ts
783e56155d44f5711abee575ac1afe577344cd03
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / dashboard / health-pie / health-pie.component.spec.ts
1 import { NO_ERRORS_SCHEMA } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3
4 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
5 import { DimlessPipe } from '~/app/shared/pipes/dimless.pipe';
6 import { FormatterService } from '~/app/shared/services/formatter.service';
7 import { configureTestBed } from '~/testing/unit-test-helper';
8 import { HealthPieComponent } from './health-pie.component';
9
10 describe('HealthPieComponent', () => {
11 let component: HealthPieComponent;
12 let fixture: ComponentFixture<HealthPieComponent>;
13
14 configureTestBed({
15 schemas: [NO_ERRORS_SCHEMA],
16 declarations: [HealthPieComponent],
17 providers: [DimlessBinaryPipe, DimlessPipe, FormatterService]
18 });
19
20 beforeEach(() => {
21 fixture = TestBed.createComponent(HealthPieComponent);
22 component = fixture.componentInstance;
23 });
24
25 it('should create', () => {
26 expect(component).toBeTruthy();
27 });
28
29 it('Add slice border if there is more than one slice with numeric non zero value', () => {
30 component.chartConfig.dataset[0].data = [48, 0, 1, 0];
31 component.ngOnChanges();
32
33 expect(component.chartConfig.dataset[0].borderWidth).toEqual(1);
34 });
35
36 it('Remove slice border if there is only one slice with numeric non zero value', () => {
37 component.chartConfig.dataset[0].data = [48, 0, undefined, 0];
38 component.ngOnChanges();
39
40 expect(component.chartConfig.dataset[0].borderWidth).toEqual(0);
41 });
42
43 it('Remove slice border if there is no slice with numeric non zero value', () => {
44 component.chartConfig.dataset[0].data = [undefined, 0];
45 component.ngOnChanges();
46
47 expect(component.chartConfig.dataset[0].borderWidth).toEqual(0);
48 });
49
50 it('should not hide any slice if there is no user click on legend item', () => {
51 const initialData = [8, 15];
52 component.chartConfig.dataset[0].data = initialData;
53 component.ngOnChanges();
54
55 expect(component.chartConfig.dataset[0].data).toEqual(initialData);
56 });
57
58 describe('tooltip body', () => {
59 const tooltipBody = ['text: 10000'];
60
61 it('should return amount converted to appropriate units', () => {
62 component.isBytesData = false;
63 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text: 10 k');
64
65 component.isBytesData = true;
66 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text: 9.8 KiB');
67 });
68
69 it('should not return amount when showing label as tooltip', () => {
70 component.showLabelAsTooltip = true;
71 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text');
72 });
73 });
74 });