1 import { NO_ERRORS_SCHEMA } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
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';
10 describe('HealthPieComponent', () => {
11 let component: HealthPieComponent;
12 let fixture: ComponentFixture<HealthPieComponent>;
15 schemas: [NO_ERRORS_SCHEMA],
16 declarations: [HealthPieComponent],
17 providers: [DimlessBinaryPipe, DimlessPipe, FormatterService]
21 fixture = TestBed.createComponent(HealthPieComponent);
22 component = fixture.componentInstance;
25 it('should create', () => {
26 expect(component).toBeTruthy();
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();
33 expect(component.chartConfig.dataset[0].borderWidth).toEqual(1);
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();
40 expect(component.chartConfig.dataset[0].borderWidth).toEqual(0);
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();
47 expect(component.chartConfig.dataset[0].borderWidth).toEqual(0);
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();
55 expect(component.chartConfig.dataset[0].data).toEqual(initialData);
58 describe('tooltip body', () => {
59 const tooltipBody = ['text: 10000'];
61 it('should return amount converted to appropriate units', () => {
62 component.isBytesData = false;
63 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text: 10 k');
65 component.isBytesData = true;
66 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text: 9.8 KiB');
69 it('should not return amount when showing label as tooltip', () => {
70 component.showLabelAsTooltip = true;
71 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text');