]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
2 | ||
9f95a23c | 3 | import { ChartsModule } from 'ng2-charts'; |
11fdf7f2 | 4 | |
f67539c2 | 5 | import { configureTestBed } from '~/testing/unit-test-helper'; |
11fdf7f2 TL |
6 | import { CephfsChartComponent } from './cephfs-chart.component'; |
7 | ||
8 | describe('CephfsChartComponent', () => { | |
9 | let component: CephfsChartComponent; | |
10 | let fixture: ComponentFixture<CephfsChartComponent>; | |
11 | ||
801d1391 TL |
12 | const counter = [ |
13 | [0, 15], | |
14 | [5, 15], | |
15 | [10, 25], | |
16 | [15, 50] | |
17 | ]; | |
eafe8130 | 18 | |
11fdf7f2 TL |
19 | configureTestBed({ |
20 | imports: [ChartsModule], | |
21 | declarations: [CephfsChartComponent] | |
22 | }); | |
23 | ||
24 | beforeEach(() => { | |
25 | fixture = TestBed.createComponent(CephfsChartComponent); | |
26 | component = fixture.componentInstance; | |
eafe8130 TL |
27 | component.mdsCounter = { |
28 | 'mds_server.handle_client_request': counter, | |
29 | 'mds_mem.ino': counter, | |
30 | name: 'a' | |
31 | }; | |
11fdf7f2 TL |
32 | fixture.detectChanges(); |
33 | }); | |
34 | ||
35 | it('should create', () => { | |
36 | expect(component).toBeTruthy(); | |
37 | }); | |
eafe8130 TL |
38 | |
39 | it('completed the chart', () => { | |
40 | const lhs = component.chart.datasets[0].data; | |
41 | expect(lhs.length).toBe(3); | |
42 | expect(lhs).toEqual([ | |
43 | { | |
44 | x: 5000, | |
45 | y: 15 | |
46 | }, | |
47 | { | |
48 | x: 10000, | |
49 | y: 25 | |
50 | }, | |
51 | { | |
52 | x: 15000, | |
53 | y: 50 | |
54 | } | |
55 | ]); | |
56 | ||
57 | const rhs = component.chart.datasets[1].data; | |
58 | expect(rhs.length).toBe(3); | |
59 | expect(rhs).toEqual([ | |
60 | { | |
61 | x: 5000, | |
62 | y: 0 | |
63 | }, | |
64 | { | |
65 | x: 10000, | |
9f95a23c | 66 | y: 10 |
eafe8130 TL |
67 | }, |
68 | { | |
69 | x: 15000, | |
9f95a23c | 70 | y: 25 |
eafe8130 TL |
71 | } |
72 | ]); | |
73 | }); | |
74 | ||
75 | it('should force angular to update the chart datasets array in order to update the graph', () => { | |
76 | const oldDatasets = component.chart.datasets; | |
77 | component.ngOnChanges(); | |
78 | expect(oldDatasets).toEqual(component.chart.datasets); | |
79 | expect(oldDatasets).not.toBe(component.chart.datasets); | |
80 | }); | |
11fdf7f2 | 81 | }); |