Add more unit tests and component tests#1289
Conversation
WalkthroughAdds many Vitest test suites for dashboard and ui packages, splits Vitest configs into unit (node) and component (jsdom) projects with package-level setup, updates ui package test scripts/deps/tsconfig, and adds CI jobs to run UI unit/component tests before dashboard E2E. ChangesTest infrastructure and CI
Feature test coverage
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
jwfing
left a comment
There was a problem hiding this comment.
Code Review — Add more unit tests and component tests
Summary: Good coverage addition across analytics, compute, database, functions, realtime, storage, and core utils. The vitest config refactor (splitting environment per config type) is a clean improvement. No blocking issues found.
Requirements context
No spec or plan under /docs/superpowers/ matches this PR's scope (pure test coverage improvement with a config refactor). Assessed against the PR description alone: add unit/component tests across the dashboard and align vitest environments per config type.
Findings
Critical
(none)
Suggestion
[Software Engineering] vitest.config.ts still runs unit .ts tests under jsdom
packages/dashboard/vitest.config.ts:9
The default config includes src/**/*.test.{ts,tsx} with environment: 'jsdom'. This is a superset of both the unit config (.ts → node) and the component config (.tsx → jsdom). As a result, running vitest without an explicit --config flag still executes all unit tests (.ts) in jsdom rather than node. The environment improvement only applies when callers explicitly use vitest.unit.config.ts. Consider noting this in the PR or a follow-up comment/script, or accepting the default config as a "run-everything-in-jsdom" convenience while specialized configs enforce stricter environments in CI.
[Functionality] BucketFormDialog.test.tsx — only create mode tested
packages/dashboard/src/features/storage/components/__tests__/BucketFormDialog.test.tsx:26–47
The mock exposes editBucket but no test exercises the edit mode. A follow-up test would verify that submitting in edit mode calls editBucket (not createBucket) with the updated name.
[Functionality] ChannelFormDialog.test.tsx — only happy-path create tested
packages/dashboard/src/features/realtime/components/__tests__/ChannelFormDialog.test.tsx:7–25
No coverage for: submitting with an empty/invalid pattern (validation rejection), or the edit flow if the component supports it. These would be valuable to add alongside the existing test.
[Functionality] DeleteServiceDialog.test.tsx — error path not covered
packages/dashboard/src/features/compute/components/__tests__/DeleteServiceDialog.test.tsx:7–33
The test exercises the full success path. Worth adding a case where onConfirm rejects — verify the dialog stays open and an error state (if any) is displayed, so that regression protection exists if error handling is changed later.
Information
[Software Engineering] Prefer jest-dom matchers for disabled assertions
packages/dashboard/src/features/compute/components/__tests__/DeleteServiceDialog.test.tsx:21,24
packages/dashboard/src/features/storage/components/__tests__/S3AccessKeyCreateDialog.test.tsx:47,51
// current
expect((deleteButton as HTMLButtonElement).disabled).toBe(true);
// preferred — setup.ts already imports @testing-library/jest-dom/vitest
expect(deleteButton).toBeDisabled();
expect(doneButton).not.toBeDisabled();toBeDisabled() gives a clearer failure message and avoids the as HTMLButtonElement cast.
[Software Engineering] Redundant .toBeTruthy() on getBy* queries
packages/dashboard/src/features/storage/components/__tests__/S3AccessKeyCreateDialog.test.tsx:41–42
expect(screen.getByText('S3 Access Key Created')).toBeTruthy();
expect(screen.getByDisplayValue(createdKey.accessKeyId)).toBeTruthy();getBy* queries throw if the element is not found, so .toBeTruthy() is redundant. Prefer toBeInTheDocument() from jest-dom (already available via setup.ts) for a more descriptive failure message, or omit the expect wrapper entirely and rely on the query throw.
Verdict
approved (informational — no Critical findings; a human must give the explicit GitHub approval)
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/dashboard/src/features/realtime/components/__tests__/ChannelFormDialog.test.tsx (1)
17-24: ⚡ Quick winConsider asserting dialog closing for consistency.
The other dialog tests in this PR (DeleteServiceDialog, CreateBackupDialog, RenameBackupDialog) all verify that
onOpenChange(false)is called after the action completes. Adding the same assertion here would maintain consistency and ensure the dialog closes properly after channel creation.Suggested addition
await waitFor(() => { expect(onCreate).toHaveBeenCalledWith({ pattern: 'room:%', enabled: true, description: 'Room updates', webhookUrls: undefined, }); + expect(onOpenChange).toHaveBeenCalledWith(false); });To support this assertion, capture the mock at line 11:
-render(<ChannelFormDialog mode="create" open onOpenChange={vi.fn()} onCreate={onCreate} />); +const onOpenChange = vi.fn(); +render(<ChannelFormDialog mode="create" open onOpenChange={onOpenChange} onCreate={onCreate} />);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/dashboard/src/features/realtime/components/__tests__/ChannelFormDialog.test.tsx` around lines 17 - 24, The test should also assert the dialog is closed by verifying onOpenChange(false) is called; add a jest mock for onOpenChange (e.g., const onOpenChange = jest.fn()) and pass it into the rendered ChannelFormDialog in the test, then extend the existing waitFor block that checks onCreate to also expect(onOpenChange).toHaveBeenCalledWith(false). Ensure you place the onOpenChange mock alongside the existing onCreate mock so the test verifies both channel creation (onCreate) and dialog closing (onOpenChange(false)).packages/dashboard/src/lib/utils/__tests__/utils.test.ts (1)
37-42: ⚡ Quick winStrengthen the formatTime assertion to verify time component.
The test at line 39 uses
toMatch(/May 17, 2026/)which only verifies the date portion. Since the function is namedformatTime(notformatDate), the assertion should verify that time information is included in the output.🧪 Proposed enhancement to verify time component
- expect(formatTime('2026-05-17T12:30:00.000Z')).toMatch(/May 17, 2026/); + expect(formatTime('2026-05-17T12:30:00.000Z')).toMatch(/May 17, 2026.*12:30/);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/dashboard/src/lib/utils/__tests__/utils.test.ts` around lines 37 - 42, The test for formatTime only checks the date portion; update the assertion for formatTime('2026-05-17T12:30:00.000Z') to also verify the time component is present (e.g. assert the output contains "12:30" or matches a time regex like /,\s*\d{1,2}:\d{2}/ or a locale time pattern) while keeping the invalid-input check unchanged; locate the test in the describe('formatTime') block and modify the expect for formatTime accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/dashboard/vitest.config.ts`:
- Around line 9-11: The root vitest config currently sets environment: 'jsdom'
and include: ['src/**/*.test.{ts,tsx}'] (with setupFiles) which causes unit and
component tests to run in jsdom; update this file to stop mixing environments by
either removing the test configuration entirely so vitest.unit.config.ts and
vitest.component.config.ts are used exclusively, or change the include pattern
to only component tests (e.g., include only *.test.tsx) and keep environment:
'jsdom' and setupFiles only for component runs; locate the keys environment,
include and setupFiles in vitest.config.ts to apply the change.
---
Nitpick comments:
In
`@packages/dashboard/src/features/realtime/components/__tests__/ChannelFormDialog.test.tsx`:
- Around line 17-24: The test should also assert the dialog is closed by
verifying onOpenChange(false) is called; add a jest mock for onOpenChange (e.g.,
const onOpenChange = jest.fn()) and pass it into the rendered ChannelFormDialog
in the test, then extend the existing waitFor block that checks onCreate to also
expect(onOpenChange).toHaveBeenCalledWith(false). Ensure you place the
onOpenChange mock alongside the existing onCreate mock so the test verifies both
channel creation (onCreate) and dialog closing (onOpenChange(false)).
In `@packages/dashboard/src/lib/utils/__tests__/utils.test.ts`:
- Around line 37-42: The test for formatTime only checks the date portion;
update the assertion for formatTime('2026-05-17T12:30:00.000Z') to also verify
the time component is present (e.g. assert the output contains "12:30" or
matches a time regex like /,\s*\d{1,2}:\d{2}/ or a locale time pattern) while
keeping the invalid-input check unchanged; locate the test in the
describe('formatTime') block and modify the expect for formatTime accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: eab99413-1bcc-4034-b1dc-2f5e40166e86
📒 Files selected for processing (14)
packages/dashboard/src/features/analytics/lib/__tests__/format.test.tspackages/dashboard/src/features/compute/components/__tests__/DeleteServiceDialog.test.tsxpackages/dashboard/src/features/database/__tests__/helpers.test.tspackages/dashboard/src/features/database/components/__tests__/CreateBackupDialog.test.tsxpackages/dashboard/src/features/database/components/__tests__/RenameBackupDialog.test.tsxpackages/dashboard/src/features/functions/__tests__/helpers.test.tspackages/dashboard/src/features/realtime/components/__tests__/ChannelFormDialog.test.tsxpackages/dashboard/src/features/storage/components/__tests__/BucketFormDialog.test.tsxpackages/dashboard/src/features/storage/components/__tests__/S3AccessKeyCreateDialog.test.tsxpackages/dashboard/src/lib/utils/__tests__/utils.test.tspackages/dashboard/vitest.component.config.tspackages/dashboard/vitest.config.tspackages/dashboard/vitest.shared.config.tspackages/dashboard/vitest.unit.config.ts
💤 Files with no reviewable changes (1)
- packages/dashboard/vitest.shared.config.ts
There was a problem hiding this comment.
1 issue found across 14 files
Confidence score: 4/5
- This PR looks safe to merge overall, with only a minor-to-moderate risk centered on test reliability rather than production behavior.
- The main issue is in
packages/dashboard/src/lib/utils/__tests__/utils.test.ts: formatting a...Ztimestamp in local time can shift the calendar day, which may cause flaky failures across different timezones/CI environments. - Given the 4/10 severity and the issue being test-only, risk to end users appears limited, but merge confidence is slightly reduced due to potential intermittent CI instability.
- Pay close attention to
packages/dashboard/src/lib/utils/__tests__/utils.test.ts- timezone-dependent date expectations may fail unpredictably across environments.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/dashboard/src/lib/utils/__tests__/utils.test.ts">
<violation number="1" location="packages/dashboard/src/lib/utils/__tests__/utils.test.ts:39">
P2: This test is timezone-dependent: a `...Z` timestamp formatted in local time can produce a different calendar day, causing flaky failures across environments.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Re-trigger cubic
Greptile SummaryThis PR adds unit and component test suites across the dashboard and
Confidence Score: 5/5Safe to merge — changes are additive test infrastructure with no modifications to production code paths. All changes are test files, vitest config restructuring, a tsconfig build exclusion, and CI workflow additions. Production source files are untouched. The vitest project split correctly assigns environments, and the date/locale assertions in the new tests are stable because they use date-fns English formatting rather than system locale. No files require special attention. Important Files Changed
Reviews (4): Last reviewed commit: "address comments" | Re-trigger Greptile |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.github/workflows/frontend-tests.yml (1)
52-90: ⚡ Quick winGate dashboard UI tests on the new unit/component jobs for fail-fast CI.
Right now all jobs can run concurrently. Adding
needstodashboard-ui-testsensures the heavier Playwright job only starts after fast UI suites pass.Workflow tweak
dashboard-ui-tests: name: Dashboard UI Tests runs-on: ubuntu-latest + needs: + - dashboard-unit-tests + - dashboard-component-tests + - ui-unit-tests + - ui-component-tests🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/frontend-tests.yml around lines 52 - 90, The dashboard Playwright job currently can run in parallel with the new UI jobs; update the GitHub Actions workflow so the dashboard Playwright job (dashboard-ui-tests) depends on the fast UI jobs by adding a needs: entry referencing the new job ids (ui-unit-tests and ui-component-tests) so dashboard-ui-tests only starts after those pass; modify the dashboard-ui-tests job definition to include needs: [ui-unit-tests, ui-component-tests].
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.github/workflows/frontend-tests.yml:
- Around line 52-90: The dashboard Playwright job currently can run in parallel
with the new UI jobs; update the GitHub Actions workflow so the dashboard
Playwright job (dashboard-ui-tests) depends on the fast UI jobs by adding a
needs: entry referencing the new job ids (ui-unit-tests and ui-component-tests)
so dashboard-ui-tests only starts after those pass; modify the
dashboard-ui-tests job definition to include needs: [ui-unit-tests,
ui-component-tests].
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 981f0f5f-89c8-42c7-8df1-34923317c5a6
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (11)
.github/workflows/frontend-tests.ymlpackages/ui/package.jsonpackages/ui/src/components/__tests__/Button.test.tsxpackages/ui/src/components/__tests__/Input.test.tsxpackages/ui/src/components/__tests__/SearchInput.test.tsxpackages/ui/src/lib/__tests__/utils.test.tspackages/ui/src/test/setup.tspackages/ui/tsconfig.build.jsonpackages/ui/vitest.component.config.tspackages/ui/vitest.config.tspackages/ui/vitest.unit.config.ts
✅ Files skipped from review due to trivial changes (5)
- packages/ui/src/test/setup.ts
- packages/ui/vitest.component.config.ts
- packages/ui/vitest.config.ts
- packages/ui/vitest.unit.config.ts
- packages/ui/src/lib/tests/utils.test.ts
jwfing
left a comment
There was a problem hiding this comment.
Summary
Solid test-coverage expansion across analytics, database, storage, compute, realtime, and @insforge/ui primitives, with a well-executed vitest config split into node/jsdom project environments.
Requirements context
No matching spec/plan found under /docs/superpowers/ — this is a standalone test-addition initiative. Assessment is against the PR description and the implicit requirement of "increase coverage without breaking existing behaviour."
Findings
Critical
(none)
Suggestion
Software engineering — missing edit-mode coverage for ChannelFormDialog
packages/dashboard/src/features/realtime/components/__tests__/ChannelFormDialog.test.tsx:1-26
The component accepts both mode="create" and mode="edit". In edit mode the form is pre-populated from the channel prop, the submit button label changes to "Save Channel", and the callback interface is different (onEdit vs onCreate). Only create mode is tested. The edit path has distinct logic (diff webhook comparison at ChannelFormDialog.tsx:133-139) that would benefit from at least one test.
Software engineering — @insforge/ui vitest configs have no shared base
packages/ui/vitest.component.config.ts, packages/ui/vitest.unit.config.ts
Unlike the dashboard package (which uses mergeConfig(sharedConfig, ...) to share path aliases and other settings), the UI configs are fully standalone. Right now this is fine because tests only use relative imports. But if path aliases or global test options are ever needed, both files must be updated independently with no shared source. Consider extracting a vitest.shared.config.ts following the dashboard's pattern to avoid future divergence.
Information
Software engineering — direct .disabled property access instead of jest-dom matchers
packages/dashboard/src/features/compute/components/__tests__/DeleteServiceDialog.test.tsx:21, packages/dashboard/src/features/storage/components/__tests__/S3AccessKeyCreateDialog.test.tsx:45
// current
expect((deleteButton as HTMLButtonElement).disabled).toBe(true);
// clearer with @testing-library/jest-dom
expect(deleteButton).toBeDisabled();@testing-library/jest-dom is a common companion library that provides DOM-aware matchers with better failure messages. If the project chooses to add it, a one-line import in each setup file covers all tests. Not a blocker — the current assertions are functionally correct.
Software engineering — BucketFormDialog and S3AccessKeyCreateDialog cover only the happy path
packages/dashboard/src/features/storage/components/__tests__/BucketFormDialog.test.tsx, packages/dashboard/src/features/storage/components/__tests__/S3AccessKeyCreateDialog.test.tsx
Edit mode for BucketFormDialog and error/rejection paths for both dialogs are not covered. Fine for a first-pass PR; just noting so follow-up work is tracked.
Software engineering — @insforge/ui gets its own hoisted [email protected] install
packages/ui/package.json:78-85, package-lock.json
The lock file shows a nested packages/ui/node_modules/vitest block. If the workspace root already provides the same version of vitest to all packages, the package-level devDependency is redundant. Minor install-time overhead only; no functional issue.
Verdict
approved (informational — no Critical findings; explicit GitHub approval via the approve flow)
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
Summary
Add more tests
Summary by cubic
Add unit and component tests across the dashboard and
@insforge/uito improve coverage for analytics, helpers, dialogs, storage, realtime channels, core utils, and UI components. Splitvitestconfigs per package and update CI to run separate UI tests and gate dashboard E2E on all test jobs.Refactors
vitestinto named projects for dashboard and@insforge/ui: unit usesnode; component usesjsdomwith package-localsrc/test/setup.ts.jsdomenv andsetupFilesout of shared configs into component configs; added project names.@insforge/uitest scripts and excluded tests from build; CI runsui-unit-testsandui-component-tests, and gatesdashboard-e2e-testson all unit/component jobs.Dependencies
@insforge/uidev deps:vitest,jsdom,@testing-library/react,@testing-library/user-event.Written for commit 6eb6460. Summary will update on new commits. Review in cubic
Note
Add unit and component tests for dashboard features and split vitest configs by environment
DeleteServiceDialog,CreateBackupDialog,RenameBackupDialog,BucketFormDialog,S3AccessKeyCreateDialog,ChannelFormDialog).jsdomenvironment andsetupFilesconfig out of vitest.shared.config.ts into individual config files, setting unit tests tonodeenvironment and component/general tests tojsdom.Changes since #1289 opened
vitest,@testing-library/react,@testing-library/user-event, andjsdomas devDependencies to the@insforge/uipackage, configured separatevitest.unit.config.tsandvitest.component.config.tsprojects usingnodeandjsdomenvironments respectively, created test setup runningcleanup()viaafterEachhook, addedtest,test:unit, andtest:componentnpm scripts, excluded test files from build viatsconfig.build.json, and integratedui-unit-testsandui-component-testsjobs into GitHub Actions workflow running workspace-scoped vitest commands onubuntu-latestwith Node.js v20 [416986c]Buttoncomponent verifying native attribute forwarding includingtype,disabled, andclassName, class application based on variant and size props, andasChildprop rendering child anchor elements with expected role, href, and classes [416986c]Inputcomponent asserting placeholder attribute passthrough, value updates andonChangehandler invocation per keystroke during typing, disabled state support, and custom className application [416986c]SearchInputcomponent covering immediate and committed change callbacks whendebounceTimeequals zero, and clear button functionality that resets input value and invokes callbacks with empty string [416986c]cnutility function validating conditional class merging and Tailwind CSS conflict resolution, expecting outputtext-sm px-4from mixed input classes [416986c]Macroscope summarized 6ed78f2.
Summary by CodeRabbit
Tests
Chores