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;
31 component.dataArray = [
45 component.labelsArray = ['Read', 'Write', 'Total'];
48 it('should create', () => {
49 expect(component).toBeTruthy();
52 it('should have a chart', () => {
53 const chartElement = fixture.debugElement.nativeElement.querySelector('canvas');
54 expect(chartElement).toBeTruthy();
57 it('should have three datasets', () => {
58 component.ngOnChanges({ dataArray: new SimpleChange(null, component.dataArray, false) });
59 expect(component.chartData.dataset[0].data).toBeDefined();
60 expect(component.chartData.dataset[1].data).toBeDefined();
61 expect(component.chartData.dataset[2].data).toBeDefined();
64 it('should set label', () => {
65 component.ngOnChanges({ dataArray: new SimpleChange(null, component.dataArray, false) });
66 expect(component.chartData.dataset[0].label).toEqual('Read');
67 expect(component.chartData.dataset[1].label).toEqual('Write');
68 expect(component.chartData.dataset[2].label).toEqual('Total');
71 it('should transform and update data', () => {
72 component.ngOnChanges({ dataArray: new SimpleChange(null, component.dataArray, false) });
73 expect(component.chartData.dataset[0].data).toEqual([
79 it('should set currentData to last value', () => {
80 component.ngOnChanges({ dataArray: new SimpleChange(null, component.dataArray, false) });
81 expect(component.currentChartData.dataset[0].currentData).toBe('130');
84 it('should keep data units consistency', () => {
85 // Timeout to be able to access chart object
87 fixture.detectChanges();
89 component.dataUnits = 'B';
90 component.ngOnChanges({ dataArray: new SimpleChange(null, component.dataArray, false) });
92 expect(component.currentDataUnits).toBe('KiB');
93 expect(component.chartDataUnits).toBe('KiB');