diff --git a/superset-frontend/src/SqlLab/components/SouthPane/SouthPane.test.tsx b/superset-frontend/src/SqlLab/components/SouthPane/SouthPane.test.tsx index e56022b8a..93d373279 100644 --- a/superset-frontend/src/SqlLab/components/SouthPane/SouthPane.test.tsx +++ b/superset-frontend/src/SqlLab/components/SouthPane/SouthPane.test.tsx @@ -16,11 +16,12 @@ * 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 { 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, @@ -48,12 +49,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, @@ -148,3 +151,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(, { + 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 dbde83ae9..fe929cb08 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 ? (