Skip to content

Commit 7a04a73

Browse files
committed
EES-5401 added test wrapper to allow queries
1 parent eaa57bf commit 7a04a73

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/explore-education-statistics-common/src/modules/charts/components/__tests__/ChartRenderer.test.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { testChartTableData } from '@common/modules/charts/components/__tests__/__data__/testChartData';
2-
import mapFullTable from '@common/modules/table-tool/utils/mapFullTable';
3-
import { render, screen } from '@testing-library/react';
1+
import render from '@common-test/render';
42
import React from 'react';
3+
import { testChartTableData } from '@common/modules/charts/components/__tests__/__data__/testChartData';
54
import ChartRenderer, {
65
ChartRendererProps,
76
} from '@common/modules/charts/components/ChartRenderer';
87
import { AxisConfiguration } from '@common/modules/charts/types/chart';
98
import { DataSet } from '@common/modules/charts/types/dataSet';
9+
import mapFullTable from '@common/modules/table-tool/utils/mapFullTable';
10+
import { screen } from '@testing-library/react';
1011

1112
jest.mock('recharts/lib/util/LogUtils');
1213

src/explore-education-statistics-common/src/modules/charts/components/__tests__/MapBlock.test.tsx

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import render from '@common-test/render';
2+
import React from 'react';
13
import {
24
testMapConfiguration,
35
testMapTableData,
@@ -8,10 +10,16 @@ import MapBlock, {
810
import { LegendConfiguration } from '@common/modules/charts/types/legend';
911
import mapFullTable from '@common/modules/table-tool/utils/mapFullTable';
1012
import { within } from '@testing-library/dom';
11-
import { render, screen, waitFor } from '@testing-library/react';
13+
import { screen, waitFor } from '@testing-library/react';
1214
import userEvent from '@testing-library/user-event';
15+
import _tableBuilderService from '@common/services/tableBuilderService';
1316
import { produce } from 'immer';
14-
import React from 'react';
17+
18+
jest.mock('@common/services/tableBuilderService');
19+
20+
const tableBuilderService = _tableBuilderService as jest.Mocked<
21+
typeof _tableBuilderService
22+
>;
1523

1624
// EES-4902 react leaflet now uses ESM so unable to test this currently.
1725
// It's stubbed out in the mocks folder.
@@ -35,6 +43,9 @@ describe('MapBlock', () => {
3543
};
3644

3745
test('renders legends and polygons correctly', async () => {
46+
tableBuilderService.getGeoJson.mockResolvedValue(
47+
testMapTableData.subjectMeta.locations,
48+
);
3849
render(<MapBlock {...testBlockProps} />);
3950

4051
// await waitFor(() => {
@@ -52,6 +63,12 @@ describe('MapBlock', () => {
5263
// expect(paths[3]).toHaveAttribute('fill', '#003078');
5364
// });
5465

66+
await waitFor(() => {
67+
expect(
68+
screen.getByLabelText('1. Select data to view'),
69+
).toBeInTheDocument();
70+
});
71+
5572
const legendItems = screen.getAllByTestId('mapBlock-legend-item');
5673

5774
expect(legendItems).toHaveLength(5);
@@ -72,6 +89,10 @@ describe('MapBlock', () => {
7289
});
7390

7491
test('renders legend groups correctly with custom 1 d.p decimal places', async () => {
92+
tableBuilderService.getGeoJson.mockResolvedValue(
93+
testMapTableData.subjectMeta.locations,
94+
);
95+
7596
const fullTable = mapFullTable(
7697
produce(testMapTableData, draft => {
7798
draft.results[0].measures['authorised-absence-rate'] = '3.5123';
@@ -102,6 +123,10 @@ describe('MapBlock', () => {
102123
});
103124

104125
test('renders legend groups correctly with custom 3 d.p decimal places', async () => {
126+
tableBuilderService.getGeoJson.mockResolvedValue(
127+
testMapTableData.subjectMeta.locations,
128+
);
129+
105130
const fullTable = mapFullTable(
106131
produce(testMapTableData, draft => {
107132
draft.results[0].measures['authorised-absence-rate'] = '3.5123';
@@ -132,6 +157,10 @@ describe('MapBlock', () => {
132157
});
133158

134159
test('changing selected data set changes legends and polygons', async () => {
160+
tableBuilderService.getGeoJson.mockResolvedValue(
161+
testMapTableData.subjectMeta.locations,
162+
);
163+
135164
render(<MapBlock {...testBlockProps} />);
136165

137166
await waitFor(async () => {
@@ -174,6 +203,10 @@ describe('MapBlock', () => {
174203
});
175204

176205
test.skip('changing selected location focuses the correct polygon', async () => {
206+
tableBuilderService.getGeoJson.mockResolvedValue(
207+
testMapTableData.subjectMeta.locations,
208+
);
209+
177210
const { container } = render(<MapBlock {...testBlockProps} />);
178211

179212
await waitFor(() => {
@@ -205,6 +238,10 @@ describe('MapBlock', () => {
205238
});
206239

207240
test('changing selected location renders its indicator tile', async () => {
241+
tableBuilderService.getGeoJson.mockResolvedValue(
242+
testMapTableData.subjectMeta.locations,
243+
);
244+
208245
render(<MapBlock {...testBlockProps} />);
209246

210247
await waitFor(() => {
@@ -233,6 +270,10 @@ describe('MapBlock', () => {
233270
});
234271

235272
test('renders location indicator tiles correctly with custom decimal places', async () => {
273+
tableBuilderService.getGeoJson.mockResolvedValue(
274+
testMapTableData.subjectMeta.locations,
275+
);
276+
236277
const fullTable = mapFullTable(
237278
produce(testMapTableData, draft => {
238279
draft.results[0].measures['authorised-absence-rate'] = '3.5123';
@@ -294,6 +335,10 @@ describe('MapBlock', () => {
294335
});
295336

296337
test.skip('resetting the map when select None Selected', async () => {
338+
tableBuilderService.getGeoJson.mockResolvedValue(
339+
testMapTableData.subjectMeta.locations,
340+
);
341+
297342
const { container } = render(<MapBlock {...testBlockProps} />);
298343

299344
await waitFor(() => {
@@ -325,6 +370,10 @@ describe('MapBlock', () => {
325370
});
326371

327372
test('ensure values with decimal places go are assigned the correct colour when the legend values are set to 0 decimal places', async () => {
373+
tableBuilderService.getGeoJson.mockResolvedValue(
374+
testMapTableData.subjectMeta.locations,
375+
);
376+
328377
const fullTable = mapFullTable(
329378
produce(testMapTableData, draft => {
330379
draft.results[0].measures['authorised-absence-rate'] =

0 commit comments

Comments
 (0)