test(dashboard): add edge case tests for legacy chart customization migration#9
Conversation
…igration Co-Authored-By: andrei.cinca99 <andrei.cinca99@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
||
| const result = migrateChartCustomization(legacy); | ||
|
|
||
| expect(result.chartsInScope).toBeUndefined(); |
There was a problem hiding this comment.
🟡 Test codifies falsy-check bug: chartId 0 is silently dropped from chartsInScope
The test comment at line 928 explicitly says chartId as 0 (falsy but valid), acknowledging that 0 is a valid chart ID (the LegacyChartCustomizationItem type at superset-frontend/packages/superset-ui-core/src/query/types/Dashboard.ts:268 defines chartId?: number). However, the test assertion at line 943 expects chartsInScope to be undefined, codifying the falsy-check bug in the implementation at migrateChartCustomization.ts:134 (legacy.chartId ? [legacy.chartId] : undefined). When chartId is 0, the truthiness check treats it as falsy and drops it. The test should assert toEqual([0]) and the implementation should use legacy.chartId != null instead of a truthiness check.
Prompt for agents
The test 'migrateChartCustomization handles chartId as zero' at line 930 asserts that chartsInScope is undefined when chartId is 0, but this codifies a truthiness-check bug in the implementation.
Two changes are needed:
1. In superset-frontend/src/dashboard/util/migrateChartCustomization.ts at line 134, change:
chartsInScope: legacy.chartId ? [legacy.chartId] : undefined,
to:
chartsInScope: legacy.chartId != null ? [legacy.chartId] : undefined,
(This uses a null check instead of truthiness to handle chartId: 0 correctly.)
2. In the test file at line 943, change the assertion from:
expect(result.chartsInScope).toBeUndefined();
to:
expect(result.chartsInScope).toEqual([0]);
(This asserts the correct behavior: chartId 0 should be preserved in chartsInScope.)
Was this helpful? React with 👍 or 👎 to provide feedback.
SUMMARY
Adds 25 new edge case tests to
migrateChartCustomization.test.ts, increasing coverage of the legacy chart customization migration logic introduced in apache#37176. The existing 27 tests covered the happy paths; these new tests exercise boundary conditions across all exported functions.New test coverage areas:
isLegacyChartCustomizationFormat: hybrid objects (bothcustomizationandtypepresent), non-object primitives (number, array), objects withtypebut nocustomizationextractDatasetId(viamigrateChartCustomization): falsy numbers (0), negative numbers, empty strings, dataset objects with non-numeric string valuesextractColumnName: empty string column''when bothcustomization.nameandtitleare absentdefaultDataMaskgroupby enrichment: scalar (non-array)filterState.valuewrapping, merging into existingcustom_form_data, preserving pre-setfilterState.label, label generation from multiple values, skipping enrichment for falsy values (null,'', absent)controlValuesmerging:controlValuesoverriding base control properties, graceful handling whencontrolValuesis absentremovedflag: explicitfalsevsundefinedmigrateChartCustomizationArray: single-item arrays, order preservation with mixed legacy/new format itemschartId:chartId: 0treated as missing (see note below)The test
'migrateChartCustomization handles chartId as zero'documents thatchartId: 0results inchartsInScope: undefined. This is because the production code uses a truthiness check (legacy.chartId ? [legacy.chartId] : undefined), which treats0as falsy. If0is a valid chart ID in practice, this is a latent bug inmigrateChartCustomization.ts:134. This PR only adds the test to document the behavior — no production code is changed.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — test-only change.
TESTING INSTRUCTIONS
All 52 tests should pass (27 existing + 25 new).
ADDITIONAL INFORMATION
Link to Devin session: https://app.devin.ai/sessions/90d9e3cc63d645f1b37e4d43024eff9c
Requested by: @andreicinca