Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/client/javascripts/geospatial-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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']
}

/**
Expand Down
50 changes: 49 additions & 1 deletion test/client/javascripts/map.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
createFeatureHTML,
createFeaturesHTML,
getHelpPanelHtml
getHelpPanelHtml,
getUIManager
} from '~/src/client/javascripts/geospatial-map.js'
import {
formSubmitFactory,
Expand Down Expand Up @@ -1645,4 +1646,51 @@ describe('Maps Client JS', () => {
expect(result).toBe('TQ 29472 80890')
})
})

describe('UiManager', () => {
beforeEach(() => {
document.body.innerHTML = `
<div class="app-geospatial-field">
<textarea class="govuk-textarea"></textarea>
</div>`
})

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'
*/
Loading