sadpandajoe commented on code in PR #36081:
URL: https://github.com/apache/superset/pull/36081#discussion_r3477916139


##########
superset-frontend/plugins/plugin-chart-pivot-table/test/TableRenderer.test.tsx:
##########
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import '@testing-library/jest-dom';
+import { render } from '@testing-library/react';
+import PivotTableChart from '../src/PivotTableChart';
+import transformProps from '../src/plugin/transformProps';
+import testData from './testData';
+import { ProviderWrapper } from './testHelpers';
+
+test('applies pvtRowLabelLast class to last data row when colTotals is 
disabled', () => {
+  const transformedProps = {
+    ...transformProps(testData.withoutColTotals),
+    margin: 32,
+    legacy_order_by: null,
+    order_desc: false,
+  };
+  const { container } = render(
+    ProviderWrapper({
+      children: <PivotTableChart {...transformedProps} />,
+    }),
+  );
+
+  const tableBody = container.querySelector('tbody');
+  const dataRows = Array.from(tableBody?.querySelectorAll('tr') ?? []).filter(
+    row => !row.classList.contains('pvtRowTotals'),
+  );
+
+  // Get the last data row
+  const lastDataRow = dataRows[dataRows.length - 1];
+  expect(lastDataRow).toBeInTheDocument();
+
+  // Check if any cell in the last data row has pvtRowLabelLast class
+  const lastRowCells = lastDataRow.querySelectorAll('th.pvtRowLabel');
+  const hasLastClass = Array.from(lastRowCells).some(cell =>
+    cell.classList.contains('pvtRowLabelLast'),
+  );
+
+  expect(hasLastClass).toBe(true);
+});
+
+test('does not apply pvtRowLabelLast class to last data row when colTotals is 
enabled', () => {
+  const transformedProps = {
+    ...transformProps(testData.withColTotals),
+    margin: 32,
+    legacy_order_by: null,
+    order_desc: false,
+  };
+  const { container } = render(
+    ProviderWrapper({
+      children: <PivotTableChart {...transformedProps} />,
+    }),
+  );
+
+  const tableBody = container.querySelector('tbody');
+  const dataRows = Array.from(tableBody?.querySelectorAll('tr') ?? []).filter(
+    row => !row.classList.contains('pvtRowTotals'),
+  );
+
+  // Get the last data row (before totals row)
+  const lastDataRow = dataRows[dataRows.length - 1];
+  expect(lastDataRow).toBeInTheDocument();
+
+  // Check if any cell in the last data row has pvtRowLabelLast class
+  const lastRowCells = lastDataRow.querySelectorAll('th.pvtRowLabel');
+  const hasLastClass = Array.from(lastRowCells).some(cell =>
+    cell.classList.contains('pvtRowLabelLast'),
+  );
+
+  // Should NOT have the class because totals row will have the border
+  expect(hasLastClass).toBe(false);
+
+  // Verify totals row exists
+  const totalsRow = container.querySelector('tr.pvtRowTotals');
+  expect(totalsRow).toBeInTheDocument();
+});

Review Comment:
   Both of these assertions stay true even if the fix is reverted: with 
colTotals on, `pvtRowLabelLast` is absent from data rows by definition, and the 
totals row exists regardless of the border change. So the colTotals branch the 
fix actually touches isn't pinned by this test.
   
   Can you add an assertion that the totals row (or its label cell) carries the 
bottom border, e.g. checking `border-bottom` via `getComputedStyle`/snapshot, 
or asserting the `tr.pvtRowTotals` styling path the fix relies on in 
`Styles.ts`? Right now this passes whether or not the fix is present.



##########
superset-frontend/plugins/plugin-chart-pivot-table/test/testData.ts:
##########
@@ -0,0 +1,157 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  ChartDataResponseResult,
+  ChartProps,
+  DatasourceType,
+  VizType,
+  QueryFormData,
+} from '@superset-ui/core';
+import { supersetTheme } from '@apache-superset/core/theme';
+import { GenericDataType } from '@apache-superset/core/common';
+
+const basicFormData: QueryFormData = {
+  datasource: '1__table',
+  viz_type: VizType.PivotTable,
+  groupbyRows: ['country'],
+  groupbyColumns: ['city'],
+  metrics: ['SUM(sales)'],
+  metricsLayout: 'COLUMNS',
+  rowOrder: 'key_a_to_z',
+  colOrder: 'key_a_to_z',
+  aggregateFunction: 'Sum',
+  rowSubTotals: false,
+  colTotals: true,
+  colSubTotals: false,
+  rowTotals: true,
+  valueFormat: 'SMART_NUMBER',
+  dateFormat: 'smart_date',
+  transposePivot: false,
+  combineMetric: false,
+  rowSubtotalPosition: false,
+  colSubtotalPosition: false,
+};
+
+const basicChartProps = {
+  width: 800,
+  height: 600,
+  datasource: {
+    id: 1,
+    name: 'test_dataset',
+    type: DatasourceType.Table,
+    columns: [],
+    metrics: [],
+    columnFormats: {},
+    verboseMap: {},
+  },
+  hooks: {},
+  initialValues: {},
+  queriesData: [
+    {
+      data: {
+        columns: [],
+        records: [],
+      },
+    },
+  ],
+  formData: basicFormData,
+  theme: supersetTheme,
+};
+
+const basicQueryResult: ChartDataResponseResult = {
+  annotation_data: null,
+  cache_key: null,
+  cached_dttm: null,
+  cache_timeout: null,
+  data: [],
+  colnames: [],
+  coltypes: [],
+  error: null,
+  is_cached: false,
+  query: 'SELECT ...',
+  rowcount: 100,
+  sql_rowcount: 100,
+  stacktrace: null,
+  status: 'success',
+  from_dttm: null,
+  to_dttm: null,
+  queried_dttm: null,
+};
+
+// Shared test data
+const pivotData = [

Review Comment:
   This fixture is flat (one city per country), so every 
`rowAttrSpans[rowIdx][i]` is 1 and the `rowIdx + rowSpan === visibleRowCount` 
branch in `TableRenderers.tsx` only ever fires for the trivial single-span 
case. The bug this PR fixes (#36031) is the nested case: last group expanded, 
outer row spanning multiple sub-rows. As written, this regression test can't 
reproduce the original bug, so a revert of the fix wouldn't fail it.
   
   Can you add a `nestedPivotData` fixture (multiple cities per country, with 
the last country having 2+ cities) plus a test that asserts `pvtRowLabelLast` 
lands on the outer `th` whose `rowSpan > 1`?



-- 
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