1
+ import render from '@common-test/render' ;
2
+ import React from 'react' ;
1
3
import {
2
4
testMapConfiguration ,
3
5
testMapTableData ,
@@ -8,10 +10,16 @@ import MapBlock, {
8
10
import { LegendConfiguration } from '@common/modules/charts/types/legend' ;
9
11
import mapFullTable from '@common/modules/table-tool/utils/mapFullTable' ;
10
12
import { within } from '@testing-library/dom' ;
11
- import { render , screen , waitFor } from '@testing-library/react' ;
13
+ import { screen , waitFor } from '@testing-library/react' ;
12
14
import userEvent from '@testing-library/user-event' ;
15
+ import _tableBuilderService from '@common/services/tableBuilderService' ;
13
16
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
+ > ;
15
23
16
24
// EES-4902 react leaflet now uses ESM so unable to test this currently.
17
25
// It's stubbed out in the mocks folder.
@@ -35,6 +43,9 @@ describe('MapBlock', () => {
35
43
} ;
36
44
37
45
test ( 'renders legends and polygons correctly' , async ( ) => {
46
+ tableBuilderService . getGeoJson . mockResolvedValue (
47
+ testMapTableData . subjectMeta . locations ,
48
+ ) ;
38
49
render ( < MapBlock { ...testBlockProps } /> ) ;
39
50
40
51
// await waitFor(() => {
@@ -52,6 +63,12 @@ describe('MapBlock', () => {
52
63
// expect(paths[3]).toHaveAttribute('fill', '#003078');
53
64
// });
54
65
66
+ await waitFor ( ( ) => {
67
+ expect (
68
+ screen . getByLabelText ( '1. Select data to view' ) ,
69
+ ) . toBeInTheDocument ( ) ;
70
+ } ) ;
71
+
55
72
const legendItems = screen . getAllByTestId ( 'mapBlock-legend-item' ) ;
56
73
57
74
expect ( legendItems ) . toHaveLength ( 5 ) ;
@@ -72,6 +89,10 @@ describe('MapBlock', () => {
72
89
} ) ;
73
90
74
91
test ( 'renders legend groups correctly with custom 1 d.p decimal places' , async ( ) => {
92
+ tableBuilderService . getGeoJson . mockResolvedValue (
93
+ testMapTableData . subjectMeta . locations ,
94
+ ) ;
95
+
75
96
const fullTable = mapFullTable (
76
97
produce ( testMapTableData , draft => {
77
98
draft . results [ 0 ] . measures [ 'authorised-absence-rate' ] = '3.5123' ;
@@ -102,6 +123,10 @@ describe('MapBlock', () => {
102
123
} ) ;
103
124
104
125
test ( 'renders legend groups correctly with custom 3 d.p decimal places' , async ( ) => {
126
+ tableBuilderService . getGeoJson . mockResolvedValue (
127
+ testMapTableData . subjectMeta . locations ,
128
+ ) ;
129
+
105
130
const fullTable = mapFullTable (
106
131
produce ( testMapTableData , draft => {
107
132
draft . results [ 0 ] . measures [ 'authorised-absence-rate' ] = '3.5123' ;
@@ -132,6 +157,10 @@ describe('MapBlock', () => {
132
157
} ) ;
133
158
134
159
test ( 'changing selected data set changes legends and polygons' , async ( ) => {
160
+ tableBuilderService . getGeoJson . mockResolvedValue (
161
+ testMapTableData . subjectMeta . locations ,
162
+ ) ;
163
+
135
164
render ( < MapBlock { ...testBlockProps } /> ) ;
136
165
137
166
await waitFor ( async ( ) => {
@@ -174,6 +203,10 @@ describe('MapBlock', () => {
174
203
} ) ;
175
204
176
205
test . skip ( 'changing selected location focuses the correct polygon' , async ( ) => {
206
+ tableBuilderService . getGeoJson . mockResolvedValue (
207
+ testMapTableData . subjectMeta . locations ,
208
+ ) ;
209
+
177
210
const { container } = render ( < MapBlock { ...testBlockProps } /> ) ;
178
211
179
212
await waitFor ( ( ) => {
@@ -205,6 +238,10 @@ describe('MapBlock', () => {
205
238
} ) ;
206
239
207
240
test ( 'changing selected location renders its indicator tile' , async ( ) => {
241
+ tableBuilderService . getGeoJson . mockResolvedValue (
242
+ testMapTableData . subjectMeta . locations ,
243
+ ) ;
244
+
208
245
render ( < MapBlock { ...testBlockProps } /> ) ;
209
246
210
247
await waitFor ( ( ) => {
@@ -233,6 +270,10 @@ describe('MapBlock', () => {
233
270
} ) ;
234
271
235
272
test ( 'renders location indicator tiles correctly with custom decimal places' , async ( ) => {
273
+ tableBuilderService . getGeoJson . mockResolvedValue (
274
+ testMapTableData . subjectMeta . locations ,
275
+ ) ;
276
+
236
277
const fullTable = mapFullTable (
237
278
produce ( testMapTableData , draft => {
238
279
draft . results [ 0 ] . measures [ 'authorised-absence-rate' ] = '3.5123' ;
@@ -294,6 +335,10 @@ describe('MapBlock', () => {
294
335
} ) ;
295
336
296
337
test . skip ( 'resetting the map when select None Selected' , async ( ) => {
338
+ tableBuilderService . getGeoJson . mockResolvedValue (
339
+ testMapTableData . subjectMeta . locations ,
340
+ ) ;
341
+
297
342
const { container } = render ( < MapBlock { ...testBlockProps } /> ) ;
298
343
299
344
await waitFor ( ( ) => {
@@ -325,6 +370,10 @@ describe('MapBlock', () => {
325
370
} ) ;
326
371
327
372
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
+
328
377
const fullTable = mapFullTable (
329
378
produce ( testMapTableData , draft => {
330
379
draft . results [ 0 ] . measures [ 'authorised-absence-rate' ] =
0 commit comments