diff --git a/src/client/javascripts/geospatial-map.js b/src/client/javascripts/geospatial-map.js index aec354bd3..cbdda3d52 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 } @@ -559,15 +559,24 @@ 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 ? options.geometryTypes.split(',') : [] + 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..deea56697 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('UiManager', () => { + beforeEach(() => { + document.body.innerHTML = ` +
+ +
` + }) + + it('should create UiManager with default geometry types', () => { + const geospatialElem = document.querySelector('.app-geospatial-field') + const uiManager = getUIManager( + // @ts-expect-error - partial mock of data + {}, + {}, + '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') + const uiManager = getUIManager( + // @ts-expect-error - partial mock of data + {}, + {}, + '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' + */