-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathDensityChart.test.js
65 lines (56 loc) · 1.86 KB
/
DensityChart.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
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import DensityChart from '../source/components/VisualTools/Chart/DensityChart';
const mockData = [
{ x: 10, y: 20 },
{ x: 15, y: 25 },
{ x: 20, y: 30 },
];
const mockFields = { x: 'x', y: 'y' };
const mockLayout = { width: 500, height: 500, currentCols: 1 };
const mockFilters = [];
const mockTitle = 'Test Density Chart';
const mockFilterAdded = [];
const mockId = 'test-density-chart';
describe('DensityChart 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,
}));
// Setting the mock on the HTMLDivElement prototype
Element.prototype.getBoundingClientRect = mockGetBoundingClientRect;
});
afterEach(() => {
// Restore the original implementation
jest.restoreAllMocks();
});
it('renders the chart, contents, axes', async () => {
const {container} = render(
<DensityChart
data={mockData}
fields={mockFields}
id={mockId}
title={mockTitle}
filterData={mockData}
filters={mockFilters}
filterAdded={mockFilterAdded}
layout={mockLayout}
/>
);
await waitFor(() => {
const chartElement = screen.getByRole('figure', { hidden: true });
expect(chartElement).toBeInTheDocument();
// console.log(chartElement.innerHTML)
const tickElements = chartElement.querySelectorAll('.tick');
const domainElements = chartElement.querySelectorAll('.domain');
expect(tickElements.length).toBeGreaterThan(0); // axes rendered
expect(domainElements.length).toBeGreaterThan(0); // body rendered
}), { timeout: 3000 };
});
});