Skip to content

Commit 439f402

Browse files
Add action button click tests
1 parent 6c5d9ea commit 439f402

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

test/client/javascripts/map.test.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
makeTileRequestTransformer
55
} from '~/src/client/javascripts/map.js'
66

7-
describe('Location Maps Client JS', () => {
7+
describe('Maps Client JS', () => {
88
/** @type {jest.Mock} */
99
let onMock
1010

@@ -41,6 +41,12 @@ describe('Location Maps Client JS', () => {
4141
/** @type {jest.Mock} */
4242
let drawPluginEditFeature
4343

44+
/** @type {jest.Mock} */
45+
let drawPluginNewPolygon
46+
47+
/** @type {jest.Mock} */
48+
let drawPluginNewLine
49+
4450
/** @type {jest.Mock} */
4551
let drawPluginDeleteFeature
4652

@@ -64,6 +70,8 @@ describe('Location Maps Client JS', () => {
6470
drawPluginAddFeature = jest.fn()
6571
drawPluginEditFeature = jest.fn()
6672
drawPluginDeleteFeature = jest.fn()
73+
drawPluginNewPolygon = jest.fn()
74+
drawPluginNewLine = jest.fn()
6775
interactPlugin = jest.fn(() => ({
6876
selectFeature: interactPluginSelectFeature,
6977
enable: interactPluginEnable,
@@ -72,7 +80,9 @@ describe('Location Maps Client JS', () => {
7280
drawMLPlugin = jest.fn(() => ({
7381
addFeature: drawPluginAddFeature,
7482
editFeature: drawPluginEditFeature,
75-
deleteFeature: drawPluginDeleteFeature
83+
deleteFeature: drawPluginDeleteFeature,
84+
newPolygon: drawPluginNewPolygon,
85+
newLine: drawPluginNewLine
7686
}))
7787

7888
class MockInteractiveMap {
@@ -1066,6 +1076,43 @@ describe('Location Maps Client JS', () => {
10661076
)
10671077
})
10681078

1079+
test('action buttons', () => {
1080+
initialiseGeospatialMaps()
1081+
1082+
const onMapReady = onMock.mock.calls[5][1]
1083+
expect(typeof onMapReady).toBe('function')
1084+
1085+
expect(addButtonMock).toHaveBeenCalledTimes(3)
1086+
const { onClick: onAddPointClick } = addButtonMock.mock.calls[0][1]
1087+
const { onClick: onAddPolygonClick } = addButtonMock.mock.calls[1][1]
1088+
const { onClick: onAddLineClick } = addButtonMock.mock.calls[2][1]
1089+
1090+
expect(typeof onAddPointClick).toBe('function')
1091+
expect(typeof onAddPolygonClick).toBe('function')
1092+
expect(typeof onAddLineClick).toBe('function')
1093+
1094+
// Manually invoke add point button click
1095+
onAddPointClick()
1096+
expectToggleButtons(true)
1097+
expect(interactPluginEnable).toHaveBeenCalledTimes(1)
1098+
1099+
// Manually invoke add polygon button click
1100+
onAddPolygonClick()
1101+
expectToggleButtons(true, 3)
1102+
expect(drawPluginNewPolygon).toHaveBeenCalledExactlyOnceWith(
1103+
expect.any(String),
1104+
expect.any(Object)
1105+
)
1106+
1107+
// Manually invoke add line button click
1108+
onAddLineClick()
1109+
expectToggleButtons(true, 6)
1110+
expect(drawPluginNewLine).toHaveBeenCalledExactlyOnceWith(
1111+
expect.any(String),
1112+
expect.any(Object)
1113+
)
1114+
})
1115+
10691116
test.skip('description changed', () => {
10701117
const { geospatialInput, listContainer } = initialiseGeospatialMaps()
10711118

0 commit comments

Comments
 (0)