1 import { NO_ERRORS_SCHEMA } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
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';
11 describe('HealthPieComponent', () => {
12 let component: HealthPieComponent;
13 let fixture: ComponentFixture<HealthPieComponent>;
16 schemas: [NO_ERRORS_SCHEMA],
17 declarations: [HealthPieComponent],
18 providers: [DimlessBinaryPipe, DimlessPipe, FormatterService, CssHelper]
22 fixture = TestBed.createComponent(HealthPieComponent);
23 component = fixture.componentInstance;
26 it('should create', () => {
27 expect(component).toBeTruthy();
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();
34 expect(component.chartConfig.dataset[0].borderWidth).toEqual(1);
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();
41 expect(component.chartConfig.dataset[0].borderWidth).toEqual(0);
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();
48 expect(component.chartConfig.dataset[0].borderWidth).toEqual(0);
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();
56 expect(component.chartConfig.dataset[0].data).toEqual(initialData);
59 describe('tooltip body', () => {
60 const tooltipBody = ['text: 10000'];
62 it('should return amount converted to appropriate units', () => {
63 component.isBytesData = false;
64 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text: 10 k');
66 component.isBytesData = true;
67 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text: 9.8 KiB');
70 it('should not return amount when showing label as tooltip', () => {
71 component.showLabelAsTooltip = true;
72 expect(component['getChartTooltipBody'](tooltipBody)).toEqual('text');