Skip to content

Commit d30c765

Browse files
authored
feat(e2e): Add custom Cypress command to wait for idle map (#1940)
* Add waitForMapIdle custom command * Update react-map-gl to latest * Wrap cypress property setters in useEffect
1 parent 91d207d commit d30c765

File tree

5 files changed

+85
-29
lines changed

5 files changed

+85
-29
lines changed

examples/next/pages/_app.page.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,56 @@
44
import App from 'next/app';
55
import { Amplify, Hub } from 'aws-amplify';
66
import { Authenticator, AmplifyProvider } from '@aws-amplify/ui-react';
7+
import { useEffect } from 'react';
8+
import { MapProvider, useMap } from 'react-map-gl';
79

810
if (typeof window !== 'undefined') {
911
window['Amplify'] = Amplify;
1012
window['Hub'] = Hub;
1113
}
1214

15+
const SetCypressProperties = () => {
16+
const { default: map } = useMap();
17+
18+
useEffect(() => {
19+
if (typeof window !== 'undefined' && window['Cypress']) {
20+
map?.once('load', () => {
21+
window['map'] = map;
22+
});
23+
24+
map?.on('idle', () => {
25+
window['idleMap'] = true;
26+
});
27+
28+
map?.on('render', () => {
29+
window['idleMap'] = false;
30+
});
31+
32+
return () => {
33+
map?.off('idle', () => {
34+
delete window['idleMap'];
35+
});
36+
37+
map?.off('render', () => {
38+
delete window['idleMap'];
39+
});
40+
};
41+
}
42+
}, [map]);
43+
44+
return null;
45+
};
46+
1347
export default function MyApp(props) {
48+
if (/\/geo\//g.test(props.router.route)) {
49+
return (
50+
<MapProvider>
51+
<App {...props} />
52+
<SetCypressProperties />
53+
</MapProvider>
54+
);
55+
}
56+
1457
return (
1558
<AmplifyProvider>
1659
<Authenticator.Provider>

packages/e2e/cypress/support/commands.d.ts

Lines changed: 33 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/e2e/cypress/support/commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ Cypress.Commands.add('findInputField', (field: string) => {
6666
return cy.findByRole('textbox', { name: regex });
6767
}
6868
});
69+
70+
Cypress.Commands.add('waitForIdleMap', () => {
71+
cy.window().its('idleMap').should('be.true');
72+
});

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"maplibre-gl-js-amplify": "1.5.0",
7474
"qrcode": "1.5.0",
7575
"react-generate-context": "1.0.1",
76-
"react-map-gl": "7.0.10"
76+
"react-map-gl": "7.0.13"
7777
},
7878
"peerDependencies": {
7979
"aws-amplify": "3.x.x || 4.x.x",

yarn.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)