@salesforce/retail-react-app 8.3.0-nightly-20251208080231 → 8.3.0-preview.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/CHANGELOG.md +2 -1
- package/app/components/address-suggestion-dropdown/index.jsx +189 -0
- package/app/components/address-suggestion-dropdown/index.test.jsx +332 -0
- package/app/components/forms/address-fields.jsx +18 -2
- package/app/components/forms/useAddressFields.jsx +139 -1
- package/app/components/forms/useAddressFields.test.js +310 -0
- package/app/hooks/useAutocompleteSuggestions.js +131 -0
- package/app/hooks/useAutocompleteSuggestions.test.js +296 -0
- package/app/mocks/mock-address-suggestions.js +445 -0
- package/app/pages/checkout/index.jsx +4 -2
- package/app/pages/checkout/index.test.js +206 -0
- package/app/pages/checkout/util/checkout-context.js +4 -1
- package/app/pages/checkout/util/google-api-provider.js +45 -0
- package/app/pages/checkout/util/google-api-provider.test.js +395 -0
- package/app/ssr.js +5 -1
- package/app/static/img/GoogleMaps_Logo_Gray_4x.png +0 -0
- package/app/static/translations/compiled/en-GB.json +6 -0
- package/app/static/translations/compiled/en-US.json +6 -0
- package/app/static/translations/compiled/en-XA.json +15 -1
- package/app/theme/components/project/swatch-group.js +1 -1
- package/app/utils/address-suggestions.js +237 -0
- package/config/default.js +4 -1
- package/package.json +9 -8
- package/translations/en-GB.json +3 -0
- package/translations/en-US.json +3 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const mockAddresses = [
|
|
9
|
+
{
|
|
10
|
+
description: '123 Main Street, New York, NY 10001, USA',
|
|
11
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
12
|
+
place_id: 'ChIJ1234567890',
|
|
13
|
+
reference: 'ref_1234567890',
|
|
14
|
+
structured_formatting: {
|
|
15
|
+
main_text: '123 Main Street',
|
|
16
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
17
|
+
secondary_text: 'New York, NY 10001, USA'
|
|
18
|
+
},
|
|
19
|
+
terms: [
|
|
20
|
+
{offset: 0, value: '123 Main Street'},
|
|
21
|
+
{offset: 17, value: 'New York'},
|
|
22
|
+
{offset: 27, value: 'NY'},
|
|
23
|
+
{offset: 30, value: '10001'},
|
|
24
|
+
{offset: 37, value: 'USA'}
|
|
25
|
+
],
|
|
26
|
+
types: ['street_address']
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
description: '456 Oak Avenue, Los Angeles, CA 90210, USA',
|
|
30
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
31
|
+
place_id: 'ChIJ4567890123',
|
|
32
|
+
reference: 'ref_4567890123',
|
|
33
|
+
structured_formatting: {
|
|
34
|
+
main_text: '456 Oak Avenue',
|
|
35
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
36
|
+
secondary_text: 'Los Angeles, CA 90210, USA'
|
|
37
|
+
},
|
|
38
|
+
terms: [
|
|
39
|
+
{offset: 0, value: '456 Oak Avenue'},
|
|
40
|
+
{offset: 16, value: 'Los Angeles'},
|
|
41
|
+
{offset: 29, value: 'CA'},
|
|
42
|
+
{offset: 32, value: '90210'},
|
|
43
|
+
{offset: 39, value: 'USA'}
|
|
44
|
+
],
|
|
45
|
+
types: ['street_address']
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
description: '789 Pine Road, Chicago, IL 60601, USA',
|
|
49
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
50
|
+
place_id: 'ChIJ7890123456',
|
|
51
|
+
reference: 'ref_7890123456',
|
|
52
|
+
structured_formatting: {
|
|
53
|
+
main_text: '789 Pine Road',
|
|
54
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
55
|
+
secondary_text: 'Chicago, IL 60601, USA'
|
|
56
|
+
},
|
|
57
|
+
terms: [
|
|
58
|
+
{offset: 0, value: '789 Pine Road'},
|
|
59
|
+
{offset: 14, value: 'Chicago'},
|
|
60
|
+
{offset: 22, value: 'IL'},
|
|
61
|
+
{offset: 25, value: '60601'},
|
|
62
|
+
{offset: 31, value: 'USA'}
|
|
63
|
+
],
|
|
64
|
+
types: ['street_address']
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
description: '321 Elm Street, Miami, FL 33101, USA',
|
|
68
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
69
|
+
place_id: 'ChIJ3210987654',
|
|
70
|
+
reference: 'ref_3210987654',
|
|
71
|
+
structured_formatting: {
|
|
72
|
+
main_text: '321 Elm Street',
|
|
73
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
74
|
+
secondary_text: 'Miami, FL 33101, USA'
|
|
75
|
+
},
|
|
76
|
+
terms: [
|
|
77
|
+
{offset: 0, value: '321 Elm Street'},
|
|
78
|
+
{offset: 15, value: 'Miami'},
|
|
79
|
+
{offset: 21, value: 'FL'},
|
|
80
|
+
{offset: 24, value: '33101'},
|
|
81
|
+
{offset: 30, value: 'USA'}
|
|
82
|
+
],
|
|
83
|
+
types: ['street_address']
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
description: '654 Cedar Lane, Seattle, WA 98101, USA',
|
|
87
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
88
|
+
place_id: 'ChIJ6543210987',
|
|
89
|
+
reference: 'ref_6543210987',
|
|
90
|
+
structured_formatting: {
|
|
91
|
+
main_text: '654 Cedar Lane',
|
|
92
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
93
|
+
secondary_text: 'Seattle, WA 98101, USA'
|
|
94
|
+
},
|
|
95
|
+
terms: [
|
|
96
|
+
{offset: 0, value: '654 Cedar Lane'},
|
|
97
|
+
{offset: 15, value: 'Seattle'},
|
|
98
|
+
{offset: 23, value: 'WA'},
|
|
99
|
+
{offset: 26, value: '98101'},
|
|
100
|
+
{offset: 32, value: 'USA'}
|
|
101
|
+
],
|
|
102
|
+
types: ['street_address']
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
description: '987 Maple Drive, Austin, TX 78701, USA',
|
|
106
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
107
|
+
place_id: 'ChIJ9876543210',
|
|
108
|
+
reference: 'ref_9876543210',
|
|
109
|
+
structured_formatting: {
|
|
110
|
+
main_text: '987 Maple Drive',
|
|
111
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
112
|
+
secondary_text: 'Austin, TX 78701, USA'
|
|
113
|
+
},
|
|
114
|
+
terms: [
|
|
115
|
+
{offset: 0, value: '987 Maple Drive'},
|
|
116
|
+
{offset: 15, value: 'Austin'},
|
|
117
|
+
{offset: 22, value: 'TX'},
|
|
118
|
+
{offset: 25, value: '78701'},
|
|
119
|
+
{offset: 31, value: 'USA'}
|
|
120
|
+
],
|
|
121
|
+
types: ['street_address']
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
description: '147 Broadway, New York, NY 10038, USA',
|
|
125
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
126
|
+
place_id: 'ChIJ1472583690',
|
|
127
|
+
reference: 'ref_1472583690',
|
|
128
|
+
structured_formatting: {
|
|
129
|
+
main_text: '147 Broadway',
|
|
130
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
131
|
+
secondary_text: 'New York, NY 10038, USA'
|
|
132
|
+
},
|
|
133
|
+
terms: [
|
|
134
|
+
{offset: 0, value: '147 Broadway'},
|
|
135
|
+
{offset: 13, value: 'New York'},
|
|
136
|
+
{offset: 23, value: 'NY'},
|
|
137
|
+
{offset: 26, value: '10038'},
|
|
138
|
+
{offset: 33, value: 'USA'}
|
|
139
|
+
],
|
|
140
|
+
types: ['street_address']
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
description: '258 Market Street, San Francisco, CA 94102, USA',
|
|
144
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
145
|
+
place_id: 'ChIJ2583691470',
|
|
146
|
+
reference: 'ref_2583691470',
|
|
147
|
+
structured_formatting: {
|
|
148
|
+
main_text: '258 Market Street',
|
|
149
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
150
|
+
secondary_text: 'San Francisco, CA 94102, USA'
|
|
151
|
+
},
|
|
152
|
+
terms: [
|
|
153
|
+
{offset: 0, value: '258 Market Street'},
|
|
154
|
+
{offset: 18, value: 'San Francisco'},
|
|
155
|
+
{offset: 33, value: 'CA'},
|
|
156
|
+
{offset: 36, value: '94102'},
|
|
157
|
+
{offset: 42, value: 'USA'}
|
|
158
|
+
],
|
|
159
|
+
types: ['street_address']
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
description: '369 State Street, Boston, MA 02101, USA',
|
|
163
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
164
|
+
place_id: 'ChIJ3691472580',
|
|
165
|
+
reference: 'ref_3691472580',
|
|
166
|
+
structured_formatting: {
|
|
167
|
+
main_text: '369 State Street',
|
|
168
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
169
|
+
secondary_text: 'Boston, MA 02101, USA'
|
|
170
|
+
},
|
|
171
|
+
terms: [
|
|
172
|
+
{offset: 0, value: '369 State Street'},
|
|
173
|
+
{offset: 16, value: 'Boston'},
|
|
174
|
+
{offset: 23, value: 'MA'},
|
|
175
|
+
{offset: 26, value: '02101'},
|
|
176
|
+
{offset: 32, value: 'USA'}
|
|
177
|
+
],
|
|
178
|
+
types: ['street_address']
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
description: '159 Washington Avenue, Philadelphia, PA 19101, USA',
|
|
182
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
183
|
+
place_id: 'ChIJ1592583691',
|
|
184
|
+
reference: 'ref_1592583691',
|
|
185
|
+
structured_formatting: {
|
|
186
|
+
main_text: '159 Washington Avenue',
|
|
187
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
188
|
+
secondary_text: 'Philadelphia, PA 19101, USA'
|
|
189
|
+
},
|
|
190
|
+
terms: [
|
|
191
|
+
{offset: 0, value: '159 Washington Avenue'},
|
|
192
|
+
{offset: 22, value: 'Philadelphia'},
|
|
193
|
+
{offset: 35, value: 'PA'},
|
|
194
|
+
{offset: 38, value: '19101'},
|
|
195
|
+
{offset: 44, value: 'USA'}
|
|
196
|
+
],
|
|
197
|
+
types: ['street_address']
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
description: '42 Wallaby Way, Sydney, NSW 2000, Australia',
|
|
201
|
+
matched_substrings: [{length: 2, offset: 0}],
|
|
202
|
+
place_id: 'ChIJ42wallabyway',
|
|
203
|
+
reference: 'ref_42wallabyway',
|
|
204
|
+
structured_formatting: {
|
|
205
|
+
main_text: '42 Wallaby Way',
|
|
206
|
+
main_text_matched_substrings: [{length: 2, offset: 0}],
|
|
207
|
+
secondary_text: 'Sydney, NSW 2000, Australia'
|
|
208
|
+
},
|
|
209
|
+
terms: [
|
|
210
|
+
{offset: 0, value: '42 Wallaby Way'},
|
|
211
|
+
{offset: 15, value: 'Sydney'},
|
|
212
|
+
{offset: 22, value: 'NSW'},
|
|
213
|
+
{offset: 26, value: '2000'},
|
|
214
|
+
{offset: 31, value: 'Australia'}
|
|
215
|
+
],
|
|
216
|
+
types: ['street_address']
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
description: '221B Baker Street, London, UK NW1 6XE',
|
|
220
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
221
|
+
place_id: 'ChIJ221bbakerstreet',
|
|
222
|
+
reference: 'ref_221bbakerstreet',
|
|
223
|
+
structured_formatting: {
|
|
224
|
+
main_text: '221B Baker Street',
|
|
225
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
226
|
+
secondary_text: 'London, UK NW1 6XE'
|
|
227
|
+
},
|
|
228
|
+
terms: [
|
|
229
|
+
{offset: 0, value: '221B Baker Street'},
|
|
230
|
+
{offset: 18, value: 'London'},
|
|
231
|
+
{offset: 25, value: 'UK'},
|
|
232
|
+
{offset: 28, value: 'NW1 6XE'}
|
|
233
|
+
],
|
|
234
|
+
types: ['street_address']
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
description: '1600 Pennsylvania Avenue NW, Washington, DC 20500, USA',
|
|
238
|
+
matched_substrings: [{length: 4, offset: 0}],
|
|
239
|
+
place_id: 'ChIJ1600pennsylvania',
|
|
240
|
+
reference: 'ref_1600pennsylvania',
|
|
241
|
+
structured_formatting: {
|
|
242
|
+
main_text: '1600 Pennsylvania Avenue NW',
|
|
243
|
+
main_text_matched_substrings: [{length: 4, offset: 0}],
|
|
244
|
+
secondary_text: 'Washington, DC 20500, USA'
|
|
245
|
+
},
|
|
246
|
+
terms: [
|
|
247
|
+
{offset: 0, value: '1600 Pennsylvania Avenue NW'},
|
|
248
|
+
{offset: 28, value: 'Washington'},
|
|
249
|
+
{offset: 39, value: 'DC'},
|
|
250
|
+
{offset: 42, value: '20500'},
|
|
251
|
+
{offset: 48, value: 'USA'}
|
|
252
|
+
],
|
|
253
|
+
types: ['street_address']
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
description: '1 Infinite Loop, Cupertino, CA 95014, USA',
|
|
257
|
+
matched_substrings: [{length: 1, offset: 0}],
|
|
258
|
+
place_id: 'ChIJ1infiniteloop',
|
|
259
|
+
reference: 'ref_1infiniteloop',
|
|
260
|
+
structured_formatting: {
|
|
261
|
+
main_text: '1 Infinite Loop',
|
|
262
|
+
main_text_matched_substrings: [{length: 1, offset: 0}],
|
|
263
|
+
secondary_text: 'Cupertino, CA 95014, USA'
|
|
264
|
+
},
|
|
265
|
+
terms: [
|
|
266
|
+
{offset: 0, value: '1 Infinite Loop'},
|
|
267
|
+
{offset: 16, value: 'Cupertino'},
|
|
268
|
+
{offset: 26, value: 'CA'},
|
|
269
|
+
{offset: 29, value: '95014'},
|
|
270
|
+
{offset: 35, value: 'USA'}
|
|
271
|
+
],
|
|
272
|
+
types: ['street_address']
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
description: '350 Fifth Avenue, New York, NY 10118, USA',
|
|
276
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
277
|
+
place_id: 'ChIJ350fifthavenue',
|
|
278
|
+
reference: 'ref_350fifthavenue',
|
|
279
|
+
structured_formatting: {
|
|
280
|
+
main_text: '350 Fifth Avenue',
|
|
281
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
282
|
+
secondary_text: 'New York, NY 10118, USA'
|
|
283
|
+
},
|
|
284
|
+
terms: [
|
|
285
|
+
{offset: 0, value: '350 Fifth Avenue'},
|
|
286
|
+
{offset: 17, value: 'New York'},
|
|
287
|
+
{offset: 27, value: 'NY'},
|
|
288
|
+
{offset: 30, value: '10118'},
|
|
289
|
+
{offset: 36, value: 'USA'}
|
|
290
|
+
],
|
|
291
|
+
types: ['street_address']
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
description: '1234 Tech Boulevard, San Jose, CA 95113, USA',
|
|
295
|
+
matched_substrings: [{length: 4, offset: 0}],
|
|
296
|
+
place_id: 'ChIJ1234techblvd',
|
|
297
|
+
reference: 'ref_1234techblvd',
|
|
298
|
+
structured_formatting: {
|
|
299
|
+
main_text: '1234 Tech Boulevard',
|
|
300
|
+
main_text_matched_substrings: [{length: 4, offset: 0}],
|
|
301
|
+
secondary_text: 'San Jose, CA 95113, USA'
|
|
302
|
+
},
|
|
303
|
+
terms: [
|
|
304
|
+
{offset: 0, value: '1234 Tech Boulevard'},
|
|
305
|
+
{offset: 19, value: 'San Jose'},
|
|
306
|
+
{offset: 28, value: 'CA'},
|
|
307
|
+
{offset: 31, value: '95113'},
|
|
308
|
+
{offset: 37, value: 'USA'}
|
|
309
|
+
],
|
|
310
|
+
types: ['street_address']
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
description: '567 Innovation Drive, Mountain View, CA 94043, USA',
|
|
314
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
315
|
+
place_id: 'ChIJ567innovation',
|
|
316
|
+
reference: 'ref_567innovation',
|
|
317
|
+
structured_formatting: {
|
|
318
|
+
main_text: '567 Innovation Drive',
|
|
319
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
320
|
+
secondary_text: 'Mountain View, CA 94043, USA'
|
|
321
|
+
},
|
|
322
|
+
terms: [
|
|
323
|
+
{offset: 0, value: '567 Innovation Drive'},
|
|
324
|
+
{offset: 20, value: 'Mountain View'},
|
|
325
|
+
{offset: 33, value: 'CA'},
|
|
326
|
+
{offset: 36, value: '94043'},
|
|
327
|
+
{offset: 42, value: 'USA'}
|
|
328
|
+
],
|
|
329
|
+
types: ['street_address']
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
description: '890 Startup Circle, Palo Alto, CA 94301, USA',
|
|
333
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
334
|
+
place_id: 'ChIJ890startup',
|
|
335
|
+
reference: 'ref_890startup',
|
|
336
|
+
structured_formatting: {
|
|
337
|
+
main_text: '890 Startup Circle',
|
|
338
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
339
|
+
secondary_text: 'Palo Alto, CA 94301, USA'
|
|
340
|
+
},
|
|
341
|
+
terms: [
|
|
342
|
+
{offset: 0, value: '890 Startup Circle'},
|
|
343
|
+
{offset: 18, value: 'Palo Alto'},
|
|
344
|
+
{offset: 28, value: 'CA'},
|
|
345
|
+
{offset: 31, value: '94301'},
|
|
346
|
+
{offset: 37, value: 'USA'}
|
|
347
|
+
],
|
|
348
|
+
types: ['street_address']
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
description: '234 Venture Way, Menlo Park, CA 94025, USA',
|
|
352
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
353
|
+
place_id: 'ChIJ234venture',
|
|
354
|
+
reference: 'ref_234venture',
|
|
355
|
+
structured_formatting: {
|
|
356
|
+
main_text: '234 Venture Way',
|
|
357
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
358
|
+
secondary_text: 'Menlo Park, CA 94025, USA'
|
|
359
|
+
},
|
|
360
|
+
terms: [
|
|
361
|
+
{offset: 0, value: '234 Venture Way'},
|
|
362
|
+
{offset: 16, value: 'Menlo Park'},
|
|
363
|
+
{offset: 27, value: 'CA'},
|
|
364
|
+
{offset: 30, value: '94025'},
|
|
365
|
+
{offset: 36, value: 'USA'}
|
|
366
|
+
],
|
|
367
|
+
types: ['street_address']
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
description: '789 Silicon Valley Road, Santa Clara, CA 95054, USA',
|
|
371
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
372
|
+
place_id: 'ChIJ789silicon',
|
|
373
|
+
reference: 'ref_789silicon',
|
|
374
|
+
structured_formatting: {
|
|
375
|
+
main_text: '789 Silicon Valley Road',
|
|
376
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
377
|
+
secondary_text: 'Santa Clara, CA 95054, USA'
|
|
378
|
+
},
|
|
379
|
+
terms: [
|
|
380
|
+
{offset: 0, value: '789 Silicon Valley Road'},
|
|
381
|
+
{offset: 24, value: 'Santa Clara'},
|
|
382
|
+
{offset: 35, value: 'CA'},
|
|
383
|
+
{offset: 38, value: '95054'},
|
|
384
|
+
{offset: 44, value: 'USA'}
|
|
385
|
+
],
|
|
386
|
+
types: ['street_address']
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
description: '123 Yonge Street, Toronto, ON M5C 1W4, Canada',
|
|
390
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
391
|
+
place_id: 'ChIJ123yonge',
|
|
392
|
+
reference: 'ref_123yonge',
|
|
393
|
+
structured_formatting: {
|
|
394
|
+
main_text: '123 Yonge Street',
|
|
395
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
396
|
+
secondary_text: 'Toronto, ON M5C 1W4, Canada'
|
|
397
|
+
},
|
|
398
|
+
terms: [
|
|
399
|
+
{offset: 0, value: '123 Yonge Street'},
|
|
400
|
+
{offset: 16, value: 'Toronto'},
|
|
401
|
+
{offset: 24, value: 'ON'},
|
|
402
|
+
{offset: 27, value: 'M5C 1W4'},
|
|
403
|
+
{offset: 35, value: 'Canada'}
|
|
404
|
+
],
|
|
405
|
+
types: ['street_address']
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
description: '456 Robson Street, Vancouver, BC V6B 2A3, Canada',
|
|
409
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
410
|
+
place_id: 'ChIJ456robson',
|
|
411
|
+
reference: 'ref_456robson',
|
|
412
|
+
structured_formatting: {
|
|
413
|
+
main_text: '456 Robson Street',
|
|
414
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
415
|
+
secondary_text: 'Vancouver, BC V6B 2A3, Canada'
|
|
416
|
+
},
|
|
417
|
+
terms: [
|
|
418
|
+
{offset: 0, value: '456 Robson Street'},
|
|
419
|
+
{offset: 17, value: 'Vancouver'},
|
|
420
|
+
{offset: 26, value: 'BC'},
|
|
421
|
+
{offset: 29, value: 'V6B 2A3'},
|
|
422
|
+
{offset: 37, value: 'Canada'}
|
|
423
|
+
],
|
|
424
|
+
types: ['street_address']
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
description: '789 Sainte-Catherine Street, Montreal, QC H3B 1B1, Canada',
|
|
428
|
+
matched_substrings: [{length: 3, offset: 0}],
|
|
429
|
+
place_id: 'ChIJ789sainte',
|
|
430
|
+
reference: 'ref_789sainte',
|
|
431
|
+
structured_formatting: {
|
|
432
|
+
main_text: '789 Sainte-Catherine Street',
|
|
433
|
+
main_text_matched_substrings: [{length: 3, offset: 0}],
|
|
434
|
+
secondary_text: 'Montreal, QC H3B 1B1, Canada'
|
|
435
|
+
},
|
|
436
|
+
terms: [
|
|
437
|
+
{offset: 0, value: '789 Sainte-Catherine Street'},
|
|
438
|
+
{offset: 28, value: 'Montreal'},
|
|
439
|
+
{offset: 36, value: 'QC'},
|
|
440
|
+
{offset: 39, value: 'H3B 1B1'},
|
|
441
|
+
{offset: 47, value: 'Canada'}
|
|
442
|
+
],
|
|
443
|
+
types: ['street_address']
|
|
444
|
+
}
|
|
445
|
+
]
|
|
@@ -41,6 +41,7 @@ import {useToast} from '@salesforce/retail-react-app/app/hooks/use-toast'
|
|
|
41
41
|
import LoadingSpinner from '@salesforce/retail-react-app/app/components/loading-spinner'
|
|
42
42
|
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
|
|
43
43
|
import {useMultiship} from '@salesforce/retail-react-app/app/hooks/use-multiship'
|
|
44
|
+
import {GoogleAPIProvider} from '@salesforce/retail-react-app/app/pages/checkout/util/google-api-provider'
|
|
44
45
|
|
|
45
46
|
const Checkout = () => {
|
|
46
47
|
const {formatMessage} = useIntl()
|
|
@@ -253,8 +254,9 @@ const CheckoutContainer = () => {
|
|
|
253
254
|
return (
|
|
254
255
|
<CheckoutProvider>
|
|
255
256
|
{isDeletingUnavailableItem && <LoadingSpinner wrapperStyles={{height: '100vh'}} />}
|
|
256
|
-
|
|
257
|
-
|
|
257
|
+
<GoogleAPIProvider>
|
|
258
|
+
<Checkout />
|
|
259
|
+
</GoogleAPIProvider>
|
|
258
260
|
<UnavailableProductConfirmationModal
|
|
259
261
|
productItems={basket?.productItems}
|
|
260
262
|
handleUnavailableProducts={handleUnavailableProducts}
|
|
@@ -20,6 +20,13 @@ import {
|
|
|
20
20
|
mockedCustomerProductLists
|
|
21
21
|
} from '@salesforce/retail-react-app/app/mocks/mock-data'
|
|
22
22
|
import mockConfig from '@salesforce/retail-react-app/config/mocks/default'
|
|
23
|
+
import {useMapsLibrary} from '@vis.gl/react-google-maps'
|
|
24
|
+
|
|
25
|
+
// Mock Google Maps API
|
|
26
|
+
jest.mock('@vis.gl/react-google-maps', () => ({
|
|
27
|
+
useMapsLibrary: jest.fn(),
|
|
28
|
+
APIProvider: ({children}) => children
|
|
29
|
+
}))
|
|
23
30
|
|
|
24
31
|
// This is a flaky test file!
|
|
25
32
|
jest.retryTimes(5)
|
|
@@ -512,6 +519,205 @@ test('Can proceed through checkout as registered customer', async () => {
|
|
|
512
519
|
document.cookie = ''
|
|
513
520
|
})
|
|
514
521
|
|
|
522
|
+
test('Uses google address autocomplete when a platform provided google API key is provided by the shopper configuration API', async () => {
|
|
523
|
+
// Mock Google Maps API and useAutocompleteSuggestions hook
|
|
524
|
+
const mockFetchAutocompleteSuggestions = jest.fn()
|
|
525
|
+
const mockAutocompleteSuggestion = {
|
|
526
|
+
fetchAutocompleteSuggestions: mockFetchAutocompleteSuggestions
|
|
527
|
+
}
|
|
528
|
+
const mockAutocompleteSessionToken = jest.fn()
|
|
529
|
+
const mockPlaces = {
|
|
530
|
+
AutocompleteSessionToken: mockAutocompleteSessionToken,
|
|
531
|
+
AutocompleteSuggestion: mockAutocompleteSuggestion
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
useMapsLibrary.mockReturnValue(mockPlaces)
|
|
535
|
+
|
|
536
|
+
// Keep a *deep* copy of the initial mocked basket. Our mocked fetch responses will continuously
|
|
537
|
+
// update this object, which essentially mimics a saved basket on the backend.
|
|
538
|
+
let currentBasket = JSON.parse(JSON.stringify(scapiBasketWithItem))
|
|
539
|
+
|
|
540
|
+
// Set the default shipping method in the initial basket state
|
|
541
|
+
currentBasket.shipments[0].shippingMethod = defaultShippingMethod
|
|
542
|
+
|
|
543
|
+
// Set up additional requests for intercepting/mocking for just this test.
|
|
544
|
+
global.server.use(
|
|
545
|
+
// mock adding guest email to basket
|
|
546
|
+
rest.put('*/baskets/:basketId/customer', (req, res, ctx) => {
|
|
547
|
+
currentBasket.customerInfo.email = 'test@test.com'
|
|
548
|
+
return res(ctx.json(currentBasket))
|
|
549
|
+
}),
|
|
550
|
+
|
|
551
|
+
rest.get('*/configuration/shopper-configurations/*/configurations', (req, res, ctx) => {
|
|
552
|
+
const configurations = {
|
|
553
|
+
configurations: [
|
|
554
|
+
{
|
|
555
|
+
id: 'gcp',
|
|
556
|
+
value: 'platform-provided-key'
|
|
557
|
+
}
|
|
558
|
+
]
|
|
559
|
+
}
|
|
560
|
+
return res(ctx.json(configurations))
|
|
561
|
+
}),
|
|
562
|
+
|
|
563
|
+
// mock add shipping and billing address to basket
|
|
564
|
+
rest.put('*/shipping-address', (req, res, ctx) => {
|
|
565
|
+
const shippingBillingAddress = {
|
|
566
|
+
address1: '123 Main St',
|
|
567
|
+
city: 'Tampa',
|
|
568
|
+
countryCode: 'US',
|
|
569
|
+
firstName: 'Tester',
|
|
570
|
+
fullName: 'Tester McTesting',
|
|
571
|
+
id: '047b18d4aaaf4138f693a4b931',
|
|
572
|
+
lastName: 'McTesting',
|
|
573
|
+
phone: '(727) 555-1234',
|
|
574
|
+
postalCode: '33610',
|
|
575
|
+
stateCode: 'FL'
|
|
576
|
+
}
|
|
577
|
+
currentBasket.shipments[0].shippingAddress = shippingBillingAddress
|
|
578
|
+
currentBasket.billingAddress = shippingBillingAddress
|
|
579
|
+
return res(ctx.json(currentBasket))
|
|
580
|
+
}),
|
|
581
|
+
|
|
582
|
+
// mock add billing address to basket
|
|
583
|
+
rest.put('*/billing-address', (req, res, ctx) => {
|
|
584
|
+
const shippingBillingAddress = {
|
|
585
|
+
address1: '123 Main St',
|
|
586
|
+
city: 'Tampa',
|
|
587
|
+
countryCode: 'US',
|
|
588
|
+
firstName: 'Tester',
|
|
589
|
+
fullName: 'Tester McTesting',
|
|
590
|
+
id: '047b18d4aaaf4138f693a4b931',
|
|
591
|
+
lastName: 'McTesting',
|
|
592
|
+
phone: '(727) 555-1234',
|
|
593
|
+
postalCode: '33610',
|
|
594
|
+
stateCode: 'FL'
|
|
595
|
+
}
|
|
596
|
+
currentBasket.shipments[0].shippingAddress = shippingBillingAddress
|
|
597
|
+
currentBasket.billingAddress = shippingBillingAddress
|
|
598
|
+
return res(ctx.json(currentBasket))
|
|
599
|
+
}),
|
|
600
|
+
|
|
601
|
+
// mock add shipping method
|
|
602
|
+
rest.put('*/shipments/me/shipping-method', (req, res, ctx) => {
|
|
603
|
+
currentBasket.shipments[0].shippingMethod = defaultShippingMethod
|
|
604
|
+
return res(ctx.json(currentBasket))
|
|
605
|
+
}),
|
|
606
|
+
|
|
607
|
+
// mock add payment instrument
|
|
608
|
+
rest.post('*/baskets/:basketId/payment-instruments', (req, res, ctx) => {
|
|
609
|
+
currentBasket.paymentInstruments = [
|
|
610
|
+
{
|
|
611
|
+
amount: 0,
|
|
612
|
+
paymentCard: {
|
|
613
|
+
cardType: 'Visa',
|
|
614
|
+
creditCardExpired: false,
|
|
615
|
+
expirationMonth: 1,
|
|
616
|
+
expirationYear: 2040,
|
|
617
|
+
holder: 'Testy McTester',
|
|
618
|
+
maskedNumber: '************1111',
|
|
619
|
+
numberLastDigits: '1111',
|
|
620
|
+
validFromMonth: 1,
|
|
621
|
+
validFromYear: 2020
|
|
622
|
+
},
|
|
623
|
+
paymentInstrumentId: '875cae2724408c9a3eb45715ba',
|
|
624
|
+
paymentMethodId: 'CREDIT_CARD'
|
|
625
|
+
}
|
|
626
|
+
]
|
|
627
|
+
return res(ctx.json(currentBasket))
|
|
628
|
+
}),
|
|
629
|
+
|
|
630
|
+
// mock place order
|
|
631
|
+
rest.post('*/orders', (req, res, ctx) => {
|
|
632
|
+
const response = {
|
|
633
|
+
...currentBasket,
|
|
634
|
+
...scapiOrderResponse,
|
|
635
|
+
customerInfo: {...scapiOrderResponse.customerInfo, email: 'customer@test.com'},
|
|
636
|
+
status: 'created'
|
|
637
|
+
}
|
|
638
|
+
return res(ctx.json(response))
|
|
639
|
+
}),
|
|
640
|
+
|
|
641
|
+
rest.get('*/baskets', (req, res, ctx) => {
|
|
642
|
+
const baskets = {
|
|
643
|
+
baskets: [currentBasket],
|
|
644
|
+
total: 1
|
|
645
|
+
}
|
|
646
|
+
return res(ctx.json(baskets))
|
|
647
|
+
})
|
|
648
|
+
)
|
|
649
|
+
|
|
650
|
+
// Set the initial browser router path and render our component tree.
|
|
651
|
+
window.history.pushState({}, 'Checkout', createPathWithDefaults('/checkout'))
|
|
652
|
+
const {user} = renderWithProviders(<WrappedCheckout history={history} />, {
|
|
653
|
+
wrapperProps: {isGuest: true, siteAlias: 'uk', appConfig: mockConfig.app}
|
|
654
|
+
})
|
|
655
|
+
|
|
656
|
+
// Wait for checkout to load and display first step
|
|
657
|
+
await screen.findByText(/checkout as guest/i)
|
|
658
|
+
|
|
659
|
+
// Verify cart products display
|
|
660
|
+
await user.click(screen.getByText(/2 items in cart/i))
|
|
661
|
+
expect(await screen.findByText(/Long Sleeve Crew Neck$/i)).toBeInTheDocument()
|
|
662
|
+
|
|
663
|
+
// Verify password field is reset if customer toggles login form
|
|
664
|
+
const loginToggleButton = screen.getByText(/Already have an account\? Log in/i)
|
|
665
|
+
await user.click(loginToggleButton)
|
|
666
|
+
// Provide customer email and submit
|
|
667
|
+
const passwordInput = document.querySelector('input[type="password"]')
|
|
668
|
+
await user.type(passwordInput, 'Password1!')
|
|
669
|
+
|
|
670
|
+
const checkoutAsGuestButton = screen.getByText(/Checkout as guest/i)
|
|
671
|
+
await user.click(checkoutAsGuestButton)
|
|
672
|
+
|
|
673
|
+
// Provide customer email and submit
|
|
674
|
+
const emailInput = screen.getByLabelText(/email/i)
|
|
675
|
+
const submitBtn = screen.getByText(/checkout as guest/i)
|
|
676
|
+
await user.type(emailInput, 'test@test.com')
|
|
677
|
+
await user.click(submitBtn)
|
|
678
|
+
|
|
679
|
+
// Wait for next step to render
|
|
680
|
+
await waitFor(() => {
|
|
681
|
+
expect(screen.getByTestId('sf-toggle-card-step-1-content')).not.toBeEmptyDOMElement()
|
|
682
|
+
})
|
|
683
|
+
|
|
684
|
+
// Email should be displayed in previous step summary
|
|
685
|
+
expect(screen.getByText('test@test.com')).toBeInTheDocument()
|
|
686
|
+
|
|
687
|
+
// Shipping Address Form must be present
|
|
688
|
+
expect(screen.getByLabelText('Shipping Address Form')).toBeInTheDocument()
|
|
689
|
+
|
|
690
|
+
// Fill out shipping address form and submit
|
|
691
|
+
await user.type(screen.getByLabelText(/first name/i), 'Tester')
|
|
692
|
+
await user.type(screen.getByLabelText(/last name/i), 'McTesting')
|
|
693
|
+
await user.type(screen.getByLabelText(/phone/i), '(727) 555-1234')
|
|
694
|
+
await user.type(screen.getAllByLabelText(/address/i)[0], '123 Main St')
|
|
695
|
+
await user.type(screen.getByLabelText(/city/i), 'Tampa')
|
|
696
|
+
await user.selectOptions(screen.getByLabelText(/state/i), ['FL'])
|
|
697
|
+
await user.type(screen.getByLabelText(/zip code/i), '33610')
|
|
698
|
+
await user.click(screen.getByText(/continue to shipping method/i))
|
|
699
|
+
|
|
700
|
+
// Wait for next step to render
|
|
701
|
+
await waitFor(() => {
|
|
702
|
+
expect(screen.getByTestId('sf-toggle-card-step-2-content')).not.toBeEmptyDOMElement()
|
|
703
|
+
expect(mockFetchAutocompleteSuggestions).toHaveBeenCalled()
|
|
704
|
+
})
|
|
705
|
+
|
|
706
|
+
// Shipping address displayed in previous step summary
|
|
707
|
+
const step1Content = within(screen.getByTestId('sf-toggle-card-step-1-content'))
|
|
708
|
+
expect(step1Content.getByText('Tester McTesting')).toBeInTheDocument()
|
|
709
|
+
expect(step1Content.getByText('123 Main St')).toBeInTheDocument()
|
|
710
|
+
expect(step1Content.getByText('Tampa, FL 33610')).toBeInTheDocument()
|
|
711
|
+
expect(step1Content.getByText('US')).toBeInTheDocument()
|
|
712
|
+
|
|
713
|
+
// Applied shipping method should be displayed in previous step summary
|
|
714
|
+
expect(screen.getByText(defaultShippingMethod.name)).toBeInTheDocument()
|
|
715
|
+
|
|
716
|
+
// Verify checkout container is present
|
|
717
|
+
expect(screen.getByTestId('sf-checkout-container')).toBeInTheDocument()
|
|
718
|
+
document.cookie = ''
|
|
719
|
+
})
|
|
720
|
+
|
|
515
721
|
test('Can edit address during checkout as a registered customer', async () => {
|
|
516
722
|
// Set the initial browser router path and render our component tree.
|
|
517
723
|
window.history.pushState({}, 'Checkout', createPathWithDefaults('/checkout'))
|