This is an automated email from the ASF dual-hosted git repository. michaelsmolina pushed a commit to branch 5.0 in repository https://gitbox.apache.org/repos/asf/superset.git
commit 8b1de4c12ceb2a6a02f45102be33ef2efc6237a5 Author: JUST.in DO IT <[email protected]> AuthorDate: Tue Feb 11 13:13:47 2025 -0800 fix(sqllab): close the table tab (#32224) (cherry picked from commit 937d40cdde45da05a3cda1c50c864910570efd03) --- .../SqlLab/components/SouthPane/SouthPane.test.tsx | 24 +++++++++++++++++++++- .../src/SqlLab/components/SouthPane/index.tsx | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/SouthPane/SouthPane.test.tsx b/superset-frontend/src/SqlLab/components/SouthPane/SouthPane.test.tsx index 0d30c46f1e..dbfa9192ec 100644 --- a/superset-frontend/src/SqlLab/components/SouthPane/SouthPane.test.tsx +++ b/superset-frontend/src/SqlLab/components/SouthPane/SouthPane.test.tsx @@ -16,12 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -import { render } from 'spec/helpers/testing-library'; +import { render, waitFor, within } from 'spec/helpers/testing-library'; import SouthPane from 'src/SqlLab/components/SouthPane'; import '@testing-library/jest-dom'; import { STATUS_OPTIONS } from 'src/SqlLab/constants'; import { initialState, table, defaultQueryEditor } from 'src/SqlLab/fixtures'; import { denormalizeTimestamp } from '@superset-ui/core'; +import userEvent from '@testing-library/user-event'; const mockedProps = { queryEditorId: defaultQueryEditor.id, @@ -49,12 +50,14 @@ const mockState = { tables: [ { ...table, + id: 't3', name: 'table3', dataPreviewQueryId: '2g2_iRFMl', queryEditorId: defaultQueryEditor.id, }, { ...table, + id: 't4', name: 'table4', dataPreviewQueryId: 'erWdqEWPm', queryEditorId: defaultQueryEditor.id, @@ -149,3 +152,22 @@ test('should render tabs for table metadata view', () => { expect(tabs[index + 2]).toHaveTextContent(`${schema}.${name}`); }); }); + +test('should remove tab', async () => { + const { getAllByRole } = await render(<SouthPane {...mockedProps} />, { + useRedux: true, + initialState: mockState, + }); + + const tabs = getAllByRole('tab'); + const totalTabs = mockState.sqlLab.tables.length + 2; + expect(tabs).toHaveLength(totalTabs); + const removeButton = within(tabs[2].parentElement as HTMLElement).getByRole( + 'button', + { + name: /remove/, + }, + ); + userEvent.click(removeButton); + await waitFor(() => expect(getAllByRole('tab')).toHaveLength(totalTabs - 1)); +}); diff --git a/superset-frontend/src/SqlLab/components/SouthPane/index.tsx b/superset-frontend/src/SqlLab/components/SouthPane/index.tsx index dbde83ae9d..fe929cb080 100644 --- a/superset-frontend/src/SqlLab/components/SouthPane/index.tsx +++ b/superset-frontend/src/SqlLab/components/SouthPane/index.tsx @@ -136,7 +136,7 @@ const SouthPane = ({ dispatch(removeTables([table])); } }, - [dispatch, queryEditorId], + [dispatch, pinnedTables], ); return offline ? (
