This is an automated email from the ASF dual-hosted git repository. sadpandajoe pushed a commit to branch fix-metric-popover-dropped-column in repository https://gitbox.apache.org/repos/asf/superset.git
commit ce9baf96bff742df7624b74b57e3fe100d33f230 Author: Joe Li <[email protected]> AuthorDate: Fri Nov 13 23:45:58 2026 +0000 test(explore): cover dropped column preselection in the add-metric popover Dropping a column on the Metrics control after the popover has already been opened once shows the previous (or no) metric in the popover instead of the dropped column. Add regression tests for both cases. --- .../DndMetricSelect.test.tsx | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.test.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.test.tsx index 0a61c6e4961..1d83563d166 100644 --- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.test.tsx +++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.test.tsx @@ -18,6 +18,7 @@ */ import { useState } from 'react'; import { + act, fireEvent, render, screen, @@ -27,6 +28,7 @@ import { within, } from 'spec/helpers/testing-library'; import { Metric } from '@superset-ui/core'; +import { ColumnMeta } from '@superset-ui/chart-controls'; import { GenericDataType } from '@apache-superset/core/common'; import { useDroppable } from '@dnd-kit/core'; import { useSortable } from '@dnd-kit/sortable'; @@ -652,6 +654,97 @@ test('saves a new simple adhoc metric with a custom title from an empty drop zon expect(await screen.findByText('Total revenue')).toBeInTheDocument(); }); +const droppableColumns: ColumnMeta[] = [ + { + column_name: 'revenue', + verbose_name: 'Revenue', + type_generic: GenericDataType.Numeric, + }, + { + column_name: 'country', + verbose_name: 'Country', + type_generic: GenericDataType.String, + }, +]; + +const getColumnField = async () => { + const columnSelect = await screen.findByRole('combobox', { + name: 'Select column', + }); + return columnSelect.closest('.ant-select') as HTMLElement; +}; + +test('preselects the dropped column in the add-metric popover after the popover was opened and cancelled once', async () => { + render( + <DndMetricSelect + {...defaultProps} + columns={droppableColumns} + value={[]} + multi + />, + { useDndKit: true, useRedux: true }, + ); + + await userEvent.click(screen.getByText('Drop columns/metrics here or click')); + await screen.findByRole('tab', { name: 'Simple' }); + await userEvent.keyboard('{Escape}'); + await waitFor(() => + expect( + screen.queryByRole('tab', { name: 'Simple' }), + ).not.toBeInTheDocument(), + ); + + act(() => { + simulateDrop(captured, { + type: DndItemType.Column, + value: droppableColumns[0], + }); + }); + + // A dropped column opens the popover on the Simple tab with that column + // selected, rather than on the Saved metrics tab with nothing selected. + expect(await screen.findByRole('tab', { name: 'Simple' })).toHaveAttribute( + 'aria-selected', + 'true', + ); + expect(await getColumnField()).toHaveTextContent('Revenue'); +}); + +test('shows the newly dropped column, not the previously dropped one, in the add-metric popover', async () => { + render( + <DndMetricSelect + {...defaultProps} + columns={droppableColumns} + value={[]} + multi + />, + { useDndKit: true, useRedux: true }, + ); + + act(() => { + simulateDrop(captured, { + type: DndItemType.Column, + value: droppableColumns[0], + }); + }); + expect(await getColumnField()).toHaveTextContent('Revenue'); + await userEvent.keyboard('{Escape}'); + await waitFor(() => + expect( + screen.queryByRole('combobox', { name: 'Select column' }), + ).not.toBeInTheDocument(), + ); + + act(() => { + simulateDrop(captured, { + type: DndItemType.Column, + value: droppableColumns[1], + }); + }); + + expect(await getColumnField()).toHaveTextContent('Country'); +}); + test('removes only the clicked metric when its remove control is used', async () => { const onChange = jest.fn(); render(
