Skip to content

Commit 1681dad

Browse files
rusackasclaude
andcommitted
test(pivot-table): cover missing-denominator and customFormatters cases
Adds the two test-coverage gaps flagged in review: a percent showValuesAs cell whose denominator rollup level is absent from the data renders blank instead of NaN%/Infinity%, and a percent cell ignores an active customFormatters override rather than applying it to a ratio. Co-Authored-By: Claude Opus 4.8 <[email protected]>
1 parent 85760b8 commit 1681dad

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

‎superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/tableRenders.test.tsx‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,3 +936,67 @@ test('TableRenderer shows actual values when showValuesAs is unset (default)', (
936936
expect.arrayContaining(['1.00', '1.00', '1.00', '1.00']),
937937
);
938938
});
939+
940+
/**
941+
* Regression guard: `buildGroupbyCombinations` requests the denominator's
942+
* rollup level whenever a percent `showValuesAs` is active, but if a cached
943+
* response predates that (e.g. a stale query result), the level a percent
944+
* mode needs can be absent from the data entirely. The denominator aggregator
945+
* then never receives a push and its underlying value stays `null`, which
946+
* would produce `Infinity` (JS coerces `null` to `0` under `/`) rather than
947+
* throwing -- the shared number formatter must render that as blank instead
948+
* of leaking `Infinity%`/`NaN%` into the cell.
949+
*/
950+
test('TableRenderer renders blank instead of NaN%/Infinity% when the denominator level is missing', () => {
951+
// Leaf cells and the grand total are present, but the row-total level
952+
// (`__rows: ['color'], __columns: []`) that `percent_row` needs is not --
953+
// simulating a response fetched before the denominator level was requested.
954+
const dataMissingRowTotals = TAGGED_COUNT_DATA.filter(
955+
record => !(record.__rows.length === 1 && record.__columns.length === 0),
956+
);
957+
const props = buildDefaultProps({
958+
data: dataMissingRowTotals,
959+
vals: ['value'],
960+
tableOptions: { rowTotals: false, colTotals: true },
961+
showValuesAs: 'percent_row',
962+
});
963+
renderWithTheme(<TableRenderer {...props} />);
964+
965+
const cellTexts = getCellTexts('pvtVal');
966+
expect(cellTexts.length).toBeGreaterThan(0);
967+
cellTexts.forEach(text => {
968+
expect(text).not.toMatch(/NaN|Infinity/);
969+
});
970+
expect(cellTexts).toEqual(expect.arrayContaining(['']));
971+
});
972+
973+
/**
974+
* Regression guard: a per-metric custom formatter (currency, decimal
975+
* precision, etc.) doesn't apply to a ratio, so `PivotData` disables
976+
* `formattedAggregators` entirely whenever a fraction `showValuesAs` is
977+
* active (see the constructor in ../../src/react-pivottable/utilities.ts).
978+
* A cell whose group would otherwise pick up a custom formatter must still
979+
* render as a plain percentage.
980+
*/
981+
test('TableRenderer ignores customFormatters while showValuesAs is a percentage', () => {
982+
const customFormatters = {
983+
color: {
984+
blue: () => 'CUSTOM',
985+
},
986+
};
987+
const props = buildDefaultProps({
988+
data: TAGGED_COUNT_DATA,
989+
vals: ['value'],
990+
tableOptions: { rowTotals: true, colTotals: true },
991+
showValuesAs: 'percent_row',
992+
customFormatters,
993+
});
994+
renderWithTheme(<TableRenderer {...props} />);
995+
996+
const cellTexts = getCellTexts('pvtVal');
997+
expect(cellTexts).not.toEqual(expect.arrayContaining(['CUSTOM']));
998+
// Each leaf cell (1) is still half of its row's total (2).
999+
expect(cellTexts).toEqual(
1000+
expect.arrayContaining(['50.0%', '50.0%', '50.0%', '50.0%']),
1001+
);
1002+
});

0 commit comments

Comments
 (0)