fix(sqllab): close the table tab (#32224)

This commit is contained in:
JUST.in DO IT 2025-02-11 13:13:47 -08:00 committed by GitHub
parent 319a860f23
commit 937d40cdde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View File

@ -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(<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));
});

View File

@ -136,7 +136,7 @@ const SouthPane = ({
dispatch(removeTables([table]));
}
},
[dispatch, queryEditorId],
[dispatch, pinnedTables],
);
return offline ? (