abhinav-phi commented on PR #44815:
URL: https://github.com/apache/superset/pull/44815#issuecomment-5937638520

   Agreed, and it was a worse problem than it looked. `slice(0, -1)` was 
encoding "the grand total is the last record" as a positional assumption, so 
appending or reordering anything in the fixture would change what the test was 
actually exercising.
   
   Replaced with a filter on the rollup tags themselves — the grand-total 
record is the one with an empty row *and* column rollup:
   
   ```ts
   const withoutGrandTotalRecord = (records: TaggedRecord[]): TaggedRecord[] =>
     records.filter(
       record =>
         (record.__rows as string[]).length > 0 ||
         (record.__columns as string[]).length > 0,
     );
   ```
   
   While checking this I found the test would not actually have caught a wrong 
selection: the grand total would still be fed directly by the surviving record, 
so `expect(rendered(pivotData, [], [])).toBe('$300.00')` would have stayed 
green. Added an assertion that pins the premise the test depends on:
   
   ```ts
   const fixture = withoutGrandTotalRecord(SINGLE_METRIC_DATA);
   // The whole point of this test is that the grand total arrives via the 
mirror
   // and not from a record, so assert the fixture really is in that shape --
   // otherwise dropping the wrong record would leave the test silently green.
   expect(fixture.some(isGrandTotalRecord)).toBe(false);
   ```
   
   Verified both directions. A filter that keeps the grand-total record now 
fails on that assertion:
   
   ```
   × metric-collapse total uses the metric formatter
     Expected: false
     Received: true
     at utilities.test.ts:175
   ```
   
   and a filter that drops the wrong record instead fails on the value:
   
   ```
     Expected: "$300.00"
     Received: ""
   ```
   
   `npx jest plugins/plugin-chart-pivot-table` → 9 suites, 120 tests, all 
passing. `oxfmt` clean.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to