Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dispute challenge/accept e2e tests to match changes to transaction details and order edit screens #7448

Merged
merged 17 commits into from
Oct 12, 2023

Conversation

Jinksi
Copy link
Member

@Jinksi Jinksi commented Oct 10, 2023

Fixes #7377
Fixes #7397 (adds e2e tests for disputed order notice → transaction details flow)

Changes proposed in this Pull Request

This PR updates e2e tests for merchant dispute challenge/accept flows to work with the new Transaction Dispute Details UI (#6883).

These e2e test suites were skipped in #7088 and now have been updated and re-enabled:

  • tests/e2e/specs/wcpay/merchant/merchant-disputes-save-for-editing.spec.js
    • Disputes > Save dispute for editing
  • tests/e2e/specs/wcpay/merchant/merchant-disputes-submit-losing.spec.js
    • Disputes > Submit losing dispute
  • tests/e2e/specs/wcpay/merchant/merchant-disputes-submit-winning.spec.js
    • Disputes > Submit winning dispute

I've also used the dispute notice's Respond now button on the order edit screen to navigate to the transaction details screen for these flows, which is a critical flow. This replaces the previous method of navigating the browser directly to the transaction details URL. Expanding our e2e test coverage to include this flow fixes #7397.

TODO:

  • Update helper methods modified in this PR in WCPay e2e guide (PaJDYF-7pO-p2)

Testing instructions

  • Ensure GitHub checks pass, in particular
    E2E Tests - Pull Request / WC - latest | wcpay - merchant

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile N/A

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Oct 10, 2023

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 7448 or branch name fix/7377-dispute-e2e-tests in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: 72c7467
  • Build time: 2023-10-12 22:37:51 UTC

Note: the build is updated when a new commit is pushed to this PR.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 2023

Size Change: +45 B (0%)

Total Size: 1.43 MB

Filename Size Change
release/woocommerce-payments/dist/index.js 284 kB +45 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.04 kB
release/woocommerce-payments/assets/css/success.css 158 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 1.8 kB
release/woocommerce-payments/dist/blocks-checkout.css 1.8 kB
release/woocommerce-payments/dist/blocks-checkout.js 75.2 kB
release/woocommerce-payments/dist/checkout-rtl.css 440 B
release/woocommerce-payments/dist/checkout.css 441 B
release/woocommerce-payments/dist/checkout.js 29 kB
release/woocommerce-payments/dist/index-rtl.css 36.4 kB
release/woocommerce-payments/dist/index.css 36.4 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 2.88 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 60.3 kB
release/woocommerce-payments/dist/multi-currency.css 2.88 kB
release/woocommerce-payments/dist/multi-currency.js 55 kB
release/woocommerce-payments/dist/order-rtl.css 676 B
release/woocommerce-payments/dist/order.css 679 B
release/woocommerce-payments/dist/order.js 41.1 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 690 B
release/woocommerce-payments/dist/payment-gateways.css 692 B
release/woocommerce-payments/dist/payment-gateways.js 38.6 kB
release/woocommerce-payments/dist/payment-request-rtl.css 146 B
release/woocommerce-payments/dist/payment-request.css 146 B
release/woocommerce-payments/dist/payment-request.js 13.1 kB
release/woocommerce-payments/dist/product-details.js 898 B
release/woocommerce-payments/dist/settings-rtl.css 9.04 kB
release/woocommerce-payments/dist/settings.css 9.05 kB
release/woocommerce-payments/dist/settings.js 234 kB
release/woocommerce-payments/dist/subscription-edit-page.js 669 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 519 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 519 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 20.4 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 693 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 117 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 117 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 19.6 kB
release/woocommerce-payments/dist/tos-rtl.css 230 B
release/woocommerce-payments/dist/tos.css 231 B
release/woocommerce-payments/dist/tos.js 22 kB
release/woocommerce-payments/dist/upe_checkout-rtl.css 440 B
release/woocommerce-payments/dist/upe_checkout.css 441 B
release/woocommerce-payments/dist/upe_checkout.js 34.1 kB
release/woocommerce-payments/dist/upe_split_checkout-rtl.css 440 B
release/woocommerce-payments/dist/upe_split_checkout.css 441 B
release/woocommerce-payments/dist/upe_split_checkout.js 34.6 kB
release/woocommerce-payments/dist/upe_with_deferred_intent_creation_checkout.js 37 kB
release/woocommerce-payments/dist/upe-blocks-checkout-rtl.css 1.8 kB
release/woocommerce-payments/dist/upe-blocks-checkout.css 1.8 kB
release/woocommerce-payments/dist/upe-blocks-checkout.js 40.9 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout-rtl.css 1.8 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout.css 1.8 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout.js 42.5 kB
release/woocommerce-payments/dist/woopay-express-button-rtl.css 146 B
release/woocommerce-payments/dist/woopay-express-button.css 146 B
release/woocommerce-payments/dist/woopay-express-button.js 52.1 kB
release/woocommerce-payments/dist/woopay-rtl.css 3.85 kB
release/woocommerce-payments/dist/woopay.css 3.85 kB
release/woocommerce-payments/dist/woopay.js 71.8 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 622 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.43 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.01 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 522 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 581 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.32 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.8 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.32 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 291 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 403 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.56 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 299 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 742 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 572 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 411 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.63 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.8 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.83 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 502 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 355 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 429 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 781 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.27 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 392 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.05 kB

compressed-size-action

@Jinksi Jinksi changed the title Update dispute challenge e2e tests Update dispute challenge/accept e2e tests Oct 11, 2023
@@ -105,6 +105,8 @@ describe.skip( 'Disputes > Save dispute for editing', () => {
// Reload the page
await page.reload();

await uiLoaded();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was flaky in my local environment: adding this seemed to make the test more robust.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds important and impactful 😁 … if the UI isn't loaded and we start expecting stuff, we're in trouble.

},

openAcceptDispute: async () => {
await Promise.all( [

This comment was marked as outdated.

@Jinksi Jinksi changed the title Update dispute challenge/accept e2e tests Update dispute challenge/accept e2e tests to match changes to transaction details and order edit screens Oct 11, 2023
@@ -589,43 +587,6 @@ export const merchantWCP = {
} );
},

openDisputeDetails: async ( disputeDetailsLink ) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper function is no longer relevant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… because the dispute details screen is goneburgers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I mentioned it part of the #7363 tasks.

await uiLoaded();
},

openChallengeDispute: async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this helper function and moved the logic inline to simplify the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this – it's not just simplification. You are removing a problematic abstraction and making each test more self-contained (decoupled).

] );
},

openAcceptDispute: async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this helper function and moved the logic inline to simplify the code – this was only used in one test.

@Jinksi Jinksi requested a review from a team October 11, 2023 11:47
@Jinksi
Copy link
Member Author

Jinksi commented Oct 11, 2023

In the GH check, the e2e tests modified in this PR are passing, yet a subsequent test fails. I'll have to investigate to see if a cleanup action needs to be taken after the dispute tests.

PASS tests/e2e/specs/wcpay/merchant/merchant-disputes-save-for-editing.spec.js (31.781 s)
PASS tests/e2e/specs/wcpay/merchant/merchant-disputes-submit-losing.spec.js (33.636 s)
PASS tests/e2e/specs/wcpay/merchant/merchant-disputes-submit-winning.spec.js (42.252 s)
PASS tests/e2e/specs/wcpay/merchant/merchant-orders-full-refund.spec.js (42.208 s)
FAIL tests/e2e/specs/wcpay/merchant/merchant-orders-status-change.spec.js 

@shendy-a8c
Copy link
Contributor

The failing merchant-orders-status-change.spec.js test might not be related to this PR as I see it fails in other PRs as well.

@haszari
Copy link
Contributor

haszari commented Oct 12, 2023

These tests were skipped in #7088 temporarily until they could be updated.

@Jinksi can you add the exact suites that were skipped (and that this PR fixes and reinstates) to the PR description? This is helpful when reviewing (since there seem to be other tests failing!)

@Jinksi
Copy link
Member Author

Jinksi commented Oct 12, 2023

@Jinksi can you add the exact suites that were skipped (and that this PR fixes and reinstates) to the PR description? This is helpful when reviewing (since there seem to be other tests failing!)

Good idea, thanks @haszari. I've added the following to the PR description:

These e2e test suites were skipped in #7088 and now have been updated and re-enabled:

  • tests/e2e/specs/wcpay/merchant/merchant-disputes-save-for-editing.spec.js
    • Disputes > Save dispute for editing
  • tests/e2e/specs/wcpay/merchant/merchant-disputes-submit-losing.spec.js
    • Disputes > Submit losing dispute
  • tests/e2e/specs/wcpay/merchant/merchant-disputes-submit-winning.spec.js
    • Disputes > Submit winning dispute

Copy link
Contributor

@haszari haszari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the code and don't see any blockers. Note I didn't run tests locally, but I'm assuming they run now 😁 . I checked the last run and I see an unrelated test is failing (merchant-orders-status-change.spec.js). Does that mean our test succeeded (concurrent/independent tests), or is it blocked (bail on first fail)?

I haven't spent a lot of time on our e2e suite so took this PR as an opportunity to dive in and understand. I have some thoughts/feedback for tests in general, none is blocking for this PR (and most is really unrelated). Mentioning here in the spirit of improving things as we go – if you think any of my suggestions are worth handling in this PR, go for it!

  • 🙌testid approach is much more explicit and robust. Should we encourage wider use? Principle: prefer explicit id over implicit or structural matchers.
  • (Nitpick) Tests often use relative ancestor imports paths. Principle: avoid relative imports, so modules can be moved easily (to a different place in the tree).
  • Test suites and individual tests should be named clearly, based on merchant intent. Principle: test what the user needs to do. Our flows list and our test suite would ideally be very similar.
  • Test scripts and expectations should be documented with comments. These comments have two benefits:
    • Describe at a high level the programmer/tester intention. E.g. Simulate merchant clicking dispute notice on order page.
    • Explicitly document implicit states that will be tested or are required (part of path to test). E.g. Wait for transaction detail page to load and render. [implied in these tests – the expect()s typically confirm something on the transaction details screen]

@@ -105,6 +105,8 @@ describe.skip( 'Disputes > Save dispute for editing', () => {
// Reload the page
await page.reload();

await uiLoaded();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds important and impactful 😁 … if the UI isn't loaded and we start expecting stuff, we're in trouble.

{
text: 'Challenge dispute',
}
'[data-testid="challenge-dispute-button"]'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 These testids are a great pattern. Is this commonplace, or can we encourage wider use?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data-testid is a common pattern from react-testing-library, although it is the least preferred method of querying an element (user-facing methods are preferred).

In the spirit of the guiding principles, it is recommended to use this (data-testid) only after the other queries don't work for your use case.
...
That said, they are way better than querying based on DOM structure or styling css class names.

The WooCommerce guide Best Practices for Writing and Running End-to-End Tests recommends a similar approach:

Include your own automation IDs
To avoid maintaining selectors in the future, it’s always a good idea to include your own data selector, such as test-automation-id
...
instead of generally searching for visible elements on the page and using their IDs, classes, and XPaths.

@@ -589,43 +587,6 @@ export const merchantWCP = {
} );
},

openDisputeDetails: async ( disputeDetailsLink ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… because the dispute details screen is goneburgers?

await uiLoaded();
},

openChallengeDispute: async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this – it's not just simplification. You are removing a problematic abstraction and making each test more self-contained (decoupled).

} );

// Challenge the dispute
await merchantWCP.openChallengeDispute();
// Click the challenge dispute button.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear names and comments in these e2e tests might help make them stable and easier to maintain (as we iterate on the software and flows).

For this example, I think this is a setup step (not a test expectation), and it does quite a few things.

Would this comment accurately reflect the intention?

// Simulate merchant challenging the dispute.
// Wait for the dispute challenge page to load and render.

This also explicitly states the outcome (expected state). I think that's useful because the actual test expectations apply to that page.


let orderId;

describe.skip( 'Disputes > Save dispute for editing', () => {
describe( 'Disputes > Save dispute for editing', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming of the suites, and the tests is a good place to take care and be really clear.

I think this test is focused on verifying that merchants can save and resume their response to dispute. Is that correct?

If so, something like this might be clearer: Disputes > Merchant can save and resume draft dispute challenge

These suite names, and the individual tests, are likely to align very closely to flows. So we might already have a list of names we can use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming of the suites, and the tests is a good place to take care and be really clear.

💯

I've updated the filename from merchant-disputes-save-for-editing.spec.jsmerchant-disputes-save-draft-challenge.spec.js in 3e9f30f.

I've also updated the test names within this file in 876468e.

@Jinksi
Copy link
Member Author

Jinksi commented Oct 12, 2023

I'll merge this now with some next steps as per our discussion:

  1. FE guild – propose guidelines for:
    1. writing more resilient tests (prefer explicit id over implicit or structural matches.)
    2. avoiding relative imports of distant files '../../../utils' including for e2e tests (this would also require a webpack configuration change as far as I can tell).
    3. test suite naming based on user intent. Principle: test what the user needs to do. Our flows list and our test suite would ideally be very similar.
    4. test scripts and expectations should be documented with comments.
  2. Helix: observe these proposed guidelines when revisiting flows and e2e tests during or as a followup task from our meetup workshop.

@Jinksi Jinksi added this pull request to the merge queue Oct 12, 2023
@haszari
Copy link
Contributor

haszari commented Oct 12, 2023

avoiding relative imports of distant files '../../../utils' including for e2e tests (this would also require a webpack configuration change as far as I can tell).

On this, it looks like our test scripts aren't getting the same linter checks as our app code (e.g. comments should be sentences). Would be nice if they were consistent.

Merged via the queue into develop with commit f1a2d7c Oct 12, 2023
27 checks passed
@Jinksi Jinksi deleted the fix/7377-dispute-e2e-tests branch October 12, 2023 23:10
@Jinksi
Copy link
Member Author

Jinksi commented Oct 12, 2023

On this, it looks like our test scripts aren't getting the same linter checks as our app code (e.g. comments should be sentences). Would be nice if they were consistent.

@haszari a quick test of this in VSCode suggests that this only applies to PHP comments, not JS. This requires some investigation.

@haszari
Copy link
Contributor

haszari commented Oct 12, 2023

that this only applies to PHP comments, not JS

Thanks for checking! I must be confusing our PHP and JS standards again 😵‍💫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants