Add comprehensive unit test suite with 97% coverage#1
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit introduces a complete unit testing infrastructure for the Query Picker plugin with excellent code coverage.
Changes:
Test Coverage:
Test Categories:
All tests are passing (18/18) and coverage exceeds the 70% thresholds set for all metrics.