Skip to content

Commit 8c3ae14

Browse files
committed
fix: keep customer address selected after delivery step
1 parent 01fec85 commit 8c3ae14

3 files changed

Lines changed: 88 additions & 6 deletions

File tree

components/data/AppProvider/index.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ export const AppProvider: React.FC<AppProviderProps> = ({
172172
if (state.order) {
173173
dispatch({ type: ActionType.START_LOADING })
174174

175-
const others = calculateSettings(order, state.isShipmentRequired)
175+
const others = calculateSettings(
176+
order,
177+
state.isShipmentRequired,
178+
state.customerAddresses
179+
)
176180

177181
dispatch({
178182
type: ActionType.CHANGE_COUPON_OR_GIFTCARD,
@@ -190,7 +194,11 @@ export const AppProvider: React.FC<AppProviderProps> = ({
190194
// TODO Remove after fixing components
191195
const order = await fetchOrder(cl, orderId)
192196

193-
const others = calculateSettings(order, state.isShipmentRequired)
197+
const others = calculateSettings(
198+
order,
199+
state.isShipmentRequired,
200+
state.customerAddresses
201+
)
194202

195203
dispatch({
196204
type: ActionType.SELECT_SHIPMENT,
@@ -209,7 +217,11 @@ export const AppProvider: React.FC<AppProviderProps> = ({
209217
dispatch({ type: ActionType.START_LOADING })
210218

211219
const order = await fetchOrder(cl, orderId)
212-
const others = calculateSettings(order, state.isShipmentRequired)
220+
const others = calculateSettings(
221+
order,
222+
state.isShipmentRequired,
223+
state.customerAddresses
224+
)
213225

214226
dispatch({
215227
type: ActionType.SAVE_SHIPMENTS,
@@ -223,8 +235,12 @@ export const AppProvider: React.FC<AppProviderProps> = ({
223235
const saveShipments = async () => {
224236
dispatch({ type: ActionType.START_LOADING })
225237
const order = await getOrderFromRef()
226-
227-
const others = calculateSettings(order, state.isShipmentRequired)
238+
console.log(order)
239+
const others = calculateSettings(
240+
order,
241+
state.isShipmentRequired,
242+
state.customerAddresses
243+
)
228244

229245
setTimeout(() => {
230246
dispatch({
@@ -238,7 +254,11 @@ export const AppProvider: React.FC<AppProviderProps> = ({
238254
dispatch({ type: ActionType.START_LOADING })
239255
const order = await getOrderFromRef()
240256

241-
const others = calculateSettings(order, state.isShipmentRequired)
257+
const others = calculateSettings(
258+
order,
259+
state.isShipmentRequired,
260+
state.customerAddresses
261+
)
242262

243263
dispatch({
244264
type: ActionType.SET_PAYMENT,

specs/e2e/customer-addresses-with-wallet.spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,57 @@ test.describe("two address on wallet and code lock", () => {
429429
})
430430
})
431431
})
432+
433+
test.describe("one address on wallet", () => {
434+
const customerEmail = faker.internet.email().toLocaleLowerCase()
435+
const customerPassword = faker.internet.password()
436+
437+
test.use({
438+
defaultParams: {
439+
order: "with-items",
440+
customer: {
441+
email: customerEmail,
442+
password: customerPassword,
443+
},
444+
lineItemsAttributes: [
445+
{ sku_code: "CANVASAU000000FFFFFF1824", quantity: 1 },
446+
],
447+
customerAddresses: [euAddress],
448+
},
449+
})
450+
451+
test("check addresses", async ({ checkoutPage }) => {
452+
await checkoutPage.checkOrderSummary("Order Summary")
453+
454+
await checkoutPage.page.locator(`text=${customerEmail}`)
455+
456+
await checkoutPage.checkStep("Shipping", "open")
457+
458+
await checkoutPage.clickStep("Customer")
459+
460+
let element = await checkoutPage.page.locator(
461+
"[data-test-id=customer-billing-address]"
462+
)
463+
await expect(element).toHaveCount(1)
464+
465+
await checkoutPage.save("Customer")
466+
467+
await checkoutPage.checkStep("Customer", "close")
468+
await checkoutPage.checkStep("Shipping", "open")
469+
470+
await expect(
471+
checkoutPage.page.locator("text=Standard Shipping")
472+
).toBeVisible()
473+
await checkoutPage.selectShippingMethod({ text: "Standard Shipping" })
474+
475+
await checkoutPage.checkShippingSummary("FREE")
476+
await checkoutPage.save("Shipping")
477+
478+
await checkoutPage.clickStep("Customer")
479+
480+
element = await checkoutPage.page.locator(
481+
"[data-test-id=customer-billing-address]"
482+
)
483+
await expect(element).toHaveCount(1)
484+
})
485+
})

specs/e2e/shipments-multiple.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ test.describe("with two shipments", () => {
3535

3636
await checkoutPage.checkShippingSummary("To be calculated")
3737

38+
await checkoutPage.page.waitForTimeout(TIMEOUT)
39+
3840
await checkoutPage.selectShippingMethod({
3941
text: "Standard Shipping",
4042
shipment: 0,
@@ -55,12 +57,15 @@ test.describe("with two shipments", () => {
5557
await checkoutPage.checkStep("Payment", "open")
5658

5759
await checkoutPage.clickStep("Shipping")
60+
await checkoutPage.page.waitForTimeout(TIMEOUT)
5861

5962
await checkoutPage.checkSelectedShippingMethod({
6063
index: 0,
6164
shipment: 0,
6265
value: true,
6366
})
67+
await checkoutPage.page.waitForTimeout(TIMEOUT)
68+
6469
await checkoutPage.checkSelectedShippingMethod({
6570
index: 0,
6671
shipment: 1,
@@ -100,6 +105,7 @@ test.describe("with two shipments", () => {
100105
shipment: 1,
101106
value: true,
102107
})
108+
await checkoutPage.page.waitForTimeout(TIMEOUT)
103109

104110
await checkoutPage.selectShippingMethod({
105111
text: "Express Delivery",
@@ -114,6 +120,8 @@ test.describe("with two shipments", () => {
114120
await checkoutPage.page.waitForTimeout(TIMEOUT)
115121

116122
await checkoutPage.save("Shipping")
123+
await checkoutPage.page.waitForTimeout(TIMEOUT)
124+
117125
await checkoutPage.checkStep("Shipping", "close")
118126
await checkoutPage.checkStep("Payment", "open")
119127
await checkoutPage.clickStep("Shipping")

0 commit comments

Comments
 (0)