refactor(sqllab): Remove tableOptions from redux state (#23488)

This commit is contained in:
JUST.in DO IT
2023-04-20 15:55:55 -07:00
committed by GitHub
parent a09162bb37
commit 5bec1a65ae
9 changed files with 12 additions and 92 deletions

View File

@@ -21,7 +21,6 @@ import React from 'react';
import { render, screen, waitFor, within } from 'spec/helpers/testing-library';
import { queryClient } from 'src/views/QueryProvider';
import fetchMock from 'fetch-mock';
import { act } from 'react-dom/test-utils';
import userEvent from '@testing-library/user-event';
import TableSelector, { TableSelectorMultiple } from '.';
@@ -36,11 +35,6 @@ const createProps = (props = {}) => ({
...props,
});
const getSchemaMockFunction = () =>
({
result: ['schema_a', 'schema_b'],
} as any);
const getTableMockFunction = () =>
({
count: 4,
@@ -124,47 +118,6 @@ test('renders disabled without schema', async () => {
});
});
test('table options are notified after schema selection', async () => {
fetchMock.get(schemaApiRoute, getSchemaMockFunction());
const callback = jest.fn();
const props = createProps({
onTablesLoad: callback,
schema: undefined,
});
render(<TableSelector {...props} />, { useRedux: true });
const schemaSelect = screen.getByRole('combobox', {
name: 'Select schema or type to search schemas',
});
expect(schemaSelect).toBeInTheDocument();
expect(callback).not.toHaveBeenCalled();
userEvent.click(schemaSelect);
expect(
await screen.findByRole('option', { name: 'schema_a' }),
).toBeInTheDocument();
expect(
await screen.findByRole('option', { name: 'schema_b' }),
).toBeInTheDocument();
fetchMock.get(tablesApiRoute, getTableMockFunction());
act(() => {
userEvent.click(screen.getAllByText('schema_a')[1]);
});
await waitFor(() => {
expect(callback).toHaveBeenCalledWith([
{ label: 'table_a', value: 'table_a' },
{ label: 'table_b', value: 'table_b' },
{ label: 'table_c', value: 'table_c' },
{ label: 'table_d', value: 'table_d' },
]);
});
});
test('table select retain value if not in SQL Lab mode', async () => {
fetchMock.get(schemaApiRoute, { result: ['test_schema'] });
fetchMock.get(tablesApiRoute, getTableMockFunction());