Skip to content

Conversation

@pbking
Copy link
Collaborator

@pbking pbking commented Dec 12, 2025

This commit introduces a complete unit testing infrastructure for the Query Picker plugin with excellent code coverage.

Changes:

  • Added Jest configuration (jest.config.js) with custom settings
  • Created Jest setup file (jest.setup.js) for test environment
  • Implemented 18 comprehensive unit tests in edit.test.jsx
  • Added test scripts to package.json (test, test:watch, test:coverage)
  • Installed testing dependencies (@testing-library/react, @testing-library/jest-dom)
  • Created detailed test documentation (TEST_DOCUMENTATION.md)

Test Coverage:

  • Statements: 97.22%
  • Branch: 95%
  • Functions: 91.66%
  • Lines: 97.05%

Test Categories:

  1. Block Variation Registration - validates WordPress block configuration
  2. Filter Registration - ensures HOC is properly registered
  3. withQueryPickerControls HOC - tests core component logic
  4. Post Selection - validates post picking and state management
  5. Post Type Change Effect - tests React effects and cleanup

All tests are passing (18/18) and coverage exceeds the 70% thresholds set for all metrics.

This commit introduces a complete unit testing infrastructure for the
Query Picker plugin with excellent code coverage.

Changes:
- Added Jest configuration (jest.config.js) with custom settings
- Created Jest setup file (jest.setup.js) for test environment
- Implemented 18 comprehensive unit tests in edit.test.jsx
- Added test scripts to package.json (test, test:watch, test:coverage)
- Installed testing dependencies (@testing-library/react, @testing-library/jest-dom)
- Created detailed test documentation (TEST_DOCUMENTATION.md)

Test Coverage:
- Statements: 97.22%
- Branch: 95%
- Functions: 91.66%
- Lines: 97.05%

Test Categories:
1. Block Variation Registration - validates WordPress block configuration
2. Filter Registration - ensures HOC is properly registered
3. withQueryPickerControls HOC - tests core component logic
4. Post Selection - validates post picking and state management
5. Post Type Change Effect - tests React effects and cleanup

All tests are passing (18/18) and coverage exceeds the 70% thresholds
set for all metrics.
This commit adds a complete PHP unit testing infrastructure
alongside code refactoring for improved testability.

Changes:
- Refactored query-picker.php to use named functions instead of anonymous
  functions for better testability and code organization
- Added PHPUnit 9 configuration (phpunit.xml)
- Created comprehensive PHP unit tests (14 tests, 39 assertions)
- Added Composer configuration with PHPUnit dependency
- Created test bootstrap with WordPress function mocks
- Updated documentation (README.md and TEST_DOCUMENTATION.md)
- Added vendor/ and .phpunit.result.cache to .gitignore

PHP Tests Added:
1. query_loop_block_query_vars filter tests (6 tests):
   - Tests query modification with picked posts
   - Tests fallback behavior without picked posts
   - Tests preservation of existing query args

2. REST API query modification tests (8 tests):
   - Tests REST query modifications
   - Tests type conversion (string IDs to integers)
   - Tests with various data scenarios (single, many, mixed types)
   - Tests order preservation

Test Results:
- All 14 PHP tests passing
- 39 assertions verified
- Covers all public functions
- Tests edge cases and error conditions

Code Quality Improvements:
- Functions now have proper PHPDoc comments
- Better separation of concerns
- Easier to test and maintain
- Follows WordPress coding standards
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