@woosmap/ui 3.166.0 → 3.168.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -49,14 +49,14 @@ export default class DistanceDemo extends Component {
|
|
|
49
49
|
const defaultLang = languages.find((item) => lang.startsWith(item.value));
|
|
50
50
|
|
|
51
51
|
this.defaultOrigin = {
|
|
52
|
-
public_id: '
|
|
53
|
-
description: '
|
|
54
|
-
location: { lat:
|
|
52
|
+
public_id: 'milano',
|
|
53
|
+
description: 'Milan, Milano, Italie',
|
|
54
|
+
location: { lat: 45.46419429317345, lng: 9.189634535335927 },
|
|
55
55
|
};
|
|
56
56
|
this.defaultDestination = {
|
|
57
|
-
public_id: '
|
|
58
|
-
description: '
|
|
59
|
-
location: { lat: 45.
|
|
57
|
+
public_id: 'linate',
|
|
58
|
+
description: 'Linate, Peschiera Borromeo, Italie',
|
|
59
|
+
location: { lat: 45.446776949835964, lng: 9.272510686783079 },
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
this.state = {
|
|
@@ -147,29 +147,27 @@ export default class DistanceDemo extends Component {
|
|
|
147
147
|
|
|
148
148
|
requestDistance = () => {
|
|
149
149
|
const instance = axios.create();
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
|
|
151
|
+
const processSuccess = (routes) => {
|
|
152
|
+
if (this.mounted) this.setState({ routes, error: null }, () => this.displayOnMap());
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const processError = (errorMessage) => {
|
|
156
|
+
const message = errorMessage || 'Unhandled error';
|
|
157
|
+
|
|
158
|
+
if (this.mounted) this.setState({ error: { message } });
|
|
159
|
+
};
|
|
160
|
+
|
|
153
161
|
instance
|
|
154
162
|
.get(this.requestUrl, { params: this.getRequestparams() })
|
|
155
163
|
.then((response) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
error: null,
|
|
161
|
-
},
|
|
162
|
-
() => {
|
|
163
|
-
this.displayOnMap();
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
|
-
}
|
|
164
|
+
const isOk = response?.data?.status === 'OK' && response?.data?.routes;
|
|
165
|
+
|
|
166
|
+
if (!isOk) processError(response?.data?.error_message);
|
|
167
|
+
else processSuccess(response.data.routes);
|
|
167
168
|
})
|
|
168
169
|
.catch((error) => {
|
|
169
|
-
|
|
170
|
-
if (this.mounted) {
|
|
171
|
-
this.setState({ error: errorResult });
|
|
172
|
-
}
|
|
170
|
+
processError(error?.data?.error_message);
|
|
173
171
|
});
|
|
174
172
|
};
|
|
175
173
|
|
|
@@ -249,6 +247,7 @@ export default class DistanceDemo extends Component {
|
|
|
249
247
|
woosmapKey={Constants.woosmapKey}
|
|
250
248
|
defaultLocality={this.defaultOrigin}
|
|
251
249
|
language={language.value}
|
|
250
|
+
types="locality|postal_code|airport"
|
|
252
251
|
callback={this.localitiesOnChangeCallBack('origin')}
|
|
253
252
|
/>
|
|
254
253
|
</>
|
|
@@ -263,6 +262,7 @@ export default class DistanceDemo extends Component {
|
|
|
263
262
|
woosmapKey={Constants.woosmapKey}
|
|
264
263
|
defaultLocality={this.defaultDestination}
|
|
265
264
|
language={language.value}
|
|
265
|
+
types="locality|postal_code|airport"
|
|
266
266
|
callback={this.localitiesOnChangeCallBack('destination')}
|
|
267
267
|
/>
|
|
268
268
|
</>
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { fireEvent, render, screen
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
3
|
import '@testing-library/jest-dom/extend-expect';
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
import DistanceDemo from './DistanceDemo';
|
|
6
6
|
|
|
7
|
+
const API_ERROR_MESSAGE = 'Some handled error message';
|
|
8
|
+
|
|
9
|
+
jest.mock('axios', () => {
|
|
10
|
+
const get = () => Promise.resolve({ data: { status: 'ERROR', error_message: API_ERROR_MESSAGE }, status: 200 });
|
|
11
|
+
return { get, create: () => ({ get }) };
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.resetModules();
|
|
16
|
+
});
|
|
17
|
+
|
|
7
18
|
it('render distance demo', () => {
|
|
8
19
|
const { container } = render(<DistanceDemo />);
|
|
9
20
|
expect(container.firstChild).toHaveClass('demo');
|
|
@@ -45,23 +56,22 @@ it('test alternative route checkbox', () => {
|
|
|
45
56
|
expect(screen.getByText('alternatives=true"')).toBeVisible();
|
|
46
57
|
});
|
|
47
58
|
|
|
48
|
-
it('
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
rejectSpy.mockRestore();
|
|
59
|
+
it('Response with statusCode === 200 and status !== "OK" should be processed as error', async () => {
|
|
60
|
+
// mocking woosmap
|
|
61
|
+
const backup = { ...(global?.woosmap || {}) };
|
|
62
|
+
function Map() {}
|
|
63
|
+
|
|
64
|
+
global.woosmap = { map: { config: { setApiKey: () => ({}) }, Map } };
|
|
65
|
+
|
|
66
|
+
// We only mount the component because axios.get() is called at componentDidMount().
|
|
67
|
+
// axios.get() is mocked and returns 200 with status !== 'OK' by default for this testsuite
|
|
68
|
+
render(<DistanceDemo />);
|
|
69
|
+
|
|
70
|
+
// wait for re-rendering
|
|
71
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
72
|
+
|
|
73
|
+
expect(screen.getByText(API_ERROR_MESSAGE, { exact: false })).toBeInTheDocument();
|
|
74
|
+
|
|
75
|
+
// set back woosmap backup
|
|
76
|
+
global.woosmap = backup;
|
|
67
77
|
});
|
|
@@ -15,8 +15,9 @@ class Popover extends Component {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
render() {
|
|
18
|
-
const { children, content, renderLayer, isOpen, layerProps, triggerProps, arrowProps } =
|
|
19
|
-
|
|
18
|
+
const { children, content, renderLayer, isOpen, layerProps, triggerProps, arrowProps, contentClassName } =
|
|
19
|
+
this.props;
|
|
20
|
+
const popOverContentClassname = contentClassName ? `popover__content ${contentClassName}` : 'popover__content';
|
|
20
21
|
return (
|
|
21
22
|
<>
|
|
22
23
|
<div className="popover__child" {...triggerProps}>
|
|
@@ -25,7 +26,11 @@ class Popover extends Component {
|
|
|
25
26
|
{renderLayer(
|
|
26
27
|
<AnimatePresence>
|
|
27
28
|
{isOpen && (
|
|
28
|
-
<Animate
|
|
29
|
+
<Animate
|
|
30
|
+
data-testid="popover-content"
|
|
31
|
+
className={popOverContentClassname}
|
|
32
|
+
layerProps={layerProps}
|
|
33
|
+
>
|
|
29
34
|
{content}
|
|
30
35
|
<Arrow
|
|
31
36
|
borderColor="rgba(27, 31, 35, 0.15)"
|
|
@@ -51,7 +56,13 @@ Popover.propTypes = {
|
|
|
51
56
|
layerProps: PropTypes.object.isRequired,
|
|
52
57
|
triggerProps: PropTypes.object.isRequired,
|
|
53
58
|
arrowProps: PropTypes.object.isRequired,
|
|
59
|
+
contentClassName: PropTypes.string,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
Popover.defaultProps = {
|
|
63
|
+
contentClassName: undefined,
|
|
54
64
|
};
|
|
65
|
+
|
|
55
66
|
function withLayer(MyComponent) {
|
|
56
67
|
function WrappedComponent(props) {
|
|
57
68
|
const [isOpen, setOpen] = React.useState(false);
|