@popsure/dirty-swan 0.27.23 → 0.27.24
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/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/components/autocompleteAddress/index.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/lib/components/autocompleteAddress/index.test.tsx +94 -0
- package/src/lib/components/autocompleteAddress/index.tsx +6 -0
- package/src/setupTests.js +48 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Address } from '@popsure/public-models';
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import AutoCompleteAddress from '.';
|
|
5
|
+
|
|
6
|
+
const address = {
|
|
7
|
+
street: 'Köpeniker Strasse',
|
|
8
|
+
houseNumber: '4000',
|
|
9
|
+
postcode: '10179',
|
|
10
|
+
city: 'Berlin',
|
|
11
|
+
country: 'DE',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const setup = (
|
|
15
|
+
address: Partial<Address> | undefined = undefined,
|
|
16
|
+
onAddressChange: (address: Partial<Address>) => void = () => {}
|
|
17
|
+
) => {
|
|
18
|
+
return render(
|
|
19
|
+
<AutoCompleteAddress
|
|
20
|
+
address={address}
|
|
21
|
+
apiKey={''}
|
|
22
|
+
onAddressChange={onAddressChange}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const inputTestId = 'ds-input-input';
|
|
28
|
+
|
|
29
|
+
describe('AutocompleteAddress component', () => {
|
|
30
|
+
it('Should show all address fields once a search is completed', () => {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
window.google.maps.places.Autocomplete = class {
|
|
33
|
+
reference: HTMLElement;
|
|
34
|
+
constructor(reference: HTMLElement) {
|
|
35
|
+
this.reference = reference;
|
|
36
|
+
}
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
addListener(_action, callback) {
|
|
39
|
+
this.reference.addEventListener('change', (e: Event) =>
|
|
40
|
+
(e.target as HTMLInputElement).value !== ''
|
|
41
|
+
? callback({
|
|
42
|
+
geometry: {
|
|
43
|
+
location: class {},
|
|
44
|
+
},
|
|
45
|
+
address_components: [
|
|
46
|
+
{
|
|
47
|
+
long_name: 'Köpeniker Strasse',
|
|
48
|
+
short_name: 'Köpeniker Strasse',
|
|
49
|
+
types: ['route'],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
: null
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const screen = setup();
|
|
59
|
+
fireEvent.change(screen.getByTestId(inputTestId), {
|
|
60
|
+
target: { value: 'Köpeniker' },
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const inputs = screen.getAllByTestId(inputTestId);
|
|
64
|
+
expect(inputs[0].getAttribute('value')).toBe('Köpeniker Strasse');
|
|
65
|
+
expect(inputs.length).toEqual(5);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('Should enable to enter the address manually', async () => {
|
|
69
|
+
const callback = jest.fn();
|
|
70
|
+
const screen = setup(undefined, callback);
|
|
71
|
+
const btn = await screen.findByText('Enter address manually');
|
|
72
|
+
fireEvent.click(btn);
|
|
73
|
+
|
|
74
|
+
// fill out all fields
|
|
75
|
+
const inputs = screen.getAllByTestId(inputTestId);
|
|
76
|
+
|
|
77
|
+
fireEvent.change(inputs[0], { target: { value: 'Köpeniker Strasse' } });
|
|
78
|
+
fireEvent.change(inputs[1], { target: { value: '4000' } });
|
|
79
|
+
fireEvent.change(inputs[3], { target: { value: '10179' } });
|
|
80
|
+
fireEvent.change(inputs[4], { target: { value: 'Berlin' } });
|
|
81
|
+
|
|
82
|
+
// callback should be called with a complete address
|
|
83
|
+
expect(callback).toHaveBeenCalledWith(address);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('Should prefill fields if an address is provided', async () => {
|
|
87
|
+
const screen = setup(address);
|
|
88
|
+
const inputs = screen.getAllByTestId(inputTestId);
|
|
89
|
+
expect(inputs[0].getAttribute('value')).toBe('Köpeniker Strasse');
|
|
90
|
+
expect(inputs[1].getAttribute('value')).toBe('4000');
|
|
91
|
+
expect(inputs[3].getAttribute('value')).toBe('10179');
|
|
92
|
+
expect(inputs[4].getAttribute('value')).toBe('Berlin');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -228,6 +228,7 @@ const AutoCompleteAddress = ({
|
|
|
228
228
|
<Input
|
|
229
229
|
className="w100"
|
|
230
230
|
id="autocomplete"
|
|
231
|
+
key="autocomplete-search"
|
|
231
232
|
data-cy="autocomplete"
|
|
232
233
|
type="text"
|
|
233
234
|
placeholder={
|
|
@@ -247,6 +248,7 @@ const AutoCompleteAddress = ({
|
|
|
247
248
|
<Input
|
|
248
249
|
className="w100"
|
|
249
250
|
data-cy="autocomplete"
|
|
251
|
+
key="autocomplete-street"
|
|
250
252
|
type="text"
|
|
251
253
|
placeholder={placeholders?.street || 'Street'}
|
|
252
254
|
value={address?.street || ''}
|
|
@@ -263,6 +265,7 @@ const AutoCompleteAddress = ({
|
|
|
263
265
|
<Input
|
|
264
266
|
className={`wmx2 ${styles['house-number-input']}`}
|
|
265
267
|
data-cy="autocomplete-house-number"
|
|
268
|
+
key="autocomplete-house-number"
|
|
266
269
|
placeholder={placeholders?.houseNumber || 'House Number'}
|
|
267
270
|
value={address?.houseNumber || ''}
|
|
268
271
|
onChange={(e) => {
|
|
@@ -279,6 +282,7 @@ const AutoCompleteAddress = ({
|
|
|
279
282
|
<Input
|
|
280
283
|
className="mt16"
|
|
281
284
|
data-cy="autocomplete-additional-info"
|
|
285
|
+
key="autocomplete-additional-info"
|
|
282
286
|
placeholder={
|
|
283
287
|
placeholders?.additionalInformation ||
|
|
284
288
|
'Additional information (C/O, apartment, …)'
|
|
@@ -297,6 +301,7 @@ const AutoCompleteAddress = ({
|
|
|
297
301
|
<Input
|
|
298
302
|
className="w100"
|
|
299
303
|
data-cy="autocomplete-postcode"
|
|
304
|
+
key="autocomplete-postcode"
|
|
300
305
|
placeholder={placeholders?.postcode || 'Postcode'}
|
|
301
306
|
value={address?.postcode || ''}
|
|
302
307
|
onChange={(e) => {
|
|
@@ -312,6 +317,7 @@ const AutoCompleteAddress = ({
|
|
|
312
317
|
<Input
|
|
313
318
|
className="w100"
|
|
314
319
|
data-cy="autocomplete-city"
|
|
320
|
+
key="autocomplete-city"
|
|
315
321
|
placeholder={placeholders?.city || 'City'}
|
|
316
322
|
value={address?.city || ''}
|
|
317
323
|
onChange={(e) => {
|
package/src/setupTests.js
CHANGED
|
@@ -1,8 +1,54 @@
|
|
|
1
1
|
window.google = {
|
|
2
2
|
maps: {
|
|
3
|
+
StyledMapType: class {},
|
|
4
|
+
Marker: class {
|
|
5
|
+
setPosition() {}
|
|
6
|
+
},
|
|
7
|
+
Map: class {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.mapTypes = { set: jest.fn() };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
setMapTypeId() {
|
|
13
|
+
return jest.fn();
|
|
14
|
+
}
|
|
15
|
+
panTo() {}
|
|
16
|
+
setZoom() {}
|
|
17
|
+
},
|
|
18
|
+
LatLngBounds: class {},
|
|
3
19
|
places: {
|
|
4
|
-
Autocomplete: class {
|
|
20
|
+
Autocomplete: class {
|
|
21
|
+
addListener() {
|
|
22
|
+
return jest.fn();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
AutocompleteService: class {},
|
|
26
|
+
PlacesServiceStatus: {
|
|
27
|
+
INVALID_REQUEST: 'INVALID_REQUEST',
|
|
28
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
29
|
+
OK: 'OK',
|
|
30
|
+
OVER_QUERY_LIMIT: 'OVER_QUERY_LIMIT',
|
|
31
|
+
REQUEST_DENIED: 'REQUEST_DENIED',
|
|
32
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
33
|
+
ZERO_RESULTS: 'ZERO_RESULTS',
|
|
34
|
+
},
|
|
35
|
+
PlacesAutocomplete: {
|
|
36
|
+
INVALID_REQUEST: 'INVALID_REQUEST',
|
|
37
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
38
|
+
OK: 'OK',
|
|
39
|
+
OVER_QUERY_LIMIT: 'OVER_QUERY_LIMIT',
|
|
40
|
+
REQUEST_DENIED: 'REQUEST_DENIED',
|
|
41
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
42
|
+
ZERO_RESULTS: 'ZERO_RESULTS',
|
|
43
|
+
},
|
|
44
|
+
PlacesService: class {
|
|
45
|
+
findPlaceFromQuery() {
|
|
46
|
+
return jest.fn();
|
|
47
|
+
}
|
|
48
|
+
},
|
|
5
49
|
},
|
|
6
|
-
|
|
50
|
+
|
|
51
|
+
MarkerClusterer: class {},
|
|
52
|
+
Geocoder: class {},
|
|
7
53
|
},
|
|
8
54
|
};
|