1 import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
4 import { CssHelper } from '~/app/shared/classes/css-helper';
5 import { DimlessBinaryPerSecondPipe } from '~/app/shared/pipes/dimless-binary-per-second.pipe';
6 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
7 import { DimlessPipe } from '~/app/shared/pipes/dimless.pipe';
8 import { FormatterService } from '~/app/shared/services/formatter.service';
9 import { configureTestBed } from '~/testing/unit-test-helper';
10 import { DashboardAreaChartComponent } from './dashboard-area-chart.component';
12 describe('DashboardAreaChartComponent', () => {
13 let component: DashboardAreaChartComponent;
14 let fixture: ComponentFixture<DashboardAreaChartComponent>;
17 schemas: [NO_ERRORS_SCHEMA],
18 declarations: [DashboardAreaChartComponent],
22 DimlessBinaryPerSecondPipe,
29 fixture = TestBed.createComponent(DashboardAreaChartComponent);
30 component = fixture.componentInstance;
37 it('should create', () => {
38 expect(component).toBeTruthy();
41 it('should have a chart', () => {
42 const chartElement = fixture.debugElement.nativeElement.querySelector('canvas');
43 expect(chartElement).toBeTruthy();
46 it('should have two datasets', () => {
51 expect(component.chartData.dataset[0].data).toBeDefined();
52 expect(component.chartData.dataset[1].data).toBeDefined();
55 it('should set label', () => {
56 component.label = 'Write';
57 expect(component.label).toBe('Write');
60 it('should transform and update data', () => {
61 expect(component.chartData.dataset[0].data).toEqual([{ x: 0, y: 0 }]);
63 component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
65 expect(component.chartData.dataset[0].data).toEqual([
71 it('should set currentData to last value', () => {
72 component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
73 expect(component.currentData).toBe('130');
76 it('should keep data units consistency', () => {
77 // Timeout to be able to access chart object
79 fixture.detectChanges();
85 component.dataUnits = 'B';
86 component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
88 expect(component.currentDataUnits).toBe('KiB');
89 expect(component.chartDataUnits).toBe('KiB');