-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathParallelCoordinates.test.js
75 lines (66 loc) · 2.19 KB
/
ParallelCoordinates.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import ParallelCoordinates from '../source/components/VisualTools/Chart/ParallelCoordinates';
const mockData = [
{ dimension1: 10, dimension2: 20, dimension3: 30 },
{ dimension1: 15, dimension2: 25, dimension3: 35 },
{ dimension1: 20, dimension2: 30, dimension3: 40 },
{ dimension1: 25, dimension2: 35, dimension3: 45 },
{ dimension1: 30, dimension2: 40, dimension3: 50 },
];
const mockFields = {
y: ['dimension1', 'dimension2', 'dimension3'],
};
const mockLayout = { width: 500, currentCols: 1 };
const mockFilters = [];
const mockTitle = 'Test Parallel Coordinates Chart';
const mockId = 'test-parallel-coords-chart';
describe('ParallelCoordinates Vis Component', () => {
beforeEach(() => {
// Mocking the getBoundingClientRect method, which otherwise breaks these tests
const mockGetBoundingClientRect = jest.fn(() => ({
width: 500,
height: 300,
top: 0,
right: 500,
bottom: 300,
left: 0,
}));
// this feels pretty bad. improve this test.
const mockGetContext = jest.fn().mockReturnValue({
strokeStyle: '',
clearRect: console.log,
beginPath: console.log,
moveTo: console.log,
lineTo: console.log,
stroke: console.log,
});
Element.prototype.getBoundingClientRect = mockGetBoundingClientRect;
HTMLCanvasElement.prototype.getContext = mockGetContext;
});
afterEach(() => {
// Restore the original implementation
jest.restoreAllMocks();
});
it('renders', async () => {
render(
<ParallelCoordinates
data={mockData}
fields={mockFields}
id={mockId}
title={mockTitle}
filterData={mockData}
filters={mockFilters}
filterAdded={[]}
layout={mockLayout}
/>
);
await waitFor(() => {
const chartElement = screen.getByRole('figure', { hidden: true });
expect(chartElement).toBeInTheDocument();
// console.log(chartElement.innerHTML)
const canvasElements = chartElement.querySelectorAll('canvas');
expect(canvasElements.length).toBeGreaterThan(0); // body rendered
}), { timeout: 3000 };
});
});