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