chore(insight-testing): unified normalized chart store#53407
chore(insight-testing): unified normalized chart store#53407sampennington wants to merge 1 commit intosam/hog-charts-trends-tooltip-bridgefrom
Conversation
|
Hey @sampennington! 👋\nThis pull request seems to contain no description. Please add useful context, rationale, and/or any other information that will help make sense of this change now and in the distant Mars-based future. |
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Size Change: 0 B Total Size: 127 MB ℹ️ View Unchanged
|
Prompt To Fix All With AIThis is a comment left during a code review.
Path: frontend/src/test/insight-testing/render-insight.tsx
Line: 28
Comment:
**Redundant `resetAllCapturedCharts()` call**
`resetCapturedCharts()` on the next line already calls `resetAllCapturedCharts()` internally (see `chartjs-mock.ts` lines 37-40), so this explicit call is superfluous and violates the "no superfluous parts" principle.
```suggestion
resetCapturedCharts()
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: frontend/src/test/insight-testing/chart-accessor.ts
Line: 177
Comment:
**Inconsistent error handling for renderer-specific method**
`hover()`, `pin()`, and `unpin()` (lines 174-176) all call `notSupported()` and throw a descriptive error when invoked on a non-hog-charts renderer. `tooltipHost()` silently returns `null` instead. When `waitForTooltip` is accidentally passed a Chart.js chart, the resulting test failure message will be the opaque `Expected: not null / Received: null` rather than the descriptive `"tooltipHost() is only supported on hog-charts entries (got renderer: chartjs)"` that the other methods produce.
Consider applying the same pattern:
```suggestion
tooltipHost: () =>
normalized.getTooltipHost ? normalized.getTooltipHost() : notSupported('tooltipHost()', normalized.renderer),
```
(Or if `null` is an intentional documented contract for Chart.js entries, a short inline comment here explaining why this one diverges from the others would help future readers.)
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "chore(insight-testing): unified normaliz..." | Re-trigger Greptile |
|
|
||
| /** Sets up Kea context, mounts common logics, and configures insight API mocks. */ | ||
| function setupTestEnvironment(mocks?: SetupMocksOptions, featureFlags?: Record<string, string | boolean>): void { | ||
| resetAllCapturedCharts() |
There was a problem hiding this comment.
Redundant
resetAllCapturedCharts() call
resetCapturedCharts() on the next line already calls resetAllCapturedCharts() internally (see chartjs-mock.ts lines 37-40), so this explicit call is superfluous and violates the "no superfluous parts" principle.
| resetAllCapturedCharts() | |
| resetCapturedCharts() |
Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/test/insight-testing/render-insight.tsx
Line: 28
Comment:
**Redundant `resetAllCapturedCharts()` call**
`resetCapturedCharts()` on the next line already calls `resetAllCapturedCharts()` internally (see `chartjs-mock.ts` lines 37-40), so this explicit call is superfluous and violates the "no superfluous parts" principle.
```suggestion
resetCapturedCharts()
```
How can I resolve this? If you propose a fix, please make it concise.| hover: (i) => (normalized.hover ? normalized.hover(i) : notSupported('hover()', normalized.renderer)), | ||
| pin: () => (normalized.pin ? normalized.pin() : notSupported('pin()', normalized.renderer)), | ||
| unpin: () => (normalized.unpin ? normalized.unpin() : notSupported('unpin()', normalized.renderer)), | ||
| tooltipHost: () => (normalized.getTooltipHost ? normalized.getTooltipHost() : null), |
There was a problem hiding this comment.
Inconsistent error handling for renderer-specific method
hover(), pin(), and unpin() (lines 174-176) all call notSupported() and throw a descriptive error when invoked on a non-hog-charts renderer. tooltipHost() silently returns null instead. When waitForTooltip is accidentally passed a Chart.js chart, the resulting test failure message will be the opaque Expected: not null / Received: null rather than the descriptive "tooltipHost() is only supported on hog-charts entries (got renderer: chartjs)" that the other methods produce.
Consider applying the same pattern:
| tooltipHost: () => (normalized.getTooltipHost ? normalized.getTooltipHost() : null), | |
| tooltipHost: () => | |
| normalized.getTooltipHost ? normalized.getTooltipHost() : notSupported('tooltipHost()', normalized.renderer), |
(Or if null is an intentional documented contract for Chart.js entries, a short inline comment here explaining why this one diverges from the others would help future readers.)
Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/test/insight-testing/chart-accessor.ts
Line: 177
Comment:
**Inconsistent error handling for renderer-specific method**
`hover()`, `pin()`, and `unpin()` (lines 174-176) all call `notSupported()` and throw a descriptive error when invoked on a non-hog-charts renderer. `tooltipHost()` silently returns `null` instead. When `waitForTooltip` is accidentally passed a Chart.js chart, the resulting test failure message will be the opaque `Expected: not null / Received: null` rather than the descriptive `"tooltipHost() is only supported on hog-charts entries (got renderer: chartjs)"` that the other methods produce.
Consider applying the same pattern:
```suggestion
tooltipHost: () =>
normalized.getTooltipHost ? normalized.getTooltipHost() : notSupported('tooltipHost()', normalized.renderer),
```
(Or if `null` is an intentional documented contract for Chart.js entries, a short inline comment here explaining why this one diverges from the others would help future readers.)
How can I resolve this? If you propose a fix, please make it concise.f407bb2 to
4a41d97
Compare
|
🎭 Playwright report · View test results →
These issues are not necessarily caused by your changes. |

Problem
The insight-testing harness is tightly coupled to Chart.js:
chartjs-mock.tsowns the capture store, andchart-accessor.tsreads Chart.js config shapes directly. Extending it to cover the hog-charts render path (TrendsLineChartD3+TrendsTooltipbridge) without touching these internals would force test authors to pick a renderer-specific waiter, and every assertion would have to branch by renderer.This is the first of three stacked PRs that add hog-charts test coverage. It's a behavior-preserving refactor — no new tests, no new capture sources.
Changes
captured-charts.tsdefinesNormalizedChart/NormalizedDataset/NormalizedAxisand owns a single in-memory capture store with arenderer: 'chartjs' | 'hog-charts'discriminator.chartjs-mock.tsnormalizes each captured Chart.js config on construction and pushes into the shared store.getCapturedChartConfigs()remains as a thin compat shim.chart-accessor.tsreads from the normalized store. The publicChartinterface is unchanged;.configis still exposed for Chart.js-specific callers (LineGraph.test.tsxuseschart.config.data.datasets[0].trendlineLinear).wait-for-chart.tsandquery-helpers.tsswitch togetAllCapturedCharts(). Future hog-charts entries will be picked up automatically.render-insight.tsxnow unconditionally mountsfeatureFlagLogicwith a seeded empty flag map. Without this, tests that render the full insight pipeline hit[KEA] Can not find path lib.logic.featureFlagLogic in the storeon the second test in a file (the reselect memoizer from the prior render holds a stale selector reference through the kea reset).How did you test this code?
Automated only — I'm an agent and haven't exercised this by hand. Ran the existing consumers of the harness:
frontend/src/scenes/insights/views/LineGraph/LineGraph.test.tsx— 5/5 greenfrontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx— 66/66 greenBoth suites hit every code path the refactor touches (labels, datasets, axis tick formatters, the
chart.configescape hatch). No new assertions, no snapshot changes.Publish to changelog?
no
🤖 LLM context
Authored by Claude Opus 4.6 via Claude Code. Part of a three-PR stack — the hog-charts mock and the
TrendsLineChartD3regression tests land in follow-up PRs that build on this store.