Skip to content

test: route charts/vega into the ui vitest project and cover the untested viz packages and hooks (#4295) - #4377

Merged
cixzhang merged 5 commits into
meta:mainfrom
AKnassa:rocky/issue-4295-func-coverage
Sep 3, 2026
Merged

cixzhang merged 5 commits into
meta:mainfrom
AKnassa:rocky/issue-4295-func-coverage

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

The bug underneath the coverage gap

packages/vega has no route into the vitest ui project, so its component tests fall through to the node project: no jsdom, no StyleX transform, no jest-dom. Main has since fixed the same problem for charts (routing plus a bare @astryxdesign/core alias); this PR adds the still-missing vega include and exclude (3 lines in vitest.config.ts) and vega's test scripts.

What this adds

Following #4295, in its order:

  1. Core hooks: renderHook tests for the three useCalendar* hooks, useCollapsible, useTableFilterState, useScrollLock, useLightbox, useChatPasteAsToken, useImperativeAlertDialog, useTranslator, useTooltip.
  2. Viz render smoke: charts (every primitive, the marks, the tooltip's pointer seam), vega (VegaChart's full lifecycle against a mocked vega/vega-lite boundary), and lab's Chart*, Radial*, ThreeD*, Sankey* and SVGIcon families.
  3. Zero-test components: CommandPaletteEmpty, InputClearButton, TypeaheadItem, ChatSendButton, PowerSearchToken, PowerSearchFilterEditor, TableHeaderCell.

66 test files, 509 tests. No source file is changed. The only non-test edits are the vega route, vega's test scripts, and a shared StyleX read-back helper (packages/core/src/__tests__/stylexDeclarations.ts).

Eight of these files were also added on main while this branch was open (charts/Chart, InputClearButton, TypeaheadItem, useScrollLock, lab/Chart, RadialChart, SVGIcon, ThreeDChart). Those keep main's version; ea311aae4 ports back only the assertions main does not cover and drops the duplicates. One of main's assertions is tightened along the way: InputClearButton's onClick event check (toBeInstanceOf(Object) passes for any object) now pins type: 'click'.

One correction to the issue: ChatComposerDrawer (#3996) and MobileNavToggle (#3721) already had tests.

How it was checked

  • The 66 files: 509 passing. The wider set of every test file the merge touched: 288 files / 7955 passing.
  • ESLint and Prettier clean on every edited file; typecheck clean for core, lab, charts and vega (test files included).
  • Sampled mutation testing from the first round still holds: inverting the send-button variant ternary, dropping CommandPaletteEmpty's xstyle merge, and deleting useTooltip's touch guard each fail exactly one test.
  • No changeset: nothing shipped changes.

Deliberately left uncovered

  • useTooltip's focus paths. jsdom resolves :focus-visible as plain :focus, so a test of that gate would pass identically with the gate deleted.
  • The ignored onOpenChange(true) guards in useLightbox and useImperativeAlertDialog. Nothing emits true through the public surface, and forcing it via element props trips no-react-introspection.

Source observations, not fixed here

  • lab/SVGIcon.tsx:131-153 spreads {...attrs, key} into each shape, so React 19 logs a key-in-spread warning per shape (pre-existing on main).
  • lab/Chart.tsx:333 emits a hard-coded clipPath id="astryx-chart-plot" that nothing references; charts/Chart.tsx already uses useId for the same thing.
  • TypeaheadItem.tsx:142-144 drops ref, className, xstyle, style and the pass-through props when item.element is set, and the group prop is documented but unused.

Refs #4295

AKnassa added 2 commits July 25, 2026 13:23
packages/charts and packages/vega had no functional tests at all, and
packages/lab's chart primitives (Chart*, Radial*, ThreeD*, Sankey*,
SVGIcon) rendered nothing under test. Add colocated tests for each, plus
renderHook tests for the three useCalendar* hooks, useCollapsible and
useTableFilterState.

Harness: charts and vega were falling through to the `node` vitest
project, which has no jsdom, no StyleX transform and no jest-dom, so
their tests could never have run there. Move both into the `ui` project
and give vega the test scripts the other packages already have.

53 test files, 307 tests. Verified: full suite 7943 pass / 430 files,
still green with packages/core/dist absent (the cold-CI path, which
charts needs because it imports core by bare name for values); 8 sampled
mutations across all four packages, each killed by exactly the new test.

Refs meta#4295
Finishes the functional-coverage sweep started in 64d9ea3. Adds
renderHook tests for useScrollLock, useLightbox, useChatPasteAsToken,
useImperativeAlertDialog, useTranslator and useTooltip, plus colocated
tests for the components that had none: CommandPaletteEmpty,
InputClearButton, TypeaheadItem, ChatSendButton, PowerSearchToken,
PowerSearchFilterEditor and TableHeaderCell.

Two of the issue's nine "zero-test" components already had tests
(ChatComposerDrawer, MobileNavToggle, from meta#3996 and meta#3721), so the
inventory is smaller than the issue states.

Extracts the StyleX declaration read-back helper that three of these
files each needed into __tests__/stylexDeclarations.ts rather than
landing a third copy.

Two branches are deliberately left uncovered, with the reason recorded
next to them: the ignored-onOpenChange(true) guards in useLightbox and
useImperativeAlertDialog are unreachable through the public surface,
and reaching into element props to force them both breaks the repo's
no-react-introspection lint rule and asserts a value that is already
settled. useTooltip's focus paths are also omitted -- jsdom resolves
:focus-visible as :focus, so those tests would pass with the gate
deleted.

Verified: 8101 tests / 443 files green, eslint and prettier clean,
core typecheck clean; three sampled mutations (the send-button variant
ternary, CommandPaletteEmpty's xstyle merge, useTooltip's touch
suppression) each killed by exactly one new test.

Refs meta#4295
@vercel

vercel Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 29, 2026 3:10am

Request Review

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 26, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 26, 2026
@AKnassa
AKnassa marked this pull request as ready for review July 26, 2026 05:03
@github-actions

github-actions Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

AlertDialog (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 182 -
Complexity N/A Medium (12) -
Calendar (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1476 -
Complexity N/A Very High (138) -
Chat (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 5421 -
Complexity N/A Very High (439) -
Collapsible (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 422 -
Complexity N/A Very High (39) -
CommandPalette (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1010 -
Complexity N/A Very High (114) -
Field (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 778 -
Complexity N/A Very High (48) -
Lightbox (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 658 -
Complexity N/A Very High (84) -
PowerSearch (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 3847 -
Complexity N/A Very High (342) -
Table (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1950 -
Complexity N/A Very High (112) -
Tooltip (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 523 -
Complexity N/A Very High (56) -
Typeahead (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1222 -
Complexity N/A Very High (174) -
Chart (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 3471 -
Complexity N/A Very High (374) -
Radial (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 782 -
Complexity N/A Very High (114) -
SVGIcon (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1337 -
Complexity N/A Very High (38) -
Sankey (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 866 -
Complexity N/A Very High (73) -
ThreeD (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 947 -
Complexity N/A Very High (84) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB
@astryxdesign/lab N/A 3.5KB 1.5KB
@astryxdesign/charts N/A 922B 436B

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

PowerSearch - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/26 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Visual Regression

Status: Skipped — Broad stable scope is deferred to the daily release gate. It covers 1964 trusted baseline shots instead of recapturing them for this PR. View the report


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang

Copy link
Copy Markdown
Contributor

Thanks for this — the Vega coverage is still wanted, but I can't refresh this branch mechanically now. Main has independently added eight of these test files and the charts test routing, so resolving the add/add conflicts requires choosing which assertions to keep rather than just taking both sides.

Could you update onto current main and narrow the config change to the still-missing Vega route? Once that is current, we can review the remaining tests against today's behavior.

[Reviewed by Robohands]

Add/add conflicts on eight test files that main added independently
(charts Chart, core InputClearButton/TypeaheadItem/useScrollLock, lab
Chart/RadialChart/SVGIcon/ThreeDChart) resolve to main's version; the
non-overlapping assertions from this branch are ported in a follow-up.

vitest.config.ts narrows to the still-missing vega route: main already
routes charts (and richtext) into the ui project.
The eight add/add conflicts resolved to main's files in the merge; this
ports back only the assertions main does not cover and that still hold
today (render gates and sizing, layer groups and masks, style restore,
registry glyph, xstyle forwarding, context guards). Duplicates of main's
coverage are dropped rather than kept twice.

Four files went stale over the 815-commit gap and follow today's
behavior: the hidden data-table fallback (meta#4382) means chart label and
tooltip queries scope to the svg; useTooltip's touch guard is per
pointer type (meta#5248) and a controlled tooltip reports Escape through
onHide (meta#4881); TableHeaderCell dividers are logical inline-end
properties (meta#4434).
@AKnassa

AKnassa commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Updated onto current main (c6041cfd5). The config change is now only the vega route (3 lines in vitest.config.ts); the charts routing and the bare @astryxdesign/core alias come from main.

The eight add/add files keep main's version, and ea311aae4 ports back only the assertions main does not cover (render gates and sizing, layer groups and masks, scroll-lock style restore, registry glyph, xstyle forwarding, context guards). Duplicates of main's coverage are dropped rather than kept twice.

Four files had gone stale and now follow today's behavior: chart label and tooltip queries scope to the svg because of the hidden data-table fallback (#4382), useTooltip's touch guard is per pointer type (#5248) and a controlled tooltip reports Escape through onHide (#4881), and TableHeaderCell dividers are logical inline-end properties (#4434).

Locally: 66 files / 509 tests green, eslint and prettier clean, typecheck clean for core, lab, charts and vega.

github-actions Bot added a commit that referenced this pull request Aug 28, 2026
CI's lint job fails on the one raw Intl call left in these tests:
main's no-raw-intl-locale rule keeps its test-oracle allowlist inside
the rule, and this file is not on it. The oracle was also the wrong
side: with no InternationalizationProvider mounted, useLocale() resolves
to 'en', so the hook's labels never followed the machine locale that
Intl.DateTimeFormat(undefined) reads. Literal 'April 2026' style
assertions match Calendar.test.tsx and drop the Intl dependency.

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 No review blockers found — Vega’s 30 tests route exclusively through the UI project, and the focused chart/Vega suites pass at this head.

[Reviewed by Robohands]

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Sep 3, 2026
@cixzhang
cixzhang merged commit 1581b09 into meta:main Sep 3, 2026
27 checks passed
@github-actions
github-actions Bot deleted the rocky/issue-4295-func-coverage branch September 3, 2026 10:40
AKnassa added a commit to AKnassa/astryx that referenced this pull request Sep 26, 2026
Resolved conflicts:
- packages/vega/src/VegaChart.tsx: kept upstream's value-compared View
  latch (meta#6051) and fed the PR's themed compile options into it as
  `compileOptions`, replacing the PR's effect dependency list.
- packages/vega/README.md: merged the file manifest (upstream's
  viewInputs.ts row plus the PR's tsconfig.build.json and
  vegaLiteConfig.ts rows).
- packages/vega/src/vegaLiteConfig.test.ts (add/add): kept upstream's
  suite and added the PR's shared-palette and withAstryxConfig tests.
- vitest.global-setup.node.mjs: took upstream's version. Vega tests now
  run in the `ui` project (meta#4377), so the node global setup no longer
  needs to build charts.

Merge fallout:
- packages/cli/clients/cli/commands/ensure-core-built.mjs: took
  upstream's version, dropping the PR's ensureBuilt/ensureChartsBuilt
  generalization, which nothing uses any more.
- vitest.config.ts: resolve the bare @astryxdesign/charts specifier to
  source, as core already is, so the `ui` project does not need a built
  charts dist.
- packages/vega/src/VegaChart.test.tsx: the vega mock now keeps the real
  module (vegaLiteConfig needs mergeConfig), and the compileOptions test
  expects the caller's config merged over the default theme config.
- packages/vega/src/VegaChart.doc.mjs: compileOptions notes that its
  config is merged over the Astryx theme config.

This branch was successfully deployed

1 active deployment
Preview — 10e2a46e Deployed Aug 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants