You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/08/05 20:02:01 UTC
(superset) branch feat/pivot-table-fraction-of updated: test(pivot-table): cover missing-denominator and customFormatters cases
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch feat/pivot-table-fraction-of
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/feat/pivot-table-fraction-of by this push:
new 1681dadf8d6 test(pivot-table): cover missing-denominator and customFormatters cases
1681dadf8d6 is described below
commit 1681dadf8d6d8ba4c6d8bef10f32cb6cb2b7f948
Author: rusackas <ev...@rusackas.com>
AuthorDate: Wed Aug 5 13:00:10 2026 -0700
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 <no...@anthropic.com>
---
.../test/react-pivottable/tableRenders.test.tsx | 64 ++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/tableRenders.test.tsx b/superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/tableRenders.test.tsx
index 16115b0cbfc..d8e9cdc19f1 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/tableRenders.test.tsx
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/tableRenders.test.tsx
@@ -936,3 +936,67 @@ test('TableRenderer shows actual values when showValuesAs is unset (default)', (
expect.arrayContaining(['1.00', '1.00', '1.00', '1.00']),
);
});
+
+/**
+ * Regression guard: `buildGroupbyCombinations` requests the denominator's
+ * rollup level whenever a percent `showValuesAs` is active, but if a cached
+ * response predates that (e.g. a stale query result), the level a percent
+ * mode needs can be absent from the data entirely. The denominator aggregator
+ * then never receives a push and its underlying value stays `null`, which
+ * would produce `Infinity` (JS coerces `null` to `0` under `/`) rather than
+ * throwing -- the shared number formatter must render that as blank instead
+ * of leaking `Infinity%`/`NaN%` into the cell.
+ */
+test('TableRenderer renders blank instead of NaN%/Infinity% when the denominator level is missing', () => {
+ // Leaf cells and the grand total are present, but the row-total level
+ // (`__rows: ['color'], __columns: []`) that `percent_row` needs is not --
+ // simulating a response fetched before the denominator level was requested.
+ const dataMissingRowTotals = TAGGED_COUNT_DATA.filter(
+ record => !(record.__rows.length === 1 && record.__columns.length === 0),
+ );
+ const props = buildDefaultProps({
+ data: dataMissingRowTotals,
+ vals: ['value'],
+ tableOptions: { rowTotals: false, colTotals: true },
+ showValuesAs: 'percent_row',
+ });
+ renderWithTheme(<TableRenderer {...props} />);
+
+ const cellTexts = getCellTexts('pvtVal');
+ expect(cellTexts.length).toBeGreaterThan(0);
+ cellTexts.forEach(text => {
+ expect(text).not.toMatch(/NaN|Infinity/);
+ });
+ expect(cellTexts).toEqual(expect.arrayContaining(['']));
+});
+
+/**
+ * Regression guard: a per-metric custom formatter (currency, decimal
+ * precision, etc.) doesn't apply to a ratio, so `PivotData` disables
+ * `formattedAggregators` entirely whenever a fraction `showValuesAs` is
+ * active (see the constructor in ../../src/react-pivottable/utilities.ts).
+ * A cell whose group would otherwise pick up a custom formatter must still
+ * render as a plain percentage.
+ */
+test('TableRenderer ignores customFormatters while showValuesAs is a percentage', () => {
+ const customFormatters = {
+ color: {
+ blue: () => 'CUSTOM',
+ },
+ };
+ const props = buildDefaultProps({
+ data: TAGGED_COUNT_DATA,
+ vals: ['value'],
+ tableOptions: { rowTotals: true, colTotals: true },
+ showValuesAs: 'percent_row',
+ customFormatters,
+ });
+ renderWithTheme(<TableRenderer {...props} />);
+
+ const cellTexts = getCellTexts('pvtVal');
+ expect(cellTexts).not.toEqual(expect.arrayContaining(['CUSTOM']));
+ // Each leaf cell (1) is still half of its row's total (2).
+ expect(cellTexts).toEqual(
+ expect.arrayContaining(['50.0%', '50.0%', '50.0%', '50.0%']),
+ );
+});