Onboarding: Add US/Chile shipping onboarding coverage#63348
Conversation
Testing GuidelinesHi @ayushpahwa , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
|
Size Change: +36 B (0%) Total Size: 5.98 MB |
📝 WalkthroughWalkthroughThis PR introduces a new helper function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
plugins/woocommerce/client/admin/client/task-lists/fills/shipping/index.js (2)
213-217: DRY: reusehasInstallableSlughere instead of duplicating its logic.The filter predicate duplicates the check that
hasInstallableSlugalready encapsulates. Since you're mapping to just the slug string first, a small restructure would keep this DRY.♻️ Suggested refactor
- const pluginsToActivate = pluginsToPromote - .map( ( pluginToPromote ) => pluginToPromote.slug ) - .filter( - ( slug ) => typeof slug === 'string' && slug.trim().length > 0 - ); + const pluginsToActivate = pluginsToPromote + .filter( hasInstallableSlug ) + .map( ( pluginToPromote ) => pluginToPromote.slug );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@plugins/woocommerce/client/admin/client/task-lists/fills/shipping/index.js` around lines 213 - 217, The current map-then-filter duplicates logic; instead use hasInstallableSlug to DRY this. Change the pipeline so you first filter pluginsToPromote with hasInstallableSlug and then map to plugin.slug (i.e., pluginsToActivate = pluginsToPromote.filter(hasInstallableSlug).map(p => p.slug)); reference hasInstallableSlug, pluginsToPromote and pluginsToActivate to locate and replace the existing map(...).filter(...) sequence.
381-381:visibleis a number here; other steps use explicit booleans.
pluginsToPromote.lengthevaluates to a number (truthy when > 0), while othervisiblefields usetrue/false. Functionally fine, butpluginsToPromote.length > 0would be more consistent.♻️ Suggested fix
- visible: pluginsToPromote.length, + visible: pluginsToPromote.length > 0,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@plugins/woocommerce/client/admin/client/task-lists/fills/shipping/index.js` at line 381, The visible property is set to a number via pluginsToPromote.length; change it to an explicit boolean for consistency by using pluginsToPromote.length > 0 (i.e., replace visible: pluginsToPromote.length with visible: pluginsToPromote.length > 0), locating the assignment to visible near the pluginsToPromote variable in the shipping/index.js fill step.plugins/woocommerce/client/admin/client/task-lists/fills/shipping/test/index.tsx (1)
89-99: Good coverage of the core cases. Consider adding a whitespace-only slug test (slug: ' ') sincehasInstallableSlugexplicitly trims — this would exercise that branch.🧪 Optional additional test
it( 'treats missing slugs as non-installable partners', () => { expect( hasInstallableSlug( {} ) ).toBe( false ); } ); + + it( 'treats whitespace-only slugs as non-installable partners', () => { + expect( hasInstallableSlug( { slug: ' ' } ) ).toBe( false ); + } );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@plugins/woocommerce/client/admin/client/task-lists/fills/shipping/test/index.tsx` around lines 89 - 99, Add a test case exercising the trim branch of hasInstallableSlug by asserting that a partner object with a whitespace-only slug (e.g., { slug: ' ' }) is treated as non-installable; locate the test block in the file that contains the existing cases for usShippingPartner/chileShippingPartner/missing slug and add a new it() asserting hasInstallableSlug({ slug: ' ' }) returns false so the trimming logic is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@plugins/woocommerce/client/admin/client/task-lists/fills/shipping/index.js`:
- Around line 213-217: The current map-then-filter duplicates logic; instead use
hasInstallableSlug to DRY this. Change the pipeline so you first filter
pluginsToPromote with hasInstallableSlug and then map to plugin.slug (i.e.,
pluginsToActivate = pluginsToPromote.filter(hasInstallableSlug).map(p =>
p.slug)); reference hasInstallableSlug, pluginsToPromote and pluginsToActivate
to locate and replace the existing map(...).filter(...) sequence.
- Line 381: The visible property is set to a number via pluginsToPromote.length;
change it to an explicit boolean for consistency by using
pluginsToPromote.length > 0 (i.e., replace visible: pluginsToPromote.length with
visible: pluginsToPromote.length > 0), locating the assignment to visible near
the pluginsToPromote variable in the shipping/index.js fill step.
In
`@plugins/woocommerce/client/admin/client/task-lists/fills/shipping/test/index.tsx`:
- Around line 89-99: Add a test case exercising the trim branch of
hasInstallableSlug by asserting that a partner object with a whitespace-only
slug (e.g., { slug: ' ' }) is treated as non-installable; locate the test
block in the file that contains the existing cases for
usShippingPartner/chileShippingPartner/missing slug and add a new it() asserting
hasInstallableSlug({ slug: ' ' }) returns false so the trimming logic is
covered.
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
ayushpahwa
left a comment
There was a problem hiding this comment.
Changes look good and the testing instructions work as expected. I was able to reproduce the error on trunk and this PR fixed it. Thanks for working on this and adding the tests.
* Add US/Chile shipping onboarding coverage * Add changelog * test: restore shipping task e2e teardown state * test: replace shipping CTA e2e checks with unit coverage
The root issue here appears to be that the shipping recommendations from WooCommerce.com expect that a plugin only downloadable if there is a slug to a WordPress.org plugin. Otherwise, the merchant should click "Learn More". This PR will fall back to the primary action being "download" and then linking the merchant to download the extension on WooCommerce.com.
Changes proposed in this Pull Request:
hasInstallableSlug) and treat empty/whitespace slugs as non-installable.Install and enable.Downloadand does not showInstall and enable.How to test the changes in this Pull Request:
pnpm --filter='@woocommerce/plugin-woocommerce' build:admincd plugins/woocommerce && wp-env startusername:adminandpassword:passwordTesting that has already taken place:
Milestone
Changelog entry
Changelog Entry Details
Significance
Type
Message
Fix shipping onboarding recommendations so non-installable partners show
Downloadand the label-printing step remains visible.Changelog Entry Comment
Comment
N/A