1187 content planner add missing unit tests for components#23209
Open
1187 content planner add missing unit tests for components#23209
Conversation
…components CategoryBadge (category-section.js) and MetaDescriptionProgressBar (outline-modal-content.js) are private components always called with explicit props by their parent. The default values for isEnabled, isLoading, date, locale, and isCornerstone were never reached, causing to flag them as uncovered branches. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…components Adds test files for CategorySection, ContentPlannerEditorItem, ContentSuggestionBlock, InlineBanner, StructureRow, and SuggestionButton, bringing each to 100% statement, branch, function, and line coverage. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t, OutlineModalContent, and FeatureModal SuggestionsModalContent: wrap renders in Modal.Panel to resolve the FocusTrap console warning, add loading text rotation test. OutlineModalContent: cover closeButtonRef focus effect, focus keyphrase and title onChange callbacks, and the fallback category branch when the category toggle is switched off before applying. FeatureModal: cover handleSuggestionClick, handlePanelMeasureChange (via captured useMeasuredRef callback), and the SparksLimitNotification render condition. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…-add-missing-unit-tests-for-components
- Drop `=false` from the `isCornerstone` JSDoc in MetaDescriptionProgressBar to match the already-removed default parameter (JSDoc/code were inconsistent). - Remove redundant `setupMocks()` call from the `handlePanelMeasureChange` test in feature-modal.test.js; `beforeEach` already calls it, so the per-test call was noise. Added a comment clarifying why `mockImplementationOnce` is placed after the `beforeEach` hook. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45aa93c to
eca6840
Compare
Coverage Report for CI Build 61Coverage increased (+0.07%) to 53.701%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
|
A merge conflict has been detected for the proposed code changes in this PR. Please resolve the conflict by either rebasing the PR or merging in changes from the base branch. |
…-add-missing-unit-tests-for-components
…ner and content-planner-editor-item - Add isPremium=true prop verification to with-inline-banner - Add stylesheet injection effect tests (style already present, main link absent, happy-path iframe injection) using a getter-only ref mock to prevent React from overwriting the mock ownerDocument before effects run - Fix missing INJECTED_STYLE_ID in the constants mock (was undefined) - Add minPostsMet=false branch tests to content-planner-editor-item covering disabled button, aria-describedby, helper text rendering, and its conditional flex class for sidebar vs metabox locations
…planner-add-missing-unit-tests-for-components
|
A merge conflict has been detected for the proposed code changes in this PR. Please resolve the conflict by either rebasing the PR or merging in changes from the base branch. |
…planner-add-missing-unit-tests-for-components
…-add-missing-unit-tests-for-components
JorPV
reviewed
May 6, 2026
Contributor
JorPV
left a comment
There was a problem hiding this comment.
CR 🚧
And maybe pull the latest trunk into your branch.
- Restore `date = ""` default on `MetaDescriptionProgressBar` to prevent a TypeError in `countMetaDescriptionLength` when no date prop is passed (`undefined !== ""` is true, causing `date.length` to throw).
- Replace CSS class selector in category-section test with a text query
so the test is not coupled to Tailwind utility class names.
- Replace plain focus mock in outline-modal-content test with a real DOM element and `jest.spyOn`, so the assertion targets the actual element rather than an arbitrary mock object.
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.
Context
Adds the missing unit tests for the AI content planner UI components. All components under `src/ai-content-planner/components/` except the top-level Redux orchestration entry point (`app.js`) now have dedicated test files achieving 100% branch coverage.
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
Removed dead default parameters from private components. Istanbul Classic (the Babel-transform coverage tool used by Jest) tracks each default parameter value as a separate branch.
CategoryBadgeandMetaDescriptionProgressBarare unexported, module-private components whose callers always pass explicit prop values, so the "use default" branches were structurally unreachable. Rather than adding artificial tests that passundefinedto trigger defaults, the defaults were removed from those private components so Istanbul no longer generates unreachable branches for them.Wrapped
SuggestionsModalContentinModal.Panelin tests. headlessui's<Modal>emits aFocusTrapwarning when no focusable element exists inside it. The original test helpers wrapped the component in a bare<div>, which contains no focusable children. Switching to<Modal.Panel closeButtonScreenReaderText="Close">adds the close button that headlessui expects, silencing the warning without needing to suppressconsole.warn.handlePanelMeasureChangeexercised by capturing theuseMeasuredRefcallback. JSDOM does not implementResizeObserver, so the resize callback wired up insideuseMeasuredRefcan never fire through a real DOM resize. The test imports theuseMeasuredRefmock, usesmockImplementationOnceto capture the callback before render, then calls it insideact()after render. This avoids an infinite re-render loop that would occur if the callback were called synchronously inside the mock (calling it mid-render triggerssetPanelHeight, which schedules another render, which calls the mock again, and so on).app.jsexcluded from the coverage target.app.jsis a top-level Redux container orchestration file that wireswithSelect``withDispatchHOCs together. Exercising it at the unit level would require mounting a full Redux store with all slices configured, which is integration-test territory. It is intentionally excluded from the--collectCoverageFromglob used for this PR's coverage check.setupMocks()must be called before overriding individual hook mocks. Infeature-modal.test.js,setupMocks()callsuseFetchContentOutline.mockReturnValue(jest.fn()), which resets any prior mock. Tests that need a specific return value must callsetupMocks()first and then apply their override — calling the override first andsetupMocks()second silently discards it. SincebeforeEachalready callssetupMocks(), per-test overrides are applied in the test body after the hook has run.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
For devs:
Relevant test scenarios
Test instructions for QA when the code is in the RC
Not applicable — this PR only adds unit tests and removes dead default parameters from unexported, module-private components. There is no user-visible behaviour change.
Impact check
This PR only affects `packages/js/tests/ai-content-planner/` (new and updated test files) and two private helper components inside `packages/js/src/ai-content-planner/components/` (`CategoryBadge` and `MetaDescriptionProgressBar`). No user-facing code paths are changed.
Other environments
Documentation
Quality assurance
Innovation
Fixes https://github.com/Yoast/reserved-tasks/issues/1187