tests: backfill Jest tests#152
Conversation
|
Successful - Artifact uploaded to the PR at https://github.com/rtCamp/OneSearch/actions/runs/22880836941/artifacts/5840706526 Typescript failures will be addressed in followup PR that migrates the js files to ts. |
There was a problem hiding this comment.
Pull request overview
This PR backfills Jest unit tests for the plugin’s JS/React code under assets/src, and adds supporting test infrastructure (Jest setup, module mocks, and TS global typings) to enable higher coverage and more reliable runs.
Changes:
- Add a suite of Jest + React Testing Library tests for key admin pages/components and
utils. - Add shared Jest setup (globals like
fetch,OneSearchSettings,OneSearchOnboarding, clipboard) and a manual mock for@wordpress/api-fetch. - Introduce TS global typings for the WordPress-injected window globals and adjust TS/Jest configs to support the test suite and aliases.
Reviewed changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
tsconfig.json |
Tweaks TS include/paths configuration (notably adds **/*.d.ts). |
tests/js/utils.test.ts |
Adds unit tests for URL helpers and global-derived constants. |
tests/js/tsconfig.json |
Adjusts test TS config (types/baseUrl/includes) for Jest tests. |
tests/js/setup.ts |
Adds shared Jest environment setup (fetch, globals, clipboard). |
tests/js/SiteTable.test.tsx |
Adds component tests for table empty/add/edit/delete flows. |
tests/js/SiteSettings.test.tsx |
Adds fetch-driven behavior tests for settings actions and notices. |
tests/js/SiteSearchSettings.test.tsx |
Adds tests around loading/saving/toggling site search settings. |
tests/js/SiteModal.test.tsx |
Adds modal validation + health-check + submit failure/success tests. |
tests/js/SiteIndexableEntities.test.tsx |
Adds tests for entity selection, saving, reindex, and error handling. |
tests/js/SettingsPage.test.tsx |
Adds tests for settings page data loading, save flows, and body-class behavior (with child mocks). |
tests/js/OnboardingScreen.test.tsx |
Adds tests for onboarding site-type load/save and error notices. |
tests/js/MultiSelectChips.test.tsx |
Adds interaction tests for multi-select UI behavior. |
tests/js/AlgoliaSettings.test.tsx |
Adds tests for Algolia credential load/save/error flows. |
package.json |
Removes --passWithNoTests from Jest scripts. |
assets/src/types/global.d.ts |
Adds global TypeScript declarations for window.OneSearchSettings/window.OneSearchOnboarding. |
assets/src/js/utils.ts |
Simplifies URL validation helper implementation. |
assets/src/admin/settings/index.tsx |
Removes in-file global typing in favor of shared global typings. |
assets/src/admin/onboarding/page.tsx |
Switches SiteType to shared global type and adjusts selector typings/props. |
assets/src/admin/onboarding/index.tsx |
Removes in-file global typing in favor of shared global typings. |
__mocks__/@wordpress/api-fetch.ts |
Adds a manual Jest mock for the WordPress apiFetch module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
bc24603 to
c1041f1
Compare
up1512001
left a comment
There was a problem hiding this comment.
TL:DR I did not check all test assuming its fully AI generated so no need to waste efforts on that, overall LGTM, just one question.
* dev: update scaffold * chore: temp-disable `.lefthook.yml` * chore: copilot feedback * ci: fix references * ci: fix translation command * fix: Remediate PHPCS lints (#147) * fix: Remediate PHPCS lints * fix: Remediate eslint + ts smells (#148) * fix: remediate eslint and ts errors * ci: fix playwright path * fix: phpstan errors (#149) * chore: cleanup configs * ci: bump actions * tests: backfill Jest tests (#152) * tests: backfill jest tests * ci: remove `--passWithNoTests` flag * fix: copilot feedback
|
cc @Kallyan01 for a prompt example |
Description
This PR backfills JS Unit tests.
Important
This PR is based on #146 which should be merged first.
Technical Details
Initial work was created with the following prompts (with oh-my-opencode + glm-5)
Then I reviewed file by file, prompting or manually fixing changes.
Checklist
Screenshots
To-do
Fixes/Covers issue
Fixes #