Skip to content

Commit

Permalink
Merge branch 'develop' into fix/skip-merchant-dispute-e2e-tests-faili…
Browse files Browse the repository at this point in the history
…ng-respond-now-not-found
  • Loading branch information
Jinksi authored Oct 16, 2023
2 parents 976b4a7 + edd225a commit 38b52c2
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 160 deletions.
4 changes: 4 additions & 0 deletions changelog/dev-7252-unskip-merchant-e2e-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Restore skipped e2e merchant tests
1 change: 1 addition & 0 deletions client/settings/advanced-settings/multi-currency-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const MultiCurrencyToggle = () => {
} ) }
checked={ isMultiCurrencyEnabled }
onChange={ handleMultiCurrencyStatusChange }
data-testid="multi-currency-toggle"
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const chkboxCaptureLaterOption = 'capture-later-checkbox';
const customerBankStatement = 'store-name-bank-statement';
let orderId;

// TODO: Unskip once refund E2E tests failure are investigated.
describe.skip( 'Order > Manual Capture', () => {
describe( 'Order > Manual Capture', () => {
beforeAll( async () => {
// As the merchant, enable the "Issue an authorization on checkout, and capture later" option in the Payment Settings page
await merchant.login();
Expand Down
300 changes: 144 additions & 156 deletions tests/e2e/specs/wcpay/merchant/merchant-orders-partial-refund.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,167 +48,155 @@ const dataTable = [
],
];

// TODO: Unskip (remove outer block) once refund E2E tests failure are investigated.
describe.skip( 'Partial refund tests', function () {
describe.each( dataTable )(
'Order > Partial refund',
( testName, { lineItems, refundInputs } ) => {
let orderId;
let orderTotal;

beforeAll( async () => {
// Set up the test order
await setupProductCheckout(
config.get( 'addresses.customer.billing' ),
lineItems
);
await fillCardDetails( page, card );
await shopper.placeOrder();
await expect( page ).toMatch( 'Order received' );

// Remember the order ID and order total. We will need them later.
orderId = await page.$eval(
'.woocommerce-order-overview__order.order > strong',
( el ) => el.innerText
);
orderTotal = await page.$eval(
'.woocommerce-order-overview__total strong',
( el ) => Number( el.innerText.replace( '$', '' ) )
);

// Login as merchant
await merchant.login();
}, 200000 );

afterAll( async () => {
await merchant.logout();
} );

it( `should refund ${ testName }`, async () => {
const refundReason = `Refunding ${ testName }`;
const refundTotal = refundInputs
.map( ( { refundAmount } ) => refundAmount )
.reduce( ( acc, cur ) => acc + cur );
const refundTotalString = refundTotal.toFixed( 2 );
const netPayment = ( orderTotal - refundTotal ).toFixed( 2 );

await merchant.goToOrder( orderId );

// We need to remove any listeners on the `dialog` event otherwise we can't catch the dialog below
await page.removeAllListeners( 'dialog' );

// Click the Refund button
await expect( page ).toClick( 'button.refund-items' );

// Fill up the quantity and/or amount to be refunded per line item
const rows = await page.$$( '#order_line_items tr.item' );
for ( let i = 0; i < refundInputs.length; i++ ) {
const { refundQty, refundAmount } = refundInputs[ i ];
const row = rows[ i ];

if ( refundQty ) {
await expect( row ).toFill(
'.refund_order_item_qty',
`${ refundQty }`
);
} else {
await expect( row ).toFill(
'.refund_line_total',
`${ refundAmount }`
);
}
describe.each( dataTable )(
'Order > Partial refund',
( testName, { lineItems, refundInputs } ) => {
let orderId;
let orderTotal;

beforeAll( async () => {
// Disable multi-currency in the merchant settings. This step is important because local environment setups
// might have multi-currency enabled. We need to ensure a consistent
// environment for the test.
await merchant.login();
await merchantWCP.deactivateMulticurrency();
await merchant.logout();

// Set up the test order
await setupProductCheckout(
config.get( 'addresses.customer.billing' ),
lineItems
);
await fillCardDetails( page, card );
await shopper.placeOrder();
await expect( page ).toMatch( 'Order received' );

// Remember the order ID and order total. We will need them later.
orderId = await page.$eval(
'.woocommerce-order-overview__order.order > strong',
( el ) => el.innerText
);
orderTotal = await page.$eval(
'.woocommerce-order-overview__total strong',
( el ) => Number( el.innerText.replace( '$', '' ) )
);

// Login as merchant
await merchant.login();
}, 200000 );

afterAll( async () => {
await merchantWCP.activateMulticurrency();
await merchant.logout();
} );

it( `should refund ${ testName }`, async () => {
const refundReason = `Refunding ${ testName }`;
const refundTotal = refundInputs
.map( ( { refundAmount } ) => refundAmount )
.reduce( ( acc, cur ) => acc + cur );
const refundTotalString = refundTotal.toFixed( 2 );
const netPayment = ( orderTotal - refundTotal ).toFixed( 2 );

await merchant.goToOrder( orderId );

// We need to remove any listeners on the `dialog` event otherwise we can't catch the dialog below
await page.removeAllListeners( 'dialog' );

// Click the Refund button
await expect( page ).toClick( 'button.refund-items' );

// Fill up the quantity and/or amount to be refunded per line item
const rows = await page.$$( '#order_line_items tr.item' );
for ( let i = 0; i < refundInputs.length; i++ ) {
const { refundQty, refundAmount } = refundInputs[ i ];
const row = rows[ i ];

if ( refundQty ) {
await expect( row ).toFill(
'.refund_order_item_qty',
`${ refundQty }`
);
} else {
await expect( row ).toFill(
'.refund_line_total',
`${ refundAmount }`
);
}
}

// Fill up the rest of the form and complete the refund flow
await expect( page ).toFill( '#refund_reason', refundReason );
await expect( page ).toMatchElement( '.do-api-refund', {
text: `Refund $${ refundTotalString } via WooPayments`,
} );
const refundDialog = await expect( page ).toDisplayDialog(
async () => {
await expect( page ).toClick( 'button.do-api-refund' );
}
);
await refundDialog.accept();
await uiUnblocked();
await page.waitForNavigation( { waitUntil: 'networkidle0' } );

// Verify each line item shows the refunded quantity and/or amount
const updatedRows = await page.$$(
'#order_line_items tr.item'
);
for ( let i = 0; i < refundInputs.length; i++ ) {
const { refundQty, refundAmount } = refundInputs[ i ];
const row = updatedRows[ i ];

if ( refundQty ) {
await expect( row ).toMatchElement(
'.quantity .refunded',
{
text: `-${ refundQty }`,
}
);
}

await expect( row ).toMatchElement(
'.line_cost .refunded',
{
text: `-$${ refundAmount.toFixed( 2 ) }`,
}
);
// Fill up the rest of the form and complete the refund flow
await expect( page ).toFill( '#refund_reason', refundReason );
await expect( page ).toMatchElement( '.do-api-refund', {
text: `Refund $${ refundTotalString } via WooPayments`,
} );
const refundDialog = await expect( page ).toDisplayDialog(
async () => {
await expect( page ).toClick( 'button.do-api-refund' );
}
);
await refundDialog.accept();
await uiUnblocked();
await page.waitForNavigation( { waitUntil: 'networkidle0' } );

// Verify each line item shows the refunded quantity and/or amount
const updatedRows = await page.$$( '#order_line_items tr.item' );
for ( let i = 0; i < refundInputs.length; i++ ) {
const { refundQty, refundAmount } = refundInputs[ i ];
const row = updatedRows[ i ];

if ( refundQty ) {
await expect( row ).toMatchElement( '.quantity .refunded', {
text: `-${ refundQty }`,
} );
}

// Verify the refund shows in the list with the amount
await expect( page ).toMatchElement( '.refund > .line_cost', {
text: `-$${ refundTotalString }`,
await expect( row ).toMatchElement( '.line_cost .refunded', {
text: `-$${ refundAmount.toFixed( 2 ) }`,
} );
}

// Verify system note was added
await expect( page ).toMatchElement( '.system-note', {
text: `refund of $${ refundTotalString }`,
} );
await expect( page ).toMatchElement( '.system-note', {
text: `Reason: ${ refundReason }`,
} );
// Verify the refund shows in the list with the amount
await expect( page ).toMatchElement( '.refund > .line_cost', {
text: `-$${ refundTotalString }`,
} );

// Verify "Refunded" and "Net Payment" values in Order Totals section
await expect( page ).toMatchElement(
'.wc-order-totals .total.refunded-total',
{
text: `-$${ refundTotalString }`,
}
);
await expect( page ).toMatchElement(
'.wc-order-totals .total',
{
text: `$${ netPayment }`,
}
);

// Pull out and follow the link to avoid working in multiple tabs
const paymentDetailsLink = await page.$eval(
'p.order_number > a',
( anchor ) => anchor.getAttribute( 'href' )
);

await merchantWCP.openPaymentDetails( paymentDetailsLink );

// Verify the transaction timeline reflects the refund events
await Promise.all( [
expect( page ).toMatchElement(
'li.woocommerce-timeline-item',
{
text: `A payment of $${ refundTotalString } was successfully refunded.`,
}
),
expect( page ).toMatchElement(
'li.woocommerce-timeline-item',
{
text: 'Payment status changed to Partial refund.',
}
),
] );
// Verify system note was added
await expect( page ).toMatchElement( '.system-note', {
text: `refund of $${ refundTotalString }`,
} );
}
);
} );
await expect( page ).toMatchElement( '.system-note', {
text: `Reason: ${ refundReason }`,
} );

// Verify "Refunded" and "Net Payment" values in Order Totals section
await expect( page ).toMatchElement(
'.wc-order-totals .total.refunded-total',
{
text: `-$${ refundTotalString }`,
}
);
await expect( page ).toMatchElement( '.wc-order-totals .total', {
text: `$${ netPayment }`,
} );

// Pull out and follow the link to avoid working in multiple tabs
const paymentDetailsLink = await page.$eval(
'p.order_number > a',
( anchor ) => anchor.getAttribute( 'href' )
);

await merchantWCP.openPaymentDetails( paymentDetailsLink );

// Verify the transaction timeline reflects the refund events
await Promise.all( [
expect( page ).toMatchElement( 'li.woocommerce-timeline-item', {
text: `A payment of $${ refundTotalString } was successfully refunded.`,
} ),
expect( page ).toMatchElement( 'li.woocommerce-timeline-item', {
text: 'Payment status changed to Partial refund.',
} ),
] );
} );
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const dataTable = [
[ 'total refund amount', 'negative', selectorTotalAmount, '-1' ],
];

// TODO: Unskip once refund E2E tests failure are investigated.
describe.skip( 'Order > Refund Failure', () => {
describe( 'Order > Refund Failure', () => {
beforeAll( async () => {
// Place an order to refund later
await setupProductCheckout(
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e/utils/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,4 +797,16 @@ export const merchantWCP = {
waitUntil: 'networkidle0',
} );
},

deactivateMulticurrency: async () => {
await merchantWCP.openWCPSettings();
await merchantWCP.unsetCheckboxByTestId( 'multi-currency-toggle' );
await merchantWCP.wcpSettingsSaveChanges();
},

activateMulticurrency: async () => {
await merchantWCP.openWCPSettings();
await merchantWCP.setCheckboxByTestId( 'multi-currency-toggle' );
await merchantWCP.wcpSettingsSaveChanges();
},
};

0 comments on commit 38b52c2

Please sign in to comment.