1 import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
4 import { configureTestBed } from '../../../../testing/unit-test-helper';
5 import { DimlessBinaryPipe } from '../../pipes/dimless-binary.pipe';
6 import { FormatterService } from '../../services/formatter.service';
7 import { SparklineComponent } from './sparkline.component';
9 describe('SparklineComponent', () => {
10 let component: SparklineComponent;
11 let fixture: ComponentFixture<SparklineComponent>;
14 declarations: [SparklineComponent],
15 schemas: [NO_ERRORS_SCHEMA],
17 providers: [DimlessBinaryPipe, FormatterService]
21 fixture = TestBed.createComponent(SparklineComponent);
22 component = fixture.componentInstance;
23 fixture.detectChanges();
26 it('should create', () => {
27 expect(component).toBeTruthy();
28 expect(component.options.tooltips.custom).toBeDefined();
31 it('should update', () => {
32 expect(component.datasets).toEqual([{ data: [] }]);
33 expect(component.labels.length).toBe(0);
35 component.data = [11, 22, 33];
36 component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
38 expect(component.datasets).toEqual([{ data: [11, 22, 33] }]);
39 expect(component.labels.length).toBe(3);
42 it('should not transform the label, if not isBinary', () => {
43 component.isBinary = false;
44 const result = component.options.tooltips.callbacks.label({ yLabel: 1024 });
45 expect(result).toBe(1024);
48 it('should transform the label, if isBinary', () => {
49 component.isBinary = true;
50 const result = component.options.tooltips.callbacks.label({ yLabel: 1024 });
51 expect(result).toBe('1 KiB');