CodeRabbit Generated Unit Tests: Add generated unit tests #37
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ckreidl/katana!37
Loading…
Reference in a new issue
No description provided.
Delete branch "coderabbitai/utg/61ea0df"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Unit test generation was requested by @chris-kreidl.
The following files were modified:
packages/katana-planner-gui/package.jsonpackages/katana-planner-gui/scripts/build-docs.test.tspackages/katana-planner-gui/src/components/App.test.tsxpackages/katana-planner-gui/src/components/HelpTab.test.tsxComment
@coderabbitai helpto get the list of available commands and usage tips.@coderabbitai are you able to see the review comments i made?
🧩 Analysis chain
🏁 Script executed:
Length of output: 7661
Yes, I can see both of your review comments! Let me read the test files and their corresponding source components to give you a proper response.
🏁 Script executed:
Length of output: 34089
Let me also check the package dependencies to understand what testing utilities are available.
🏁 Script executed:
Length of output: 15944
@chris-kreidl— Yes, you are completely right on both counts. Here's what's actually happening:Root cause: No DOM environment or React renderer is installed
packages/katana-planner-gui/package.jsonhas no@testing-library/react,happy-dom, orjsdomin its devDependencies. Without a DOM environment, React components that use hooks (useState,useEffect, etc.) cannot be meaningfully rendered or interacted with in tests.App.test.tsx— specific problemsApp({ api: mockApi })is called as a plain function. Because there's no React renderer, the hooks (useEffect,useState) never actually execute, soapi.getState()is never triggered by the component itself."App state management"and"App API interactions"callsmockApi.getState()directly and then asserts on the values the mock itself returns — theAppcomponent is never involved at all."validates planningHorizonDays is a positive number"are pure tautologies: the mock returns14, and the test asserts14 > 0. The component's actual behavior (loading state, error state, rendered tabs) is never exercised.HelpTab.test.tsx— specific problemsmockDocsis defined inline and never replaced with the realdocsmodule imported inHelpTab.tsx. Tests in"HelpTab documentation content"are asserting on data the test file invented, not the actual docs."HelpTab state management"tests reassign a plainletvariable (let active = ...), not actual React component state."uses semantic button elements for navigation"asserts"button" === "button"— completely meaningless."getting-started"— are never verified.What good tests would look like
The
build-docs.test.tsin this same PR is a great example: it runs actual build logic against real temp files and asserts on real output.For the React components, meaningful tests require adding to
devDependencies:With those in place, a test for
HelpTabthat actually tests the component would look like:Would you like me to rewrite both test files using this approach? I can add the necessary dependencies and produce tests that genuinely exercise the components' behavior.
🧠 Learnings used
@coderabbitai yes, please. feel free to add those deps and rewrite the tests. if we're going to do something, let's do it right.
🧩 Analysis chain
🏁 Script executed:
Length of output: 10611
@chris-kreidl— Absolutely, let's do it right. Here's the full plan:Plan: Rewrite test files with real DOM rendering
@happy-dom/global-registrator,@testing-library/react, and@testing-library/domtodevDependenciesApp.test.tsx: mock child components + UI primitives, usewaitForto test asyncuseEffectlifecycle (loading → success / error / unavailable)HelpTab.test.tsx: mockbuild/docs.jsbuild artifact, test all 4 nav buttons render, default active state, click-to-navigate, and content-pane updates🧠 Learnings used
💡 Use
@coderabbitaiplan to create a plan for code changes@coderabbitai am i implementing this plan or are you?
🧩 Analysis chain
@chris-kreidl— You don't have to lift a finger! I'll implement all three changes now.Task: Add proper testing deps and rewrite App + HelpTab tests
@happy-dom/global-registrator,@testing-library/react,@testing-library/domtodevDependenciesinpackages/katana-planner-gui/package.jsonpackages/katana-planner-gui/src/components/HelpTab.test.tsxwith real DOM rendering via@testing-library/react, mocking thebuild/docs.jsartifact and shadcn Card primitivespackages/katana-planner-gui/src/components/App.test.tsxwith real DOM rendering, mocking all child components and testing all four render branches (loading, error, unavailable, loaded)🏁 Script executed:
Length of output: 2366
🏁 Script executed:
Length of output: 16335
🏁 Script executed:
Length of output: 18125
@chris-kreidl— You! I lay out the plan with the full code; another agent actually commits it. Let me kick that off right now.Task: Add real testing deps + rewrite App & HelpTab tests
@happy-dom/global-registrator,@testing-library/react,@testing-library/domtopackages/katana-planner-gui/package.jsonHelpTab.test.tsx: mockbuild/docs.js+ shadcn Card, render component, test nav buttons, active state, content pane updatesApp.test.tsx: mock all children + primitives, test loading / error / unavailable / loaded render branches withwaitFor🧠 Learnings used
💡 Use
@coderabbitaiplan to create a plan for code changesReview the following changes in direct dependencies. Learn more about Socket for GitHub.
Security
View full report
@coderabbitai i've pushed the test changes to this branch. please review.
🧩 Analysis chain
🏁 Script executed:
Length of output: 34480
🏁 Script executed:
Length of output: 735
🏁 Script executed:
Length of output: 118
@chris-kreidl— Great work! The overall quality of these tests is genuinely solid. Here's the full review:✅ What's working well
test-setup.ts+bunfig.toml— RegisteringGlobalRegistratorin a shared preload is the right approach. Clean and DRY — no need to repeat it in every file.HelpTab.test.tsxmock.module("../../build/docs.js")path matches whatHelpTab.tsximports. Bun hoists it, so the position after imports is fine functionally.within(nav).getAllByRole("button")is a nice scoped query — avoids false positives from buttons outside the nav.document.body.innerHTML = ""inbeforeEachis good hygiene.App.test.tsxstubSettingshas the completeSettingsConfigshape (all 12 fields fromtypes.ts). ✅makeApicovers all 12 methods ofApiSurface. ✅spyOn(console, "error")suppression in error tests is exactly right.build-docs.test.ts— Excellent breadth: 14 cases covering headings, lists, links, code blocks, tables, inline styles, special characters, empty files, non-MD file filtering, slug generation, and output format. All good.⚠️ Issues to address
1.
tsconfig.jsondoesn't include test files — type-checking is blind to thempackages/katana-planner-gui/tsconfig.jsonhas a narrowinclude:This excludes
src/components/**/*.test.tsx,scripts/build-docs.test.ts, andtest-setup.ts. Runningbun run typecheckwill never catch type errors in these files. Consider adding a separatetsconfig.test.json:And updating the
typecheckscript:2.
build-docs.test.ts— Glob setup is duplicated across 13 of 14 testsEvery test case repeats the same 7-line setup:
Extracting it to a helper reduces noise and makes individual tests much easier to read:
Both issues are minor — the tests will run and pass as-is. The tsconfig gap is worth fixing before this merges since it leaves type errors in test code invisible to CI. The DRY refactor is just a readability win.
🧠 Learnings used
🧩 Analysis chain
🏁 Script executed:
Length of output: 34384
🏁 Script executed:
Length of output: 680
🏁 Script executed:
Length of output: 206
@chris-kreidl— These are looking significantly better than the original tests. Thetest-setup.ts+bunfig.tomlpreload approach is a clean pattern for global DOM setup. Here's the full review:✅ What's solid
test-setup.ts+bunfig.tomlpreload — registeringhappy-domglobally is cleaner than per-filebeforeAll/afterAllblocks.stubSettings— complete and accurate against the realSettingsConfigtype fromkatana-planner/src/types.spyOn(console, "error").mockImplementation(() => {})+spy.mockRestore()— correctly suppresses and restores expected error output.callscounter approach to test the retry flow is well-done.within(nav).getAllByRole("button")— scoping queries to the nav element is the right way to avoid false matches.beforeEach(() => { document.body.innerHTML = ""; })— proper DOM cleanup between tests.🔴 Issue 1 —
App.test.tsx: Missing mocks for@/components/ui/tabsandlucide-reactThe
@/components/ui/tabsimport is not mocked. Yourpackage.jsonshows"@base-ui/react": "^1.2.0"as a dependency — shadcn Tabs in this project is likely built on@base-ui/react, which only renders active tab content into the DOM by default. WithdefaultValue="general", thesales-ordersandpurchase-orderstab panels may never be inserted into the DOM, causing these assertions to fail at runtime:The fix is to add mocks for both modules before
Appis imported, the same way the child components are mocked:🟡 Issue 2 —
HelpTab.test.tsx: Missing mock for@/components/ui/cardHelpTab.tsximportsCard,CardContent,CardHeader,CardTitle,CardDescriptionfrom@/components/ui/cardbut none of these are mocked. This likely works in practice since shadcn Card components are thin wrappers, but it's inconsistent — if@base-ui/reactis involved here too, or if a future refactor makes the Card non-trivial, these tests will silently break. Add the mock for consistency and isolation:🟡 Issue 3 —
build-docs.test.ts: Significant code duplicationThe glob/scan/convert logic is copy-pasted verbatim into all 14 test cases. This means a single change to the build logic requires 14 edits, and the tests don't actually test the
build-docs.tsmodule — they test a re-implemented copy of it. Extract a shared helper:Then each test becomes just:
🧠 Learnings used
@coderabbitai
Regarding Issue 1:
Tabs triggers vs. panels: The test "renders loaded state with tabs" asserts screen.getByText("General MOs"), "Sales-Order MOs", and "Purchase Orders" — these are TabsTrigger texts (the tab buttons), which are always rendered in the DOM regardless of which panel is active. The only TabsContent assertion is screen.getByTestId("general-mo-tab"), which is the default active tab.
No test asserts that the sales-order-tab or purchase-order-tab panels are in the DOM, so @base-ui/react's behavior of only mounting the active panel doesn't affect any assertions.
lucide-react: It's a real dependency that renders inline SVGs. It works fine in happy-dom without mocking — the icons are just
Regarding issue 2:
Cardand its brethren are just a stylistics wrapper, there are no calculations or actions performed by them.@chris-kreidl— You're right on all three counts, I was mistaken.Tabs triggers vs panels —
TabsTriggerlabels are always rendered regardless of active panel, and the only panel assertion isgeneral-mo-tab(the default active one). My concern about@base-ui/reactonly mounting the active panel was a red herring given the actual assertions in the test.lucide-react— It produces plain<svg>elements; happy-dom handles those fine. No mock needed.Cardwrappers — Purely stylistic, no logic to isolate. Mocking them would be noise.I'll record these for future reviews:
✏️ Learnings added
🧠 Learnings used
@coderabbitai And regarding issue 3,
build-docs.tsdoesn't exist on this branch yet -- we can refactor this once everything's been merged.@chris-kreidl— That makes complete sense. Oncebuild-docs.tslands and the refactor can target the real module rather than a re-implementation, it'll be a cleaner change anyway.Would you like me to open a follow-up issue to track the
build-docs.test.tsDRY refactor so it doesn't get lost after merge?🧠 Learnings used
@coderabbitai yes please
🧩 Analysis chain
🏁 Script executed:
Length of output: 48
@chris-kreidl— Done! Issue#38has been opened to track thebuild-docs.test.tsDRY refactor: https://github.com/chris-kreidl/katana/issues/38🧠 Learnings used
@coderabbitai wait a second. I just realized you branched off of
mainwhen creating this branch, notdocs, where the request for these tests originally came from (and wherebuild-docs.tsdoes exist)🧩 Analysis chain
🏁 Script executed:
Length of output: 13853
@chris-kreidl— That's a significant catch. Here's the full picture:PR
#37is based onmain(confirmed bygh pr view). Sincebuild-docs.tslives ondocsbut not onmain, there are two cascading problems:build-docs.tsis absent from this branch — so the tests can't import or call it.build-docs.tsat all — they re-implement the glob/scan/convert logic inline across all 14 cases. Even after a rebase, the tests would still need to be rewritten to call the real module rather than duplicating its internals.In the current state, a regression in
build-docs.tswould not be caught by any of these tests, because they're testing a copy of the logic.Recommended path forward:
The cleanest fix is to re-target this PR to
docsas its base, then updatebuild-docs.test.tsto import and call the real script. Something like:This would also naturally resolve the duplication that issue
#38was tracking.On issue
#38: I should close it — it was opened under the incorrect assumption thatbuild-docs.tsdidn't exist yet. Once this is rebased ontodocsand the test is updated to use the real module, the issue is moot. Want me to close it now?🧠 Learnings used
@coderabbitai i've rebased the branch and refactored
build-docs.test.ts-- care to take a look?🧩 Analysis chain
🏁 Script executed:
Length of output: 16898
@chris-kreidl— The refactoredbuild-docs.test.tsis exactly right. Here's the full review:✅
build-docs.test.ts— solidbuildDocs— no more re-implemented copy of the logic. A regression inbuild-docs.tswill now actually be caught. ✅writeDocshelper — clean way to reduce per-test file-writing boilerplate without duplicating the scan logic. ✅Date.now() + Math.random()) +afterEachcleanup — proper test isolation, no inter-test interference. ✅entriesobject and the written file's content/format (startWith("export default "),endWith("};")) in one test. Good dual assertion. ✅deepOutpath with nested dirs (a/b/c/docs.js) to exercise themkdirSync(dirname(outFile), { recursive: true })path in the real module. ✅"export default {};". ✅✅
App.test.tsxandHelpTab.test.tsxUnchanged from the last review — still solid. No new issues.
🟡 One carry-over:
tsconfig.jsonstill excludes test filesFrom the earlier review —
typecheckonly coverstsconfig.json, which doesn't include*.test.tsx,scripts/**/*.test.ts, ortest-setup.ts. Type errors in the test files remain invisible to CI. This isn't a blocker for merge, but worth tracking.🔵 Issue
#38can now be closedThe duplication that prompted that issue is fully resolved by this refactor. Want me to close it?
🧠 Learnings used
@coderabbitai yes, please close it
🧩 Analysis chain
🏁 Script executed:
Length of output: 130
@chris-kreidl— Done! Issue#38is now closed with a note pointing back to this PR as the resolution.🧠 Learnings used