test(sqllab): Convert tests to RTL for SqlEditor (#22093)

This commit is contained in:
Corbin Robb 2022-11-17 11:10:13 -07:00 committed by GitHub
parent 394fb2f2d0
commit 83d990db4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,13 +33,11 @@ import AceEditorWrapper from 'src/SqlLab/components/AceEditorWrapper';
import ConnectedSouthPane from 'src/SqlLab/components/SouthPane/state'; import ConnectedSouthPane from 'src/SqlLab/components/SouthPane/state';
import SqlEditor from 'src/SqlLab/components/SqlEditor'; import SqlEditor from 'src/SqlLab/components/SqlEditor';
import QueryProvider from 'src/views/QueryProvider'; import QueryProvider from 'src/views/QueryProvider';
import { AntdDropdown } from 'src/components';
import { import {
queryEditorSetFunctionNames, queryEditorSetFunctionNames,
queryEditorSetSelectedText, queryEditorSetSelectedText,
queryEditorSetSchemaOptions, queryEditorSetSchemaOptions,
} from 'src/SqlLab/actions/sqlLab'; } from 'src/SqlLab/actions/sqlLab';
import { EmptyStateBig } from 'src/components/EmptyState';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint'; import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import { import {
initialState, initialState,
@ -130,11 +128,12 @@ describe('SqlEditor', () => {
}, },
); );
it('does not render SqlEditor if no db selected', () => { it('does not render SqlEditor if no db selected', async () => {
const queryEditor = initialState.sqlLab.queryEditors[1]; const queryEditor = initialState.sqlLab.queryEditors[1];
const updatedProps = { ...mockedProps, queryEditor }; const { findByText } = setup({ ...mockedProps, queryEditor }, store);
const wrapper = buildWrapper(updatedProps); expect(
expect(wrapper.find(EmptyStateBig)).toExist(); await findByText('Select a database to write a query'),
).toBeInTheDocument();
}); });
it('render a SqlEditorLeftBar', async () => { it('render a SqlEditorLeftBar', async () => {
@ -145,14 +144,13 @@ describe('SqlEditor', () => {
}); });
it('render an AceEditorWrapper', async () => { it('render an AceEditorWrapper', async () => {
const wrapper = buildWrapper(); const { findByTestId } = setup(mockedProps, store);
await waitForComponentToPaint(wrapper); expect(await findByTestId('react-ace')).toBeInTheDocument();
expect(wrapper.find(AceEditorWrapper)).toExist();
}); });
it('renders sql from unsaved change', () => { it('renders sql from unsaved change', async () => {
const expectedSql = 'SELECT updated_column\nFROM updated_table\nWHERE'; const expectedSql = 'SELECT updated_column\nFROM updated_table\nWHERE';
const { getByTestId } = setup( const { findByTestId } = setup(
mockedProps, mockedProps,
mockStore({ mockStore({
...initialState, ...initialState,
@ -181,15 +179,16 @@ describe('SqlEditor', () => {
}), }),
); );
expect(getByTestId('react-ace')).toHaveTextContent( expect(await findByTestId('react-ace')).toHaveTextContent(
JSON.stringify({ value: expectedSql }).slice(1, -1), JSON.stringify({ value: expectedSql }).slice(1, -1),
); );
}); });
it('render a SouthPane', async () => { it('render a SouthPane', async () => {
const wrapper = buildWrapper(); const { findByText } = setup(mockedProps, store);
await waitForComponentToPaint(wrapper); expect(
expect(wrapper.find(ConnectedSouthPane)).toExist(); await findByText(/run a query to display results/i),
).toBeInTheDocument();
}); });
it('runs query action with ctas false', async () => { it('runs query action with ctas false', async () => {
@ -263,8 +262,8 @@ describe('SqlEditor', () => {
it('render a Limit Dropdown', async () => { it('render a Limit Dropdown', async () => {
const defaultQueryLimit = 101; const defaultQueryLimit = 101;
const updatedProps = { ...mockedProps, defaultQueryLimit }; const updatedProps = { ...mockedProps, defaultQueryLimit };
const wrapper = buildWrapper(updatedProps); const { findByText } = setup(updatedProps, store);
await waitForComponentToPaint(wrapper); fireEvent.click(await findByText('LIMIT:'));
expect(wrapper.find(AntdDropdown)).toExist(); expect(await findByText('10 000')).toBeInTheDocument();
}); });
}); });