Skip to content

Commit d6d6c01

Browse files
authored
feat(e2e): Add end-to-end tests for native maplibre-gl methods (#1966)
* Add examples for using native map methods * Reference examples in geo docs * Add e2e tests for native map methods * Type the mapRef in useRef hook
1 parent 2964908 commit d6d6c01

File tree

8 files changed

+94
-51
lines changed

8 files changed

+94
-51
lines changed
Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
```jsx{12,15,21}
2-
import { Button, MapView } from '@aws-amplify/ui-react';
3-
import { Amplify } from 'aws-amplify';
4-
import { useCallback, useRef } from 'react';
1+
```jsx{12,15,21} file=../../../../../../../examples/next/pages/ui/components/geo/map-with-forward-ref/index.page.tsx
52

6-
import '@aws-amplify/ui-react/styles.css';
7-
8-
import awsExports from './aws-exports';
9-
10-
Amplify.configure(awsExports);
11-
12-
export default function MapWithRef() {
13-
const mapRef = useRef();
14-
15-
const flyToMordor = useCallback(() => {
16-
mapRef.current.flyTo({ center: [172.78, -42.28], zoom: 5 });
17-
}, []);
18-
19-
return (
20-
<>
21-
<Button onClick={flyToMordor}>Fly, you fools!</Button>
22-
<MapView ref={mapRef} />
23-
</>
24-
);
25-
}
263
```
Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
```jsx
2-
import { Button, MapView } from '@aws-amplify/ui-react';
3-
import { Amplify } from 'aws-amplify';
4-
import { useMap } from 'react-map-gl';
1+
```jsx{3,12,15,24} file=../../../../../../../examples/next/pages/ui/components/geo/use-map-hook/index.page.tsx
52

6-
import '@aws-amplify/ui-react/styles.css';
7-
8-
import awsExports from './aws-exports';
9-
10-
Amplify.configure(awsExports);
11-
12-
function FlyToButton() {
13-
const { current: map } = useMap();
14-
15-
const flyToMordor = () => {
16-
map.flyTo({ center: [172.78, -42.28], zoom: 5 });
17-
};
18-
19-
return <Button onClick={flyToMordor}>Fly, you fools!</Button>;
20-
}
21-
22-
export default function MapWithButton() {
23-
return (
24-
<MapView>
25-
<FlyToButton />
26-
</MapView>
27-
);
28-
}
293
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import awsExports from '@environments/basic-map/src/aws-exports';
2+
export default awsExports;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Button, MapView } from '@aws-amplify/ui-react';
2+
import { Amplify } from 'aws-amplify';
3+
import { useCallback, useRef } from 'react';
4+
import type { MapRef } from 'react-map-gl';
5+
6+
import '@aws-amplify/ui-react/styles.css';
7+
8+
import awsExports from './aws-exports';
9+
10+
Amplify.configure(awsExports);
11+
12+
export default function MapWithRef() {
13+
const mapRef = useRef<MapRef>();
14+
15+
const flyToMordor = useCallback(() => {
16+
mapRef.current.flyTo({ center: [172.78, -42.28], zoom: 5 });
17+
}, []);
18+
19+
return (
20+
<>
21+
<Button onClick={flyToMordor}>Fly, you fools!</Button>
22+
<MapView ref={mapRef} />
23+
</>
24+
);
25+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import awsExports from '@environments/basic-map/src/aws-exports';
2+
export default awsExports;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Button, MapView } from '@aws-amplify/ui-react';
2+
import { Amplify } from 'aws-amplify';
3+
import { useMap } from 'react-map-gl';
4+
5+
import '@aws-amplify/ui-react/styles.css';
6+
7+
import awsExports from './aws-exports';
8+
9+
Amplify.configure(awsExports);
10+
11+
function FlyToButton() {
12+
const { current: map } = useMap();
13+
14+
const flyToMordor = () => {
15+
map.flyTo({ center: [172.78, -42.28], zoom: 5 });
16+
};
17+
18+
return <Button onClick={flyToMordor}>Fly, you fools!</Button>;
19+
}
20+
21+
export default function MapWithButton() {
22+
return (
23+
<MapView>
24+
<FlyToButton />
25+
</MapView>
26+
);
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Then, When } from 'cypress-cucumber-preprocessor/steps';
2+
3+
let mapCenter;
4+
5+
When('I see the map load', () => {
6+
cy.waitForIdleMap();
7+
cy.window()
8+
.its('map')
9+
.invoke('getCenter')
10+
.then((startingCenter) => {
11+
mapCenter = startingCenter;
12+
});
13+
});
14+
15+
When('I click the button to transition the map', () => {
16+
cy.findByRole('button', { name: /fly/gi }).click({ force: true });
17+
});
18+
19+
Then('I see the map viewport transition', () => {
20+
cy.window().its('map').invoke('getCenter').should('not.eq', mapCenter);
21+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Native Map Method
2+
3+
Using the native maplibre-gl methods.
4+
5+
@react
6+
Scenario Outline: Native "flyTo" method should change map viewport
7+
Given I'm running the example "ui/components/geo/<example>"
8+
When I see the map load
9+
And I click the button to transition the map
10+
Then I see the map viewport transition
11+
12+
Examples:
13+
| example |
14+
| map-with-forward-ref |
15+
| use-map-hook |

0 commit comments

Comments
 (0)