From 02ed7a0ec84f9ebdd40586c608ddfe0a8352abc8 Mon Sep 17 00:00:00 2001 From: Jez Barnsley Date: Wed, 20 May 2026 13:30:08 +0100 Subject: [PATCH 1/3] Fixed when no map options specified --- src/client/javascripts/geospatial-map.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/javascripts/geospatial-map.js b/src/client/javascripts/geospatial-map.js index aec354bd3..3613eb7d8 100644 --- a/src/client/javascripts/geospatial-map.js +++ b/src/client/javascripts/geospatial-map.js @@ -213,7 +213,7 @@ export function processGeospatial(config, geospatial, index) { const { map, interactPlugin } = createMap(mapId, initConfig, config) const featuresManager = getFeaturesManager(geojson) const activeFeatureManager = getActiveFeatureManager() - const geometryTypes = geospatial.dataset.geometrytypes ?? 'point,line,shape' + const geometryTypes = geospatial.dataset.geometrytypes const options = { geometryTypes } @@ -567,7 +567,9 @@ function getUIManager(geojson, map, mapId, listEl, geospatialInput, options) { * @returns {string[]} */ function getAllowableGeometryTypes() { - return options.geometryTypes ? options.geometryTypes.split(',') : [] + return options.geometryTypes + ? options.geometryTypes.split(',') + : ['point', 'line', 'shape'] } /** From e13285aeeb955c0df5fcc9304dd40ec222ea89da Mon Sep 17 00:00:00 2001 From: Jez Barnsley Date: Wed, 20 May 2026 14:55:39 +0100 Subject: [PATCH 2/3] Test coverage --- src/client/javascripts/geospatial-map.js | 13 ++++-- test/client/javascripts/map.test.js | 50 +++++++++++++++++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/client/javascripts/geospatial-map.js b/src/client/javascripts/geospatial-map.js index 3613eb7d8..cbdda3d52 100644 --- a/src/client/javascripts/geospatial-map.js +++ b/src/client/javascripts/geospatial-map.js @@ -559,15 +559,22 @@ function getValueRenderer(geojson, geospatialInput) { * @param {string} mapId - the ID of the map * @param {HTMLDivElement} listEl - where to render the feature list * @param {HTMLTextAreaElement} geospatialInput - the geospatial textarea - * @param {UIManagerOptions} options - extra options such as allowable geometry types + * @param { UIManagerOptions | undefined } options - extra options such as allowable geometry types */ -function getUIManager(geojson, map, mapId, listEl, geospatialInput, options) { +export function getUIManager( + geojson, + map, + mapId, + listEl, + geospatialInput, + options +) { /** * Get a CSV list of geometry types the user can create * @returns {string[]} */ function getAllowableGeometryTypes() { - return options.geometryTypes + return options?.geometryTypes ? options.geometryTypes.split(',') : ['point', 'line', 'shape'] } diff --git a/test/client/javascripts/map.test.js b/test/client/javascripts/map.test.js index 1e0c1f7d5..6eacde2ad 100644 --- a/test/client/javascripts/map.test.js +++ b/test/client/javascripts/map.test.js @@ -1,7 +1,8 @@ import { createFeatureHTML, createFeaturesHTML, - getHelpPanelHtml + getHelpPanelHtml, + getUIManager } from '~/src/client/javascripts/geospatial-map.js' import { formSubmitFactory, @@ -1645,4 +1646,51 @@ describe('Maps Client JS', () => { expect(result).toBe('TQ 29472 80890') }) }) + + describe('processGeospatial', () => { + beforeEach(() => { + document.body.innerHTML = ` +
+ +
` + }) + + it('should create UiManager with default geometry types', () => { + const geospatialElem = document.querySelector('.app-geospatial-field') + // @ts-expect-error - partial mock of data + const uiManager = getUIManager( + {}, + {}, + 'map-id', + geospatialElem, + {}, + undefined + ) + expect(uiManager.getAllowableGeometryTypes).toBeDefined() + expect(uiManager.getAllowableGeometryTypes()).toEqual([ + 'point', + 'line', + 'shape' + ]) + }) + + it('should create UiManager with specified geometry types', () => { + const geospatialElem = document.querySelector('.app-geospatial-field') + // @ts-expect-error - partial mock of data + const uiManager = getUIManager( + {}, + {}, + 'map-id', + geospatialElem, + {}, + { geometryTypes: 'point,line' } + ) + expect(uiManager.getAllowableGeometryTypes).toBeDefined() + expect(uiManager.getAllowableGeometryTypes()).toEqual(['point', 'line']) + }) + }) }) + +/** + * @import { GeoJSON } from '~/src/client/javascripts/geospatial-map.js' + */ From 473b4c3f6f2d037f1ef53171dc86fd0e70006734 Mon Sep 17 00:00:00 2001 From: Jez Barnsley Date: Wed, 20 May 2026 14:57:11 +0100 Subject: [PATCH 3/3] Lint fix --- test/client/javascripts/map.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/client/javascripts/map.test.js b/test/client/javascripts/map.test.js index 6eacde2ad..deea56697 100644 --- a/test/client/javascripts/map.test.js +++ b/test/client/javascripts/map.test.js @@ -1647,7 +1647,7 @@ describe('Maps Client JS', () => { }) }) - describe('processGeospatial', () => { + describe('UiManager', () => { beforeEach(() => { document.body.innerHTML = `
@@ -1657,8 +1657,8 @@ describe('Maps Client JS', () => { it('should create UiManager with default geometry types', () => { const geospatialElem = document.querySelector('.app-geospatial-field') - // @ts-expect-error - partial mock of data const uiManager = getUIManager( + // @ts-expect-error - partial mock of data {}, {}, 'map-id', @@ -1676,8 +1676,8 @@ describe('Maps Client JS', () => { it('should create UiManager with specified geometry types', () => { const geospatialElem = document.querySelector('.app-geospatial-field') - // @ts-expect-error - partial mock of data const uiManager = getUIManager( + // @ts-expect-error - partial mock of data {}, {}, 'map-id',