]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
ec71070544fa3fa6ceeb8673a29eb9dd2d7d87f6
[ceph.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.data = [
32       [1, '110'],
33       [3, '130']
34     ];
35   });
36
37   it('should create', () => {
38     expect(component).toBeTruthy();
39   });
40
41   it('should have a chart', () => {
42     const chartElement = fixture.debugElement.nativeElement.querySelector('canvas');
43     expect(chartElement).toBeTruthy();
44   });
45
46   it('should have two datasets', () => {
47     component.data2 = [
48       [2, '120'],
49       [4, '140']
50     ];
51     expect(component.chartData.dataset[0].data).toBeDefined();
52     expect(component.chartData.dataset[1].data).toBeDefined();
53   });
54
55   it('should set label', () => {
56     component.label = 'Write';
57     expect(component.label).toBe('Write');
58   });
59
60   it('should transform and update data', () => {
61     expect(component.chartData.dataset[0].data).toEqual([{ x: 0, y: 0 }]);
62
63     component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
64
65     expect(component.chartData.dataset[0].data).toEqual([
66       { x: 1000, y: 110 },
67       { x: 3000, y: 130 }
68     ]);
69   });
70
71   it('should set currentData to last value', () => {
72     component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
73     expect(component.currentData).toBe('130');
74   });
75
76   it('should keep data units consistency', () => {
77     // Timeout to be able to access chart object
78     setTimeout(() => {
79       fixture.detectChanges();
80
81       component.data = [
82         [1, '1100'],
83         [3, '1300']
84       ];
85       component.dataUnits = 'B';
86       component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
87
88       expect(component.currentDataUnits).toBe('KiB');
89       expect(component.chartDataUnits).toBe('KiB');
90     }, 1000);
91   });
92 });