]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
80cdb1ea23692f9b93a497d29ec6a05c3a4e974b
[ceph-ci.git] /
1 import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3
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';
11
12 describe('DashboardAreaChartComponent', () => {
13   let component: DashboardAreaChartComponent;
14   let fixture: ComponentFixture<DashboardAreaChartComponent>;
15
16   configureTestBed({
17     schemas: [NO_ERRORS_SCHEMA],
18     declarations: [DashboardAreaChartComponent],
19     providers: [
20       CssHelper,
21       DimlessBinaryPipe,
22       DimlessBinaryPerSecondPipe,
23       DimlessPipe,
24       FormatterService
25     ]
26   });
27
28   beforeEach(() => {
29     fixture = TestBed.createComponent(DashboardAreaChartComponent);
30     component = fixture.componentInstance;
31     component.dataArray = [
32       [
33         [1, '110'],
34         [3, '130']
35       ],
36       [
37         [2, '120'],
38         [4, '140']
39       ],
40       [
41         [5, '150'],
42         [6, '160']
43       ]
44     ];
45     component.labelsArray = ['Read', 'Write', 'Total'];
46   });
47
48   it('should create', () => {
49     expect(component).toBeTruthy();
50   });
51
52   it('should have a chart', () => {
53     const chartElement = fixture.debugElement.nativeElement.querySelector('canvas');
54     expect(chartElement).toBeTruthy();
55   });
56
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();
62   });
63
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');
69   });
70
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([
74       { x: 1000, y: 110 },
75       { x: 3000, y: 130 }
76     ]);
77   });
78
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');
82   });
83
84   it('should keep data units consistency', () => {
85     // Timeout to be able to access chart object
86     setTimeout(() => {
87       fixture.detectChanges();
88
89       component.dataUnits = 'B';
90       component.ngOnChanges({ dataArray: new SimpleChange(null, component.dataArray, false) });
91
92       expect(component.currentDataUnits).toBe('KiB');
93       expect(component.chartDataUnits).toBe('KiB');
94     }, 1000);
95   });
96 });