From 70c7f3a2f8d8eb4b48f32cfcc8cd81b8d4eae7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20Szcz=C4=99ch?= <30683248+szczecha@users.noreply.github.com> Date: Thu, 11 May 2023 09:46:33 +0300 Subject: [PATCH] Add e2e for capture transactions in orders (#3567) * Update schema, remove transaction specific files * Merge `.transaction` queries and mutations into regular files * Merge OrderDetails fragments * Remove usage of `.transaction` graphl types * Update fixtures * Remove usage of useFlag, remove duplicated queries & mutations * Fix displayed event type for INFO * Remove type alias from order/types.ts, remove type casting * Fix failing tests * Add preview label and better description in Channel settings * Update button in GrantRefund page * Fix missing data-test-id * add e2e for capture transactions in orders * creates tests for transactions order view switched on --------- Co-authored-by: Jonatan Witoszek Co-authored-by: wojteknowacki --- cypress/e2e/orders/transactionsForOrders.js | 203 ++++++++++++++++++ cypress/elements/index.js | 88 +++----- cypress/elements/orders/index.js | 8 +- cypress/elements/orders/order-grant-refund.js | 9 + cypress/elements/orders/orders-selectors.js | 6 + .../elements/orders/transaction-selectors.js | 6 + cypress/fixtures/index.js | 9 +- cypress/support/api/requests/Channels.js | 34 +++ cypress/support/api/requests/Order.js | 17 +- cypress/support/api/requests/index.js | 3 + cypress/support/api/utils/index.js | 8 + cypress/support/api/utils/ordersUtils.js | 2 +- .../customCommands/basicOperations/index.js | 9 + cypress/support/pages/index.js | 5 +- .../support/pages/ordersTransactionUtils.js | 111 ++++++++++ .../OrderAddTransaction.tsx | 6 +- .../OrderGrantRefundPage.tsx | 5 + .../components/ProductCard.tsx | 6 +- .../components/RefundCard.tsx | 3 + .../components/DescriptionField.tsx | 6 +- .../components/PriceInputField.tsx | 5 + .../components/PspReferenceField.tsx | 6 +- .../components/SubmitButton.tsx | 1 + .../OrderMarkAsPaidDialog.tsx | 1 + .../components/OrderPayment/OrderPayment.tsx | 6 +- .../OrderPaymentSummaryCard.tsx | 7 +- .../OrderTransaction/OrderTransaction.tsx | 5 +- 27 files changed, 491 insertions(+), 84 deletions(-) create mode 100644 cypress/e2e/orders/transactionsForOrders.js create mode 100644 cypress/elements/orders/order-grant-refund.js create mode 100644 cypress/elements/orders/transaction-selectors.js create mode 100644 cypress/support/api/requests/index.js create mode 100644 cypress/support/api/utils/index.js create mode 100644 cypress/support/pages/ordersTransactionUtils.js diff --git a/cypress/e2e/orders/transactionsForOrders.js b/cypress/e2e/orders/transactionsForOrders.js new file mode 100644 index 000000000..a14f941c9 --- /dev/null +++ b/cypress/e2e/orders/transactionsForOrders.js @@ -0,0 +1,203 @@ +/// +/// + +import faker from "faker"; + +import { ORDERS_SELECTORS } from "../../elements/orders/orders-selectors"; +import { ONE_PERMISSION_USERS, urlList } from "../../fixtures"; +import { + createChannel, + createCustomer, + deleteCustomersStartsWith, + getOrder, + updateChannelOrderSettings, +} from "../../support/api/requests"; +import { + createOrder, + createReadyToFulfillOrder, + createShipping, + deleteChannelsStartsWith, + deleteShippingStartsWith, + getDefaultTaxClass, + productsUtils, + updateTaxConfigurationForChannel, +} from "../../support/api/utils"; +import { transactionsOrderUtils } from "../../support/pages/"; + +describe("Orders", () => { + const startsWith = "CyOrders-"; + const randomName = startsWith + faker.datatype.number(); + const randomRefNumber = startsWith + faker.datatype.number(); + const randomPSPNumber = startsWith + faker.datatype.number(); + + let customer; + let channel; + let warehouse; + let shippingMethod; + let variantsList; + let address; + let taxClass; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + deleteChannelsStartsWith(startsWith); + deleteCustomersStartsWith(startsWith); + deleteShippingStartsWith(startsWith); + productsUtils.deleteProductsStartsWith(startsWith); + + createChannel({ name: randomName }) + .then(channelResp => { + channel = channelResp; + + updateChannelOrderSettings({ + channelId: channel.id, + markAsPaidStrategy: "TRANSACTION_FLOW", + }); + updateTaxConfigurationForChannel({ channelSlug: channel.slug }); + getDefaultTaxClass(); + }) + .then(resp => { + taxClass = resp; + cy.fixture("addresses"); + }) + .then(addresses => { + address = addresses.plAddress; + createCustomer(`${randomName}@example.com`, randomName, address, true); + }) + .then(customerResp => { + customer = customerResp.user; + createShipping({ + channelId: channel.id, + name: randomName, + address, + taxClassId: taxClass.id, + }); + }) + .then( + ({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => { + shippingMethod = shippingMethodResp; + warehouse = warehouseResp; + productsUtils.createTypeAttributeAndCategoryForProduct({ + name: randomName, + }); + }, + ) + .then( + ({ + productType: productTypeResp, + attribute: attributeResp, + category: categoryResp, + }) => { + productsUtils.createProductInChannel({ + name: randomName, + channelId: channel.id, + warehouseId: warehouse.id, + productTypeId: productTypeResp.id, + attributeId: attributeResp.id, + categoryId: categoryResp.id, + taxClassId: taxClass.id, + price: 10, + }); + }, + ) + .then(({ variantsList: variantsResp }) => { + variantsList = variantsResp; + cy.checkIfDataAreNotNull({ + customer, + channel, + warehouse, + shippingMethod, + variantsList, + address, + }); + }); + }); + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest( + "auth", + ONE_PERMISSION_USERS.order, + ); + }); + + it( + "should mark order as paid. TC: 3901", + { tags: ["@orders", "@allEnv", "@stable"] }, + () => { + createOrder({ + customerId: customer.id, + shippingMethod, + channelId: channel.id, + variantsList, + address, + }).then(order => { + cy.visit(urlList.orders + `${order.id}`); + transactionsOrderUtils.markAsPaidOrderWithRefNumber(randomRefNumber); + cy.checkIfElementIsVisible(ORDERS_SELECTORS.orderTransactionsList); + getOrder(order.id).then(orderResp => { + expect(orderResp.paymentStatus).to.be.eq("FULLY_CHARGED"); + expect(orderResp.transactions).to.be.not.null; + }); + }); + }, + ); + + it( + "should be able to grant and send refund TC: 3902", + { tags: ["@orders", "@allEnv", "@stable"] }, + () => { + createReadyToFulfillOrder({ + customerId: customer.id, + shippingMethod, + channelId: channel.id, + variantsList, + address, + }).then(({ order: orderResp }) => { + const orderPrice = orderResp.total.gross.amount; + + cy.visit(urlList.orders + `${orderResp.id}`); + cy.checkIfElementNotExist(ORDERS_SELECTORS.markAsPaidButton); + transactionsOrderUtils.grantRefundAllProductsAndShippingWithReason( + "refund reason: wrong size", + orderPrice, + ); + transactionsOrderUtils.sendRefundWithDescriptionPSPAndAmount( + "refund description", + randomPSPNumber, + orderPrice, + ); + getOrder(orderResp.id).then(orderResp => { + expect(orderResp.paymentStatus).to.be.eq("NOT_CHARGED"); + expect(orderResp.transactions).to.be.not.null; + }); + }); + }, + ); + + it( + "should be able to capture manual transaction that covers partial order price TC: 3903", + { tags: ["@orders", "@allEnv", "@stable"] }, + () => { + createOrder({ + customerId: customer.id, + shippingMethod, + channelId: channel.id, + variantsList, + address, + }).then(order => { + const partialOrderPrice = order.total.gross.amount - 1; + + cy.visit(urlList.orders + `${order.id}`); + transactionsOrderUtils.captureManualTransaction( + "Manual capture description", + randomPSPNumber, + partialOrderPrice, + ); + getOrder(order.id).then(orderResp => { + expect(orderResp.paymentStatus).to.be.eq("PARTIALLY_CHARGED"); + expect(orderResp.transactions).to.be.not.null; + }); + }); + }, + ); +}); diff --git a/cypress/elements/index.js b/cypress/elements/index.js index 26b12f042..011dcf98a 100644 --- a/cypress/elements/index.js +++ b/cypress/elements/index.js @@ -1,89 +1,51 @@ -import { +export { LOGIN_SELECTORS, MENU_SELECTORS, SET_PASSWORD_SELECTORS, } from "./account/"; -import { APPS_LIST_SELECTORS } from "./apps"; -import { ATTRIBUTES_DETAILS, ATTRIBUTES_LIST } from "./attribute"; -import { +export { APPS_LIST_SELECTORS } from "./apps"; +export { ATTRIBUTES_DETAILS, ATTRIBUTES_LIST } from "./attribute"; +export { CATEGORIES_LIST_SELECTORS, CATEGORY_DETAILS_SELECTORS, COLLECTION_SELECTORS, PRODUCT_DETAILS, PRODUCTS_LIST, } from "./catalog"; -import { CHANNEL_FORM_SELECTORS, CHANNELS_SELECTORS } from "./channels"; -import { CONFIGURATION_SELECTORS } from "./configuration/configuration-selectors"; -import { +export { CHANNEL_FORM_SELECTORS, CHANNELS_SELECTORS } from "./channels"; +export { CONFIGURATION_SELECTORS } from "./configuration/configuration-selectors"; +export { CUSTOMER_DETAILS_SELECTORS, CUSTOMERS_LIST_SELECTORS, } from "./customer/"; -import { SALES_SELECTORS, VOUCHERS_SELECTORS } from "./discounts"; -import { HOMEPAGE_SELECTORS } from "./homePage/homePage-selectors"; -import { PAGINATION } from "./navigation"; -import { DRAFT_ORDERS_LIST_SELECTORS, ORDERS_SELECTORS } from "./orders"; -import { PAGE_DETAILS_SELECTORS, PAGES_LIST_SELECTORS } from "./pages/"; -import { +export { SALES_SELECTORS, VOUCHERS_SELECTORS } from "./discounts"; +export { HOMEPAGE_SELECTORS } from "./homePage/homePage-selectors"; +export { PAGINATION } from "./navigation"; +export { + DRAFT_ORDERS_LIST_SELECTORS, + ORDER_GRANT_REFUND, + ORDER_TRANSACTION_CREATE, + ORDERS_SELECTORS, +} from "./orders"; +export { PAGE_DETAILS_SELECTORS, PAGES_LIST_SELECTORS } from "./pages/"; +export { PAGE_TYPE_DETAILS_SELECTORS, PAGE_TYPES_LIST_SELECTORS, } from "./pageTypes"; -import { +export { PERMISSION_GROUP_DETAILS_SELECTORS, PERMISSION_GROUP_LIST_SELECTORS, } from "./permissionGroup"; -import { PLUGINS_DETAILS_SELECTORS, PLUGINS_LIST_SELECTORS } from "./plugins"; -import { +export { PLUGINS_DETAILS_SELECTORS, PLUGINS_LIST_SELECTORS } from "./plugins"; +export { PRODUCT_TYPE_DETAILS_SELECTORS, PRODUCT_TYPES_LIST_SELECTORS, } from "./productTypes"; -import { ADDRESS_SELECTORS, BUTTON_SELECTORS, SHARED_ELEMENTS } from "./shared"; -import { SHIPPING_ZONES_LIST_SELECTORS } from "./shipping"; -import { +export { ADDRESS_SELECTORS, BUTTON_SELECTORS, SHARED_ELEMENTS } from "./shared"; +export { SHIPPING_ZONES_LIST_SELECTORS } from "./shipping"; +export { INVITE_STAFF_MEMBER_FORM_SELECTORS, STAFF_MEMBER_DETAILS_SELECTORS, STAFF_MEMBERS_LIST_SELECTORS, } from "./staffMembers"; -import { LANGUAGES_LIST_SELECTORS } from "./translations"; - -export { - ADDRESS_SELECTORS, - APPS_LIST_SELECTORS, - ATTRIBUTES_DETAILS, - ATTRIBUTES_LIST, - BUTTON_SELECTORS, - CATEGORIES_LIST_SELECTORS, - CATEGORY_DETAILS_SELECTORS, - CHANNEL_FORM_SELECTORS, - CHANNELS_SELECTORS, - COLLECTION_SELECTORS, - CONFIGURATION_SELECTORS, - CUSTOMER_DETAILS_SELECTORS, - CUSTOMERS_LIST_SELECTORS, - DRAFT_ORDERS_LIST_SELECTORS, - HOMEPAGE_SELECTORS, - INVITE_STAFF_MEMBER_FORM_SELECTORS, - LANGUAGES_LIST_SELECTORS, - LOGIN_SELECTORS, - MENU_SELECTORS, - ORDERS_SELECTORS, - PAGE_DETAILS_SELECTORS, - PAGE_TYPE_DETAILS_SELECTORS, - PAGE_TYPES_LIST_SELECTORS, - PAGES_LIST_SELECTORS, - PAGINATION, - PERMISSION_GROUP_DETAILS_SELECTORS, - PERMISSION_GROUP_LIST_SELECTORS, - PLUGINS_DETAILS_SELECTORS, - PLUGINS_LIST_SELECTORS, - PRODUCT_DETAILS, - PRODUCT_TYPE_DETAILS_SELECTORS, - PRODUCT_TYPES_LIST_SELECTORS, - PRODUCTS_LIST, - SALES_SELECTORS, - SET_PASSWORD_SELECTORS, - SHARED_ELEMENTS, - SHIPPING_ZONES_LIST_SELECTORS, - STAFF_MEMBER_DETAILS_SELECTORS, - STAFF_MEMBERS_LIST_SELECTORS, - VOUCHERS_SELECTORS, -}; +export { LANGUAGES_LIST_SELECTORS } from "./translations"; diff --git a/cypress/elements/orders/index.js b/cypress/elements/orders/index.js index 7aac0d0c1..42437d813 100644 --- a/cypress/elements/orders/index.js +++ b/cypress/elements/orders/index.js @@ -1,4 +1,4 @@ -import { DRAFT_ORDERS_LIST_SELECTORS } from "./draft-orders-list-selectors"; -import { ORDERS_SELECTORS } from "./orders-selectors"; - -export { DRAFT_ORDERS_LIST_SELECTORS, ORDERS_SELECTORS }; +export { DRAFT_ORDERS_LIST_SELECTORS } from "./draft-orders-list-selectors"; +export { ORDER_GRANT_REFUND } from "./order-grant-refund"; +export { ORDERS_SELECTORS } from "./orders-selectors"; +export { ORDER_TRANSACTION_CREATE } from "./transaction-selectors"; diff --git a/cypress/elements/orders/order-grant-refund.js b/cypress/elements/orders/order-grant-refund.js new file mode 100644 index 000000000..cdad8ddbc --- /dev/null +++ b/cypress/elements/orders/order-grant-refund.js @@ -0,0 +1,9 @@ +export const ORDER_GRANT_REFUND = { + productsQuantityInput: '[data-test-id*="quantity-input"]', + setMaxQuantityButton: '[data-test-id="setMaxQuantityButton"]', + refundReasonInput: '[data-test-id="refundReasonInput"]', + refundShippingCheckbox: '[data-test-id="refundShippingCheckbox"]', + applySelectedRefundButton: '[data-test-id="applySelectedRefundButton"]', + refundAmountInput: '[data-test-id="amountInput"]', + grantRefundButton: '[data-test-id="grantRefundButton"]', +}; diff --git a/cypress/elements/orders/orders-selectors.js b/cypress/elements/orders/orders-selectors.js index e9309c376..8c1c63b6a 100644 --- a/cypress/elements/orders/orders-selectors.js +++ b/cypress/elements/orders/orders-selectors.js @@ -9,4 +9,10 @@ export const ORDERS_SELECTORS = { orderFulfillmentFrame: "[data-test-id='order-fulfillment']", refundButton: '[data-test-id="refund-button"]', fulfillMenuButton: '[data-test-id="fulfill-menu"]', + markAsPaidButton: '[data-test-id="markAsPaidButton"]', + transactionReferenceInput: '[data-test-id="transaction-reference-input"]', + orderTransactionsList: '[data-test-id="orderTransactionsList"]', + grantRefundButton: '[data-test-id="grantRefundButton"]', + captureManualTransactionButton: + '[data-test-id="captureManualTransactionButton"]', }; diff --git a/cypress/elements/orders/transaction-selectors.js b/cypress/elements/orders/transaction-selectors.js new file mode 100644 index 000000000..ade51a6d1 --- /dev/null +++ b/cypress/elements/orders/transaction-selectors.js @@ -0,0 +1,6 @@ +export const ORDER_TRANSACTION_CREATE = { + transactionDescription: '[data-test-id="transactionDescription"]', + transactionPspReference: '[data-test-id="transactionPspReference"]', + transactAmountInput: '[data-test-id="transactAmountInput"]', + manualTransactionSubmit: '[data-test-id="manualTransactionSubmit"]', +}; diff --git a/cypress/fixtures/index.js b/cypress/fixtures/index.js index c076821af..9e7b92b82 100644 --- a/cypress/fixtures/index.js +++ b/cypress/fixtures/index.js @@ -1,5 +1,4 @@ -import { bodyMockHomePage } from "./bodyMocks"; -import { orderDraftCreateDemoResponse } from "./errors/demo/orderDratCreate"; -import { urlList } from "./urlList"; - -export { bodyMockHomePage, orderDraftCreateDemoResponse, urlList }; +export { bodyMockHomePage } from "./bodyMocks"; +export { orderDraftCreateDemoResponse } from "./errors/demo/orderDratCreate"; +export { urlList } from "./urlList"; +export { ONE_PERMISSION_USERS } from "./users"; diff --git a/cypress/support/api/requests/Channels.js b/cypress/support/api/requests/Channels.js index 0ab58e0ab..7474f17ab 100644 --- a/cypress/support/api/requests/Channels.js +++ b/cypress/support/api/requests/Channels.js @@ -83,3 +83,37 @@ export function updateChannelWarehouses(channelId, warehouseId) { }`; return cy.sendRequestWithQuery(mutation); } + +export function updateChannelOrderSettings({ + channelId, + automaticallyConfirmAllNewOrders = true, + automaticallyFulfillNonShippableGiftCard = true, + expireOrdersAfter = 0, + markAsPaidStrategy = "PAYMENT_FLOW", // TRANSACTION_FLOW - creates the TransactionItem object. + defaultTransactionFlowStrategy = "AUTHORIZATION", +}) { + const mutation = `mutation{ + channelUpdate(id:"${channelId}", input: {orderSettings: { + automaticallyConfirmAllNewOrders: ${automaticallyConfirmAllNewOrders}, + automaticallyFulfillNonShippableGiftCard: ${automaticallyFulfillNonShippableGiftCard}, + expireOrdersAfter: ${expireOrdersAfter}, + markAsPaidStrategy: ${markAsPaidStrategy}, + defaultTransactionFlowStrategy: ${defaultTransactionFlowStrategy} + }}){ + errors{ + field + message + } + channel { + orderSettings{ + automaticallyConfirmAllNewOrders + automaticallyFulfillNonShippableGiftCard + expireOrdersAfter + markAsPaidStrategy + defaultTransactionFlowStrategy + } + } + } + }`; + return cy.sendRequestWithQuery(mutation); +} diff --git a/cypress/support/api/requests/Order.js b/cypress/support/api/requests/Order.js index 0bdf33afe..29eccb13c 100644 --- a/cypress/support/api/requests/Order.js +++ b/cypress/support/api/requests/Order.js @@ -12,6 +12,12 @@ export function markOrderAsPaid(orderId) { lines{ id } + total{ + gross{ + amount + currency + } + } } } }`; @@ -94,6 +100,12 @@ export function completeOrder(orderId) { lines{ id } + total{ + gross{ + amount + currency + } + } } errors{ message @@ -111,6 +123,9 @@ export function getOrder(orderId) { token paymentStatus isShippingRequired + transactions{ + id + } shippingMethod{ id } @@ -142,7 +157,7 @@ export function getOrder(orderId) { } } }`; - cy.sendRequestWithQuery(query).its("body.data.order"); + return cy.sendRequestWithQuery(query).its("body.data.order"); } export function fulfillOrder({ orderId, warehouse, quantity, linesId }) { diff --git a/cypress/support/api/requests/index.js b/cypress/support/api/requests/index.js new file mode 100644 index 000000000..24158d763 --- /dev/null +++ b/cypress/support/api/requests/index.js @@ -0,0 +1,3 @@ +export { createChannel, updateChannelOrderSettings } from "./Channels"; +export { createCustomer, deleteCustomersStartsWith } from "./Customer"; +export { getOrder } from "./Order"; diff --git a/cypress/support/api/utils/index.js b/cypress/support/api/utils/index.js new file mode 100644 index 000000000..895b484e6 --- /dev/null +++ b/cypress/support/api/utils/index.js @@ -0,0 +1,8 @@ +export { deleteChannelsStartsWith } from "./channelsUtils"; +export { createOrder, createReadyToFulfillOrder } from "./ordersUtils"; +export { createShipping, deleteShippingStartsWith } from "./shippingUtils"; +export { + getDefaultTaxClass, + updateTaxConfigurationForChannel, +} from "./taxesUtils"; +export * as productsUtils from "./products/productsUtils"; diff --git a/cypress/support/api/utils/ordersUtils.js b/cypress/support/api/utils/ordersUtils.js index 9b9376bfd..72f70ede9 100644 --- a/cypress/support/api/utils/ordersUtils.js +++ b/cypress/support/api/utils/ordersUtils.js @@ -200,7 +200,7 @@ export function createOrder({ orderRequest.addShippingMethod(order.id, shippingMethod); }) .then(() => orderRequest.completeOrder(order.id)) - .then(() => order); + .then(resp => (order = resp.order)); } function assignVariantsToOrder(order, variantsList) { diff --git a/cypress/support/customCommands/basicOperations/index.js b/cypress/support/customCommands/basicOperations/index.js index 90707baa1..d8e409d61 100644 --- a/cypress/support/customCommands/basicOperations/index.js +++ b/cypress/support/customCommands/basicOperations/index.js @@ -50,6 +50,15 @@ Cypress.Commands.add("checkIfDataAreNotNull", data => { Cypress.Commands.add("checkIfElementIsVisible", element => { cy.get(element).should("be.visible"); }); +Cypress.Commands.add("checkIfElementIsNotVisible", element => { + cy.get(element).should("not.be.visible"); +}); +Cypress.Commands.add("checkIfElementExist", element => { + cy.get(element).should("exist"); +}); +Cypress.Commands.add("checkIfElementNotExist", element => { + cy.get(element).should("not.exist"); +}); Cypress.Commands.add("assertCanvasRowsNumber", (canvas, rowNumber) => { cy.get(canvas).find("tr").should("have.length", rowNumber); }); diff --git a/cypress/support/pages/index.js b/cypress/support/pages/index.js index 8abecf811..ca27ae561 100644 --- a/cypress/support/pages/index.js +++ b/cypress/support/pages/index.js @@ -1,3 +1,2 @@ -import * as ordersOperationsHelpers from "./ordersOperations"; - -export { ordersOperationsHelpers }; +export * as ordersOperationsHelpers from "./ordersOperations"; +export * as transactionsOrderUtils from "./ordersTransactionUtils"; diff --git a/cypress/support/pages/ordersTransactionUtils.js b/cypress/support/pages/ordersTransactionUtils.js new file mode 100644 index 000000000..fd6c262fe --- /dev/null +++ b/cypress/support/pages/ordersTransactionUtils.js @@ -0,0 +1,111 @@ +import { + BUTTON_SELECTORS, + ORDER_GRANT_REFUND, + ORDER_TRANSACTION_CREATE, + ORDERS_SELECTORS, +} from "../../elements"; + +export function markAsPaidOrderWithRefNumber(transactionNumber) { + cy.addAliasToGraphRequest("OrderMarkAsPaid"); + clickMarkAsPaidButton(); + typeTransactionReference(`ref_${transactionNumber}`); + clickConfirmMarkAsPaidButton().waitForRequestAndCheckIfNoErrors( + "@OrderMarkAsPaid", + ); +} +export function captureManualTransaction( + transactionDescription, + transactionPSPReference, + amount, +) { + clickCaptureManualTransactionButton(); + typeTransactionDescription(`desc_${transactionDescription}`); + typeTransactionPSPReference(`psp_${transactionPSPReference}`); + typeRefundTotalAmount(amount); + clickCreateManualTransactionButton().confirmationMessageShouldAppear(); +} +export function grantRefundAllProductsAndShippingWithReason( + refundReason, + total, +) { + cy.addAliasToGraphRequest("OrderDetailsGrantRefund"); + clickGrantRefundButton(); + cy.waitForRequestAndCheckIfNoErrors("@OrderDetailsGrantRefund"); + clickMaxQuantityButton(); + typeRefundReason(refundReason); + clickRefundShippingCheckbox(); + clickApplyRefundButton(); + cy.get(ORDER_GRANT_REFUND.refundAmountInput).should("contain.value", total); + clickConfirmRefundButton(); + cy.confirmationMessageShouldAppear(); +} +export function sendRefundWithDescriptionPSPAndAmount( + transactionDescription, + transactionPSPReference, + amount, +) { + clickSendRefundButton(); + typeTransactionDescription(`desc_${transactionDescription}`); + typeTransactionPSPReference(`psp_${transactionPSPReference}`); + typeRefundTotalAmount(amount); + cy.addAliasToGraphRequest("CreateManualTransactionRefund"); + clickRefundSubmitButton(); + cy.waitForRequestAndCheckIfNoErrors( + "@CreateManualTransactionRefund", + ).confirmationMessageShouldAppear(); +} +export function clickMarkAsPaidButton() { + return cy.clickOnElement(ORDERS_SELECTORS.markAsPaidButton); +} +export function clickRefundSubmitButton() { + return cy.clickOnElement(ORDER_TRANSACTION_CREATE.manualTransactionSubmit); +} +export function clickCreateManualTransactionButton() { + return cy.clickOnElement(ORDER_TRANSACTION_CREATE.manualTransactionSubmit); +} +export function clickMaxQuantityButton() { + return cy.clickOnElement(ORDER_GRANT_REFUND.setMaxQuantityButton); +} +export function clickCaptureManualTransactionButton() { + return cy.clickOnElement(ORDERS_SELECTORS.captureManualTransactionButton); +} +export function typeRefundReason(refundReasonDescription) { + return cy + .get(ORDER_GRANT_REFUND.refundReasonInput) + .type(`reason_${refundReasonDescription}`); +} +export function typeRefundTotalAmount(amount) { + return cy.get(ORDER_TRANSACTION_CREATE.transactAmountInput).type(amount); +} +export function typeTransactionReference(reference) { + return cy.get(ORDERS_SELECTORS.transactionReferenceInput).type(reference); +} +export function typeTransactionDescription(transactionDescription) { + return cy + .get(ORDER_TRANSACTION_CREATE.transactionDescription) + .type(`desc_${transactionDescription}`); +} +export function typeTransactionPSPReference(transactionPSPReference) { + return cy + .get(ORDER_TRANSACTION_CREATE.transactionPspReference) + .type(`psp_${transactionPSPReference}`); +} +export function clickGrantRefundButton() { + return cy.clickOnElement(ORDERS_SELECTORS.grantRefundButton); +} +export function clickSendRefundButton() { + return cy.clickOnElement(ORDERS_SELECTORS.refundButton); +} +export function clickRefundShippingCheckbox() { + return cy.clickOnElement(ORDER_GRANT_REFUND.refundShippingCheckbox); +} +export function clickApplyRefundButton() { + return cy.clickOnElement(ORDER_GRANT_REFUND.applySelectedRefundButton); +} + +export function clickConfirmRefundButton() { + return cy.clickOnElement(ORDER_GRANT_REFUND.grantRefundButton); +} +export function clickConfirmMarkAsPaidButton() { + return cy.clickOnElement(BUTTON_SELECTORS.submit); +} diff --git a/src/orders/components/OrderAddTransaction/OrderAddTransaction.tsx b/src/orders/components/OrderAddTransaction/OrderAddTransaction.tsx index 8ce597110..1656377b9 100644 --- a/src/orders/components/OrderAddTransaction/OrderAddTransaction.tsx +++ b/src/orders/components/OrderAddTransaction/OrderAddTransaction.tsx @@ -40,7 +40,11 @@ const OrderAddTransaction: React.FC = ({ return (
-
diff --git a/src/orders/components/OrderGrantRefundPage/OrderGrantRefundPage.tsx b/src/orders/components/OrderGrantRefundPage/OrderGrantRefundPage.tsx index 56a4a044d..5389c50b3 100644 --- a/src/orders/components/OrderGrantRefundPage/OrderGrantRefundPage.tsx +++ b/src/orders/components/OrderGrantRefundPage/OrderGrantRefundPage.tsx @@ -155,6 +155,11 @@ const OrderGrantRefundPage: React.FC = ({ name={"reason" as keyof OrderGrantRefundFormData} onChange={change} type="text" + InputProps={{ + inputProps: { + "data-test-id": "refundReasonInput", + }, + }} /> diff --git a/src/orders/components/OrderGrantRefundPage/components/ProductCard.tsx b/src/orders/components/OrderGrantRefundPage/components/ProductCard.tsx index 7356a5f59..1de180324 100644 --- a/src/orders/components/OrderGrantRefundPage/components/ProductCard.tsx +++ b/src/orders/components/OrderGrantRefundPage/components/ProductCard.tsx @@ -67,7 +67,11 @@ export const ProductsCard: React.FC = ({ } toolbar={ - } diff --git a/src/orders/components/OrderGrantRefundPage/components/RefundCard.tsx b/src/orders/components/OrderGrantRefundPage/components/RefundCard.tsx index fdbeeadc2..b25928cc2 100644 --- a/src/orders/components/OrderGrantRefundPage/components/RefundCard.tsx +++ b/src/orders/components/OrderGrantRefundPage/components/RefundCard.tsx @@ -59,6 +59,7 @@ export const RefundCard = ({ id={`checkbox-${id}`} value={state.refundShipping} onChange={() => dispatch({ type: "toggleRefundShipping" })} + data-test-id="refundShippingCheckbox" />