]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { NO_ERRORS_SCHEMA } from '@angular/core'; |
2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
3 | ||
4 | import { configureTestBed } from '../../../../testing/unit-test-helper'; | |
5 | import { DimlessBinaryPipe } from '../../../shared/pipes/dimless-binary.pipe'; | |
81eedcae | 6 | import { DimlessPipe } from '../../../shared/pipes/dimless.pipe'; |
11fdf7f2 TL |
7 | import { FormatterService } from '../../../shared/services/formatter.service'; |
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], | |
81eedcae | 17 | providers: [DimlessBinaryPipe, DimlessPipe, FormatterService] |
11fdf7f2 TL |
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 | ||
11fdf7f2 TL |
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 | }); | |
81eedcae | 57 | |
f91f0fd5 TL |
58 | it('should set colors from css variables', () => { |
59 | const cssVar = '--my-color'; | |
60 | const cssVarColor = '#73c5c5'; | |
61 | component['getCssVar'] = (name: string) => (name === cssVar ? cssVarColor : ''); | |
62 | component.chartConfig.colors[0].backgroundColor = [cssVar, '#ffffff']; | |
63 | fixture.detectChanges(); | |
64 | ||
65 | expect(component.chartConfig.colors[0].backgroundColor).toEqual([cssVarColor, '#ffffff']); | |
66 | }); | |
67 | ||
81eedcae TL |
68 | describe('tooltip body', () => { |
69 | const tooltipBody = ['text: 10000']; | |
70 | ||
71 | it('should return amount converted to appropriate units', () => { | |
72 | component.isBytesData = false; | |
73 | expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text: 10 k'); | |
74 | ||
75 | component.isBytesData = true; | |
76 | expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text: 9.8 KiB'); | |
77 | }); | |
78 | ||
79 | it('should not return amount when showing label as tooltip', () => { | |
80 | component.showLabelAsTooltip = true; | |
81 | expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text'); | |
82 | }); | |
83 | }); | |
11fdf7f2 | 84 | }); |