@@ -21,10 +21,6 @@ const tableBuilderService = _tableBuilderService as jest.Mocked<
21
21
typeof _tableBuilderService
22
22
> ;
23
23
24
- // EES-4902 react leaflet now uses ESM so unable to test this currently.
25
- // It's stubbed out in the mocks folder.
26
- // Tests are skipped or partially commented out when they
27
- // are testing the maps directly.
28
24
describe ( 'MapBlock' , ( ) => {
29
25
const testFullTable = mapFullTable ( testMapTableData ) ;
30
26
const testBlockProps : MapBlockProps = {
@@ -43,29 +39,28 @@ describe('MapBlock', () => {
43
39
tableBuilderService . getLocationGeoJson . mockResolvedValue (
44
40
testMapTableData . subjectMeta . locations ,
45
41
) ;
46
- render ( < MapBlock { ...testBlockProps } /> ) ;
47
42
48
- // await waitFor(() => {
49
- // const paths = container.querySelectorAll<HTMLElement>(
50
- // '.leaflet-container svg:not(.leaflet-attribution-flag) path',
51
- // );
43
+ const { container } = render ( < MapBlock { ...testBlockProps } /> ) ;
52
44
53
- // expect(paths).toHaveLength(4);
45
+ await waitFor ( ( ) => {
46
+ const paths = container . querySelectorAll < HTMLElement > (
47
+ '.leaflet-container svg:not(.leaflet-attribution-flag) path' ,
48
+ ) ;
54
49
55
- // // Location polygons
56
- // expect(paths[0]).toHaveAttribute('fill', 'rgba(145, 161, 201, 1)');
57
- // expect(paths[1]).toHaveAttribute('fill', 'rgba(218, 224, 237, 1)');
58
- // expect(paths[2]).toHaveAttribute('fill', 'rgba(71, 99, 165, 1)');
59
- // // UK polygon
60
- // expect(paths[3]).toHaveAttribute('fill', '#003078');
61
- // });
50
+ expect ( paths ) . toHaveLength ( 4 ) ;
62
51
63
- await waitFor ( ( ) => {
64
- expect (
65
- screen . getByLabelText ( '1. Select data to view' ) ,
66
- ) . toBeInTheDocument ( ) ;
52
+ // Location polygons
53
+ expect ( paths [ 0 ] ) . toHaveAttribute ( 'fill' , 'rgba(145, 161, 201, 1)' ) ;
54
+ expect ( paths [ 1 ] ) . toHaveAttribute ( 'fill' , 'rgba(218, 224, 237, 1)' ) ;
55
+ expect ( paths [ 2 ] ) . toHaveAttribute ( 'fill' , 'rgba(71, 99, 165, 1)' ) ;
56
+ // UK polygon
57
+ expect ( paths [ 3 ] ) . toHaveAttribute ( 'fill' , '#003078' ) ;
67
58
} ) ;
68
59
60
+ expect (
61
+ await screen . findByLabelText ( '1. Select data to view' ) ,
62
+ ) . toBeInTheDocument ( ) ;
63
+
69
64
const legendItems = screen . getAllByTestId ( 'mapBlock-legend-item' ) ;
70
65
71
66
expect ( legendItems ) . toHaveLength ( 5 ) ;
@@ -199,7 +194,7 @@ describe('MapBlock', () => {
199
194
expect ( legendColours [ 4 ] . style . backgroundColor ) . toBe ( 'rgb(245, 164, 80)' ) ;
200
195
} ) ;
201
196
202
- test . skip ( 'changing selected location focuses the correct polygon' , async ( ) => {
197
+ test ( 'changing selected location focuses the correct polygon' , async ( ) => {
203
198
tableBuilderService . getLocationGeoJson . mockResolvedValue (
204
199
testMapTableData . subjectMeta . locations ,
205
200
) ;
@@ -221,17 +216,18 @@ describe('MapBlock', () => {
221
216
expect ( group1Options [ 0 ] ) . toHaveTextContent ( 'Leeds' ) ;
222
217
223
218
await userEvent . selectOptions ( select , group1Options [ 0 ] ) ;
219
+
224
220
const paths = container . querySelectorAll < HTMLElement > (
225
- '.leaflet-container svg:not(.leaflet-attribution-flag) path' ,
221
+ '.leaflet-container svg:not(.leaflet-attribution-flag) path.leaflet-interactive ' ,
226
222
) ;
227
223
228
- expect ( paths ) . toHaveLength ( 4 ) ;
224
+ expect ( paths ) . toHaveLength ( 3 ) ;
229
225
230
226
// Location polygons
231
227
// selected polygon has a wider border.
232
- expect ( paths [ 0 ] ) . toHaveAttribute ( 'stroke-width' , '3 ' ) ;
228
+ expect ( paths [ 0 ] ) . toHaveAttribute ( 'stroke-width' , '1 ' ) ;
233
229
expect ( paths [ 1 ] ) . toHaveAttribute ( 'stroke-width' , '1' ) ;
234
- expect ( paths [ 2 ] ) . toHaveAttribute ( 'stroke-width' , '1 ' ) ;
230
+ expect ( paths [ 2 ] ) . toHaveAttribute ( 'stroke-width' , '3 ' ) ;
235
231
} ) ;
236
232
237
233
test ( 'changing selected location renders its indicator tile' , async ( ) => {
@@ -331,7 +327,7 @@ describe('MapBlock', () => {
331
327
) . toHaveTextContent ( '4.01%' ) ;
332
328
} ) ;
333
329
334
- test . skip ( 'resetting the map when select None Selected ' , async ( ) => {
330
+ test ( 'resetting the map when no location selected ' , async ( ) => {
335
331
tableBuilderService . getLocationGeoJson . mockResolvedValue (
336
332
testMapTableData . subjectMeta . locations ,
337
333
) ;
@@ -353,17 +349,23 @@ describe('MapBlock', () => {
353
349
await userEvent . selectOptions ( select , group1Options [ 0 ] ) ;
354
350
355
351
const paths = container . querySelectorAll < HTMLElement > (
356
- '.leaflet-container svg:not(.leaflet-attribution-flag) path' ,
352
+ '.leaflet-container svg:not(.leaflet-attribution-flag) path.leaflet-interactive ' ,
357
353
) ;
358
354
359
- expect ( paths [ 0 ] ) . toHaveAttribute ( 'stroke-width' , '3' ) ;
355
+ expect ( paths ) . toHaveLength ( 3 ) ;
356
+ expect ( paths [ 0 ] ) . toHaveAttribute ( 'stroke-width' , '1' ) ;
357
+ expect ( paths [ 1 ] ) . toHaveAttribute ( 'stroke-width' , '1' ) ;
358
+ expect ( paths [ 2 ] ) . toHaveAttribute ( 'stroke-width' , '3' ) ;
360
359
361
360
await userEvent . selectOptions (
362
361
select ,
363
362
within ( select ) . getAllByRole ( 'option' ) [ 0 ] ,
364
363
) ;
365
364
366
365
expect ( paths [ 0 ] ) . toHaveAttribute ( 'stroke-width' , '1' ) ;
366
+ expect ( paths [ 1 ] ) . toHaveAttribute ( 'stroke-width' , '1' ) ;
367
+ // Stroke width is reset
368
+ expect ( paths [ 2 ] ) . toHaveAttribute ( 'stroke-width' , '1' ) ;
367
369
} ) ;
368
370
369
371
test ( 'ensure values with decimal places go are assigned the correct colour when the legend values are set to 0 decimal places' , async ( ) => {
0 commit comments