Skip to content

test(app): add widget-editor sub-component tests (#578) - #628

Merged
alfredo1996 merged 2 commits into
release/2.0from
test/issue-578-widget-editor-coverage
May 1, 2026
Merged

test(app): add widget-editor sub-component tests (#578)#628
alfredo1996 merged 2 commits into
release/2.0from
test/issue-578-widget-editor-coverage

Conversation

@alfredo1996

@alfredo1996 alfredo1996 commented Apr 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add 55 unit tests across 4 new test files for previously untested widget-editor sub-components
  • parameter-config-section.test.tsx — 16 tests for resolveInternalParamType and reverseParamTypeMapping pure functions including roundtrip verification
  • chart-type-selector.test.tsx — 10 tests for rendering, connection/chart-type selection callbacks, and icon map completeness
  • parameter-config-section-ui.test.tsx — 18 tests for all param types (date/freetext/select), seed query states, collision banners, reference hints
  • form-fields-editor.test.tsx — 11 tests for empty state, add/remove fields, field metadata display, DnD kit mocked

Test plan

  • 55 new tests all passing
  • 2291 total tests passing (171 files)
  • Zero lint errors
  • No production code changed — test-only PR
  • E2E blocked by pre-existing webpack tls module resolution issue (not related to this PR)

Closes #578

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for widget editor UI: chart type selector, form fields editor, and parameter configuration sections.
    • Verifies UI behaviors: option rendering, conditional sections, add/remove field flows, required indicators, parameter hints, seed-query controls and statuses, and type-mapping logic to ensure consistent UI-to-internal mappings.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

Walkthrough

Adds four new Vitest + React Testing Library suites for widget-editor: chart-type-selector, form-fields-editor, parameter-config-section-ui, and parameter-config-section (mapping helpers). All changes are tests only; no runtime exports or public APIs were modified.

Changes

Cohort / File(s) Summary
Widget Editor Tests
app/src/components/widget-editor/__tests__/chart-type-selector.test.tsx, app/src/components/widget-editor/__tests__/form-fields-editor.test.tsx, app/src/components/widget-editor/__tests__/parameter-config-section-ui.test.tsx, app/src/components/widget-editor/__tests__/parameter-config-section.test.tsx
Adds four new test suites. Mocks UI primitives, icons, DnD and store hooks to assert: chart type metadata/icons and connection-dependent rendering; form-fields add/delete, required flags, parameter hints, and store updates; parameter-config UI interactions, conditional controls, seed-query execution states; and param-type mapping helper roundtrips.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

testing, pkg:app, area:widgets

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding unit tests for widget-editor sub-components. It is concise, specific, and clearly indicates the PR's primary purpose.
Linked Issues check ✅ Passed The PR adds 55 tests across 4 widget-editor sub-components, directly contributing to the coverage gap closure objective in #578, though it addresses only a subset of the broader requirements.
Out of Scope Changes check ✅ Passed All changes are test-only additions targeting widget-editor sub-components. No production code modifications or unrelated changes are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/issue-578-widget-editor-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/src/components/widget-editor/__tests__/parameter-config-section.test.tsx (1)

1-129: Rename this suite to .test.ts.

This file only exercises pure helpers, so .test.tsx is misleading and violates the app test convention for non-UI utils. Please move it to .test.ts unless you plan to add JSX/rendering here. As per coding guidelines, unit tests for pure functions and utils in app/ use Vitest (no DOM) with .test.ts file extension.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/components/widget-editor/__tests__/parameter-config-section.test.tsx`
around lines 1 - 129, The test file is named .test.tsx but only exercises pure
helpers (resolveInternalParamType, reverseParamTypeMapping) and should be a
non-DOM Vitest test; rename the file from parameter-config-section.test.tsx to
parameter-config-section.test.ts (or create a new .test.ts and move the
contents) so it follows the app convention for pure-function tests, and ensure
imports/vi.mock usage remain valid after the rename.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@app/src/components/widget-editor/__tests__/parameter-config-section.test.tsx`:
- Around line 1-129: The test file is named .test.tsx but only exercises pure
helpers (resolveInternalParamType, reverseParamTypeMapping) and should be a
non-DOM Vitest test; rename the file from parameter-config-section.test.tsx to
parameter-config-section.test.ts (or create a new .test.ts and move the
contents) so it follows the app convention for pure-function tests, and ensure
imports/vi.mock usage remain valid after the rename.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: faa18cf2-ccda-4424-8bc1-e3b809c798b9

📥 Commits

Reviewing files that changed from the base of the PR and between 2b5ca1f and 55823b5.

📒 Files selected for processing (4)
  • app/src/components/widget-editor/__tests__/chart-type-selector.test.tsx
  • app/src/components/widget-editor/__tests__/form-fields-editor.test.tsx
  • app/src/components/widget-editor/__tests__/parameter-config-section-ui.test.tsx
  • app/src/components/widget-editor/__tests__/parameter-config-section.test.tsx

alfredorubin96 and others added 2 commits May 1, 2026 17:17
Add 55 unit tests across 4 test files covering:
- resolveInternalParamType / reverseParamTypeMapping pure functions (16 tests)
- ChartTypeSelector component rendering and callbacks (10 tests)
- ParameterConfigSection UI: all param types, seed query, collisions (18 tests)
- FormFieldsEditor: empty state, add/remove fields, DnD mocks (11 tests)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alfredo1996
alfredo1996 force-pushed the test/issue-578-widget-editor-coverage branch from 30d4c69 to 60e6a39 Compare May 1, 2026 15:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/src/components/widget-editor/__tests__/chart-type-selector.test.tsx (1)

44-52: ⚡ Quick win

Strengthen icon assertions by testing concrete fallback identity

At Line 44, every lucide-react export is mocked to the same component, so the assertions at Lines 65 and 70 only prove “defined,” not that known vs fallback icon resolution is correct. This can miss regressions in chartTypeIcons[type] ?? Braces.

Suggested test tightening
 import React from "react";
 import { describe, it, expect, vi } from "vitest";
 import { render, screen, fireEvent } from "@testing-library/react";
+import { Braces } from "lucide-react";
@@
-vi.mock("lucide-react", async (importOriginal) => {
-  const Icon = () => <span />;
-  const actual = await importOriginal<Record<string, unknown>>();
-  const mocked: Record<string, unknown> = {};
-  for (const key of Object.keys(actual)) {
-    mocked[key] = Icon;
-  }
-  return mocked;
-});
@@
 describe("getChartTypeMeta", () => {
   it("returns label from chart config and icon from map", () => {
     const meta = getChartTypeMeta("bar");
     expect(meta.label).toBe("Bar");
-    expect(meta.Icon).toBeDefined();
+    expect(meta.Icon).toBe(chartTypeIcons.bar);
   });

   it("returns fallback icon for unknown type", () => {
     const meta = getChartTypeMeta("unknown-type" as ChartType);
-    expect(meta.Icon).toBeDefined();
+    expect(meta.Icon).toBe(Braces);
   });
 });

Also applies to: 62-71

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/components/widget-editor/__tests__/chart-type-selector.test.tsx`
around lines 44 - 52, The test currently mocks every lucide-react export to the
same component which prevents asserting that chartTypeIcons[type] resolves to a
specific known icon vs the fallback Braces; update the vi.mock in
chart-type-selector.test.tsx so that known icon exports (the specific names used
in chartTypeIcons) return distinct, identifiable mock components and all other
icons return a generic fallback mock (e.g., createNamedMock('KnownIcon') vs
createNamedMock('Fallback')), then change the assertions that currently check
for defined to assert identity (strict equality or matching displayName) between
the rendered icon and the expected symbol (chartTypeIcons[type] or Braces) to
ensure correct resolution.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@app/src/components/widget-editor/__tests__/chart-type-selector.test.tsx`:
- Around line 44-52: The test currently mocks every lucide-react export to the
same component which prevents asserting that chartTypeIcons[type] resolves to a
specific known icon vs the fallback Braces; update the vi.mock in
chart-type-selector.test.tsx so that known icon exports (the specific names used
in chartTypeIcons) return distinct, identifiable mock components and all other
icons return a generic fallback mock (e.g., createNamedMock('KnownIcon') vs
createNamedMock('Fallback')), then change the assertions that currently check
for defined to assert identity (strict equality or matching displayName) between
the rendered icon and the expected symbol (chartTypeIcons[type] or Braces) to
ensure correct resolution.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e9e43746-9176-4bd8-b5bf-d197f2e5c9e3

📥 Commits

Reviewing files that changed from the base of the PR and between 55823b5 and 60e6a39.

📒 Files selected for processing (4)
  • app/src/components/widget-editor/__tests__/chart-type-selector.test.tsx
  • app/src/components/widget-editor/__tests__/form-fields-editor.test.tsx
  • app/src/components/widget-editor/__tests__/parameter-config-section-ui.test.tsx
  • app/src/components/widget-editor/__tests__/parameter-config-section.test.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/src/components/widget-editor/tests/parameter-config-section.test.tsx
  • app/src/components/widget-editor/tests/parameter-config-section-ui.test.tsx
  • app/src/components/widget-editor/tests/form-fields-editor.test.tsx

@alfredo1996
alfredo1996 merged commit b7c83a9 into release/2.0 May 1, 2026
8 of 10 checks passed
@sonarqubecloud

sonarqubecloud Bot commented May 1, 2026

Copy link
Copy Markdown

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.

2 participants