Skip to content

tests: backfill Jest tests#152

Merged
justlevine merged 3 commits into
test/skeleton-migrationfrom
tests/backfill-jest
Mar 10, 2026
Merged

tests: backfill Jest tests#152
justlevine merged 3 commits into
test/skeleton-migrationfrom
tests/backfill-jest

Conversation

@justlevine
Copy link
Copy Markdown
Collaborator

Description

This PR backfills JS Unit tests.

Important

This PR is based on #146 which should be merged first.

Technical Details

  1. Initial work was created with the following prompts (with oh-my-opencode + glm-5)

    Backfill Jest tests for our plugin. Tests should follow best practices, and provide full coverage.
    - Test behavior and outcomes, not implementation details.
    - Don't mock unnecessarily.
    - Ensure tests pass and that `npm run lint:js`, `npm run lint:js:types` pass.
    - No slop.
    1. Run `npm run test:js:coverage` to see the current coverage report
    2. Choose a file with inadequate test coverage in assets/src, study it, and make a plan to add tests to it.
    3. Implement the tests.
    4. Run `npm run test:js:coverage` and ensure the tests pass and coverage improve.
    5. Run `npm run lint:js && npm run lint:js:types` and fix any issues with the tests. Run `npm run test:js:coverage` to verify your work didnt break anything.
    6. Repeat steps 1-6 until we have full test coverage.
    ulw
    Review the existing Jest tests on this branch and deslopify them. Ensure they follow best practices, test real outcomes and not implementation details, and follow best practices. 
    1. Analyze the files in `tests/js` and audit them for slop.
    2. Make a plan and implement any changes you believe are justified.
    3. Ensure `npm run lint:js`, `npm run lint:js:types` and `npm run lint:js:coverage` all pass.
  2. Then I reviewed file by file, prompting or manually fixing changes.

Checklist

Screenshots

justl@LevineWork:~/work/sites/wptest/repos/onesearch$ npm run test:js:coverage

> test:js:coverage
> wp-scripts test-unit-js --coverage --passWithNoTests

 PASS   onesearch  tests/js/utils.test.ts
 PASS   onesearch  tests/js/SettingsPage.test.tsx
 PASS   onesearch  tests/js/AlgoliaSettings.test.tsx
 PASS   onesearch  tests/js/OnboardingScreen.test.tsx
 PASS   onesearch  tests/js/SiteTable.test.tsx
 PASS   onesearch  tests/js/MultiSelectChips.test.tsx
 PASS   onesearch  tests/js/SiteModal.test.tsx
 PASS   onesearch  tests/js/SiteSettings.test.tsx
 PASS   onesearch  tests/js/SiteIndexableEntities.test.tsx
 PASS   onesearch  tests/js/SiteSearchSettings.test.tsx
---------------------------|---------|----------|---------|---------|-------------------------------------
File                       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                   
---------------------------|---------|----------|---------|---------|-------------------------------------
All files                  |   92.11 |    79.13 |   85.61 |   92.14 |                                     
 admin/onboarding          |   90.32 |    81.25 |      90 |   90.32 |                                     
  page.tsx                 |   90.32 |    81.25 |      90 |   90.32 | 114,121,140                         
 admin/settings            |   90.19 |       80 |    87.5 |      90 |                                     
  page.tsx                 |   90.19 |       80 |    87.5 |      90 | 102,138,144,152,161                 
 components                |   92.21 |    78.66 |   84.74 |   92.27 |                                     
  AlgoliaSettings.tsx      |   93.33 |     87.5 |     100 |   92.85 | 63,99                               
  MultiSelectChips.js      |   91.66 |    67.34 |   88.23 |   91.11 | 50,66,115,145                       
  SiteIndexableEntities.js |   90.66 |    71.42 |   88.88 |   90.54 | 60,107,149,182,193,326-344          
  SiteModal.tsx            |   90.32 |    80.39 |   55.55 |   90.16 | 72,150,224-263                      
  SiteSearchSettings.js    |   90.32 |    80.48 |   84.21 |    90.9 | 141,185-196,217-224,232,399,474,532 
  SiteSettings.tsx         |   96.82 |    95.45 |   73.33 |   96.82 | 195,297                             
  SiteTable.tsx            |     100 |      100 |     100 |     100 |                                     
 js                        |     100 |      100 |     100 |     100 |                                     
  utils.ts                 |     100 |      100 |     100 |     100 |                                     
---------------------------|---------|----------|---------|---------|-------------------------------------

=============================== Coverage summary ===============================
Statements   : 92.11% ( 479/520 )
Branches     : 79.13% ( 292/369 )
Functions    : 85.61% ( 125/146 )
Lines        : 92.14% ( 469/509 )
================================================================================

Test Suites: 10 passed, 10 total
Tests:       63 passed, 63 total
Snapshots:   0 total
Time:        4.913 s, estimated 5 s
Ran all test suites.

To-do

Fixes/Covers issue

Fixes #

@justlevine justlevine changed the title Tests/backfill jest tests: backfill Jest tests Mar 10, 2026
@justlevine
Copy link
Copy Markdown
Collaborator Author

justlevine commented Mar 10, 2026

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.

@justlevine justlevine changed the base branch from develop to test/skeleton-migration March 10, 2026 00:42
@justlevine justlevine requested a review from Copilot March 10, 2026 00:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread tests/js/setup.ts
Comment thread tests/js/OnboardingScreen.test.tsx Outdated
Copy link
Copy Markdown
Member

@up1512001 up1512001 left a comment

Choose a reason for hiding this comment

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

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.

Comment thread assets/src/admin/settings/page.tsx
@justlevine justlevine merged commit f6384fa into test/skeleton-migration Mar 10, 2026
1 check passed
@justlevine justlevine deleted the tests/backfill-jest branch March 10, 2026 14:29
justlevine added a commit that referenced this pull request Mar 10, 2026
* 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
@justlevine
Copy link
Copy Markdown
Collaborator Author

cc @Kallyan01 for a prompt example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants