From 825b7edcc09cff7fe5a47b9913ab2479724461f9 Mon Sep 17 00:00:00 2001 From: Joe Li Date: Wed, 12 Nov 2025 11:31:19 -0800 Subject: [PATCH] fix(test): use getByRole for table headers to fix CI failures with antd 5.27.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ant Design Table v5.27.6 renders measurement cells containing duplicate header text, breaking tests using getByText(). Changed to getByRole('columnheader') for semantic, robust queries. Fixes: - DatasetList.permissions.test.tsx: 2 locations (lines 67, 137) - DatasetList.listview.test.tsx: 12 locations (lines 158-178, 276, 309, 335, 1115) All 50 tests now passing with antd@5.27.6. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../DatasetList/DatasetList.listview.test.tsx | 44 ++++++++++++++----- .../DatasetList.permissions.test.tsx | 8 +++- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/superset-frontend/src/pages/DatasetList/DatasetList.listview.test.tsx b/superset-frontend/src/pages/DatasetList/DatasetList.listview.test.tsx index 125876a0ecb..06045481c09 100644 --- a/superset-frontend/src/pages/DatasetList/DatasetList.listview.test.tsx +++ b/superset-frontend/src/pages/DatasetList/DatasetList.listview.test.tsx @@ -155,13 +155,27 @@ test('renders all required column headers', async () => { const table = screen.getByTestId('listview-table'); // Verify all column headers are present - expect(within(table).getByText(/Name/i)).toBeInTheDocument(); - expect(within(table).getByText(/Type/i)).toBeInTheDocument(); - expect(within(table).getByText(/Database/i)).toBeInTheDocument(); - expect(within(table).getByText(/Schema/i)).toBeInTheDocument(); - expect(within(table).getByText(/Owners/i)).toBeInTheDocument(); - expect(within(table).getByText(/Last modified/i)).toBeInTheDocument(); - expect(within(table).getByText(/Actions/i)).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Name/i }), + ).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Type/i }), + ).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Database/i }), + ).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Schema/i }), + ).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Owners/i }), + ).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Last modified/i }), + ).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Actions/i }), + ).toBeInTheDocument(); }); test('displays dataset name in Name column', async () => { @@ -259,7 +273,9 @@ test('sorting by Name column updates API call with sort parameter', async () => }); const table = screen.getByTestId('listview-table'); - const nameHeader = within(table).getByText(/Name/i); + const nameHeader = within(table).getByRole('columnheader', { + name: /Name/i, + }); // Record initial calls const initialCalls = fetchMock.calls(API_ENDPOINTS.DATASETS).length; @@ -290,7 +306,9 @@ test('sorting by Database column updates sort parameter', async () => { }); const table = screen.getByTestId('listview-table'); - const databaseHeader = within(table).getByText(/Database/i); + const databaseHeader = within(table).getByRole('columnheader', { + name: /Database/i, + }); const initialCalls = fetchMock.calls(API_ENDPOINTS.DATASETS).length; @@ -314,7 +332,9 @@ test('sorting by Last modified column updates sort parameter', async () => { }); const table = screen.getByTestId('listview-table'); - const modifiedHeader = within(table).getByText(/Last modified/i); + const modifiedHeader = within(table).getByRole('columnheader', { + name: /Last modified/i, + }); const initialCalls = fetchMock.calls(API_ENDPOINTS.DATASETS).length; @@ -1092,7 +1112,9 @@ test('sort order persists after deleting a dataset', async () => { }); const table = screen.getByTestId('listview-table'); - const nameHeader = within(table).getByText(/Name/i); + const nameHeader = within(table).getByRole('columnheader', { + name: /Name/i, + }); // Record initial API calls count const initialCalls = fetchMock.calls(API_ENDPOINTS.DATASETS).length; diff --git a/superset-frontend/src/pages/DatasetList/DatasetList.permissions.test.tsx b/superset-frontend/src/pages/DatasetList/DatasetList.permissions.test.tsx index 7b8971c5197..14a73e264a4 100644 --- a/superset-frontend/src/pages/DatasetList/DatasetList.permissions.test.tsx +++ b/superset-frontend/src/pages/DatasetList/DatasetList.permissions.test.tsx @@ -64,7 +64,9 @@ test('admin users see all UI elements', async () => { // Admin should see actions column await waitFor(() => { const table = screen.getByTestId('listview-table'); - expect(within(table).getByText(/Actions/i)).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Actions/i }), + ).toBeInTheDocument(); }); }); @@ -134,7 +136,9 @@ test('write users see Actions column', async () => { await waitFor(() => { const table = screen.getByTestId('listview-table'); - expect(within(table).getByText(/Actions/i)).toBeInTheDocument(); + expect( + within(table).getByRole('columnheader', { name: /Actions/i }), + ).toBeInTheDocument(); }); });