From 93f5dcebf81aafb9049991c7c9d856c54474e661 Mon Sep 17 00:00:00 2001 From: Renata Date: Fri, 5 Jul 2024 11:18:50 +0200 Subject: [PATCH] test_for_manual_refund (#5018) --- .changeset/early-vans-relate.md | 5 ++++ playwright/data/e2eTestData.ts | 2 ++ playwright/pages/ordersPage.ts | 1 + playwright/pages/refundPage.ts | 19 +++++++++++++++ playwright/tests/orders.spec.ts | 23 +++++++++++++++++++ .../OrderManualTransactionRefundAmount.tsx | 2 +- .../OrderTransactionTileEvent.tsx | 1 + .../OrderTransactionTileRoot.tsx | 1 + 8 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .changeset/early-vans-relate.md diff --git a/.changeset/early-vans-relate.md b/.changeset/early-vans-relate.md new file mode 100644 index 00000000000..c84b13edc81 --- /dev/null +++ b/.changeset/early-vans-relate.md @@ -0,0 +1,5 @@ +--- +"saleor-dashboard": minor +--- + +You can now run e2e test for a manual refund type diff --git a/playwright/data/e2eTestData.ts b/playwright/data/e2eTestData.ts index bc02435ff63..fa564bfbb3e 100644 --- a/playwright/data/e2eTestData.ts +++ b/playwright/data/e2eTestData.ts @@ -450,6 +450,8 @@ export const ORDERS = { }, fullyPaidOrderWithSeveralTransactions: { id: "T3JkZXI6MTVhYTEwMzYtZWE3OS00MzJiLTliODctNDhlYTMwYmU1NmNl", + transactionToRefundId: + "VHJhbnNhY3Rpb25JdGVtOjExNzQxZmQ3LWJkZjAtNDIxNi1hNTVkLTFkZDhiNTk4YTA5Mw==", }, partiallyPaidOrder: { id: "T3JkZXI6NmVlMDMwMTctZTViOS00OGNmLWFkYTQtODg4YTQ5MDI3ZjNk", diff --git a/playwright/pages/ordersPage.ts b/playwright/pages/ordersPage.ts index 2f1365bbf4d..8f9ec7a8d8e 100644 --- a/playwright/pages/ordersPage.ts +++ b/playwright/pages/ordersPage.ts @@ -125,6 +125,7 @@ export class OrdersPage extends BasePage { const refund = await this.orderRefundList.locator("tr").filter({ hasText: refundInfo }); await refund.locator(this.editRefundButton).click(); + await this.waitForDOMToFullyLoad(); } async assertRefundOnList(refundInfo: string) { diff --git a/playwright/pages/refundPage.ts b/playwright/pages/refundPage.ts index a5274887fcb..0184f0dd73f 100644 --- a/playwright/pages/refundPage.ts +++ b/playwright/pages/refundPage.ts @@ -14,6 +14,10 @@ export class RefundPage extends OrdersPage { readonly refundReasonInput = page.getByTestId("refund-reason-input"), readonly lineRefundReasonDialog = page.getByTestId("refund-reason-dialog"), readonly lineRefundReasonButton = page.getByTestId("line-refund-reason-button"), + readonly transactionCard = page.getByTestId("transaction-card"), + readonly transactionEventRow = page.getByTestId("transaction-event-row"), + readonly refundAmountInput = page.getByTestId("refund-amount"), + readonly amountErrorMessage = page.getByTestId("error-message"), ) { super(page); this.addLineRefundReasonDialog = new AddLineRefundReasonDialog(page); @@ -76,9 +80,24 @@ export class RefundPage extends OrdersPage { await this.waitForDOMToFullyLoad(); } + async selectTransactionToRefund(transactionId: string) { + await this.waitForDOMToFullyLoad(); + + await this.transactionCard.locator(`id=${transactionId}`).click(); + } + + async provideRefundAmount(amount: string) { + await this.refundAmountInput.fill(""); + await this.refundAmountInput.fill(amount); + } + async transferFunds() { await expect(this.saveButton).toHaveText("Transfer funds"); await this.clickSaveButton(); await this.waitForDOMToFullyLoad(); } + + async expectErrorMessage(error: string) { + expect(this.amountErrorMessage).toHaveText(error); + } } diff --git a/playwright/tests/orders.spec.ts b/playwright/tests/orders.spec.ts index efe39e16625..41bc014e760 100644 --- a/playwright/tests/orders.spec.ts +++ b/playwright/tests/orders.spec.ts @@ -288,3 +288,26 @@ test("TC: SALEOR_191 Refund products from the fully paid order @e2e @refunds", a await refundPage.transferFunds(); await refundPage.expectSuccessBannerMessage("Refund has been sent"); }); + +test("TC: SALEOR_192 Should create a manual refund with a custom amount @e2e @refunds", async () => { + const order = ORDERS.fullyPaidOrderWithSeveralTransactions; + + await ordersPage.goToExistingOrderPage(order.id); + await ordersPage.clickAddRefundButton(); + await ordersPage.orderRefundDialog.pickManualRefund(); + await ordersPage.orderRefundModal.waitFor({ state: "hidden" }); + await refundPage.expectManualRefundPageOpen(order.id); + await refundPage.selectTransactionToRefund(order.transactionToRefundId); + await refundPage.transferFunds(); + await refundPage.expectErrorMessage("You must provide amount value"); + await refundPage.provideRefundAmount("1000"); + await refundPage.expectErrorMessage( + "Provided amount cannot exceed charged amount for the selected transaction", + ); + await refundPage.provideRefundAmount("10"); + await refundPage.transferFunds(); + await refundPage.expectSuccessBannerMessage("Transaction action requested successfully"); + await ordersPage.goToExistingOrderPage(order.id); + await ordersPage.orderRefundSection.waitFor({ state: "visible" }); + await ordersPage.assertRefundOnList("Manual refund"); +}); diff --git a/src/orders/components/OrderManualTransactionRefundPage/components/OrderManualTransactionRefundAmount/OrderManualTransactionRefundAmount.tsx b/src/orders/components/OrderManualTransactionRefundPage/components/OrderManualTransactionRefundAmount/OrderManualTransactionRefundAmount.tsx index c8708fda043..206b2a3a34d 100644 --- a/src/orders/components/OrderManualTransactionRefundPage/components/OrderManualTransactionRefundAmount/OrderManualTransactionRefundAmount.tsx +++ b/src/orders/components/OrderManualTransactionRefundPage/components/OrderManualTransactionRefundAmount/OrderManualTransactionRefundAmount.tsx @@ -39,7 +39,7 @@ export const OrderManualTransactionRefundAmount = ({ {!!error && ( - + {error.message} diff --git a/src/orders/components/OrderTransactionTile/OrderTransactionTileEvent.tsx b/src/orders/components/OrderTransactionTile/OrderTransactionTileEvent.tsx index ff9f8e7fa34..37cf24d23f0 100644 --- a/src/orders/components/OrderTransactionTile/OrderTransactionTileEvent.tsx +++ b/src/orders/components/OrderTransactionTile/OrderTransactionTileEvent.tsx @@ -20,6 +20,7 @@ export const OrderTransactionTileEvent = ({ event }: OrderTransactionTileEventPr return ( { return (