Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple map interactions #751

Merged
merged 16 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
ed407bb
:heavy_plus_sign: [open-formulieren/open-forms#2177] Added dependencies
robinmolen Nov 25, 2024
23d63d9
:fire: [open-formulieren/open-forms#2177] Removing old map functional…
robinmolen Dec 10, 2024
f7f6e85
:sparkles: [open-formulieren/open-forms#2177] Map component using geo…
robinmolen Dec 10, 2024
94ed0f5
:sparkles: [open-formulieren/open-forms#2177] Change map interactions…
robinmolen Dec 10, 2024
6b20cbb
:sparkles: [open-formulieren/open-forms#2177] Map search control with…
robinmolen Dec 10, 2024
ee643c1
:sparkles: [open-formulieren/open-forms#2177] Get coordinates of geo …
robinmolen Dec 10, 2024
502069c
:sparkles: [open-formulieren/open-forms#2177] Disabled logic
robinmolen Dec 10, 2024
4d89128
:sparkles: [open-formulieren/open-forms#2177] Display map data on sum…
robinmolen Dec 12, 2024
bc40c80
:green_heart: open-formulieren/open-forms#2177 resolved version issue…
robinmolen Jan 6, 2025
ce8e518
:white_check_mark: [open-formulieren/open-forms#2177] Expanding and f…
robinmolen Jan 7, 2025
6cfeb29
:sparkles: [open-formulieren/open-forms#2177] Allow manually deleting…
robinmolen Jan 9, 2025
8283741
:lipstick: [open-formulieren/open-forms#2177] Leaflet styling
robinmolen Jan 9, 2025
c5aadb9
:globe_with_meridians: [open-formulieren/open-forms#2177] Leaflet tra…
robinmolen Jan 9, 2025
29eb3a6
:boom: [open-formulieren/open-forms#2177] Map component now only retu…
robinmolen Jan 13, 2025
1419935
:ok_hand: [open-formulieren/open-forms#2177] PR feedback
robinmolen Jan 22, 2025
73607c2
:bug: [open-formulieren/open-forms#2177] Duplicate Leaflet shapes
robinmolen Jan 22, 2025
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
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"ibantools": "^3.3.0",
"immer": "^9.0.6",
"leaflet": "^1.9.4",
"leaflet-draw": "^1.0.4",
"leaflet-geosearch": "^3.8.0",
"leaflet-gesture-handling": "^1.2.2",
"microscope-sass": "^2.0.0",
Expand All @@ -51,6 +52,7 @@
"react-formio": "^4.3.0",
"react-intl": "^6.4.4",
"react-leaflet": "4.2.1",
"react-leaflet-draw": "^0.20.4",
"react-modal": "3.16.1",
"react-number-format": "5.2.2",
"react-router-dom": "^6.11.2",
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormStepSummary/ComponentValueDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const MapDisplay = ({component, value}) => {
return <EmptyDisplay />;
}

return <Map markerCoordinates={value} disabled tileLayerUrl={component.tileLayerUrl} />;
return <Map geoJsonGeometry={value} disabled tileLayerUrl={component.tileLayerUrl} />;
};

const CoSignDisplay = ({value}) => {
Expand Down
86 changes: 81 additions & 5 deletions src/components/Map/Map.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {userEvent, within} from '@storybook/test';
import {expect, fn, userEvent, waitFor, within} from '@storybook/test';
import {useState} from 'react';

import {ConfigDecorator} from 'story-utils/decorators';

Expand All @@ -11,12 +12,29 @@ const withMapLayout = Story => (
</div>
);

const StorybookLeafletMap = props => {
const [geoJson, setGeoJson] = useState(props?.geoJsonGeometry);
const handleGeoJsonChange = args => {
if (props?.onGeoJsonGeometrySet) {
props?.onGeoJsonGeometrySet(args);
}
setGeoJson(args);
};
return (
<LeafletMap {...props} geoJsonGeometry={geoJson} onGeoJsonGeometrySet={handleGeoJsonChange} />
);
};

export default {
title: 'Private API / Map',
component: LeafletMap,
decorators: [withMapLayout, ConfigDecorator],
render: StorybookLeafletMap,
args: {
markerCoordinates: [52.1326332, 5.291266],
geoJsonGeometry: {
type: 'Point',
coordinates: [5.291266, 52.1326332],
},
defaultCenter: [52.1326332, 5.291266],
defaultZoomLevel: 12,
disabled: false,
Expand All @@ -31,17 +49,32 @@ export default {
export const Map = {};

export const MapWithAddressSearch = {
play: async ({canvasElement}) => {
args: {
onGeoJsonGeometrySet: fn(),
},
play: async ({canvasElement, args}) => {
const canvas = within(canvasElement);
const button = await canvas.findByLabelText('Zoeken');
await userEvent.click(button);

await waitFor(async () => {
const button = await canvas.findByLabelText('Zoeken');
await userEvent.click(button);
expect(await canvas.findByPlaceholderText('Zoek adres')).toBeVisible();
});

const searchField = await canvas.findByPlaceholderText('Zoek adres');
const searchBox = within(searchField.parentNode);
await userEvent.type(searchField, 'Gemeente Utrecht');
const searchResult = await searchBox.findByText('Utrecht, Utrecht, Utrecht');

await userEvent.click(searchResult);
await waitFor(async () => {
// A marker is placed on the search result
expect(args.onGeoJsonGeometrySet).toBeCalledWith({
type: 'Point',
// To make sure that this test doesn't magically fail, just expect any 2 values
coordinates: [expect.anything(), expect.anything()],
});
});
},
};

Expand All @@ -59,3 +92,46 @@ export const MapWithAerialPhotoBackground = {
'https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_orthoHR/EPSG:28992/{z}/{x}/{y}.png',
},
};

export const MapWithInteractions = {
args: {
interactions: {
polygon: true,
polyline: true,
marker: true,
},
onGeoJsonGeometrySet: fn(),
},
parameters: {
msw: {
handlers: [mockAddressSearchGet, mockLatLngSearchEmptyGet],
},
},
play: async ({canvasElement, step, args}) => {
const canvas = within(canvasElement);
const map = canvasElement.querySelector('.leaflet-pane.leaflet-map-pane');

await step('All interactions are available', async () => {
expect(await canvas.findByTitle('Pin/punt')).toBeVisible();
expect(await canvas.findByTitle('Veelhoek (polygoon)')).toBeVisible();
expect(await canvas.findByTitle('Lijn')).toBeVisible();
});

await step('Draw a marker', async () => {
const markerButton = await canvas.findByTitle('Pin/punt');
await userEvent.click(markerButton);

await userEvent.click(map, {x: 100, y: 100});

// This 'button' is the placed marker on the map
expect(await canvas.findByRole('button', {name: 'Marker'})).toBeVisible();
expect(args.onGeoJsonGeometrySet).toBeCalledWith({
type: 'Point',
// Expect that the coordinates array contains 2 items.
// We cannot pin it to specific values, because they can differentiate.
// To make sure that this test doesn't magically fail, just expect any 2 values
coordinates: [expect.anything(), expect.anything()],
});
});
},
};
Loading
Loading