Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ import AceEditorWrapper from 'src/SqlLab/components/AceEditorWrapper';
import ConnectedSouthPane from 'src/SqlLab/components/SouthPane/state';
import SqlEditor from 'src/SqlLab/components/SqlEditor';
import QueryProvider from 'src/views/QueryProvider';
import { AntdDropdown } from 'src/components';
import {
queryEditorSetFunctionNames,
queryEditorSetSelectedText,
queryEditorSetSchemaOptions,
} from 'src/SqlLab/actions/sqlLab';
import { EmptyStateBig } from 'src/components/EmptyState';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import {
initialState,
Expand Down Expand Up @@ -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 updatedProps = { ...mockedProps, queryEditor };
const wrapper = buildWrapper(updatedProps);
expect(wrapper.find(EmptyStateBig)).toExist();
const { findByText } = setup({ ...mockedProps, queryEditor }, store);
expect(
await findByText('Select a database to write a query'),
).toBeInTheDocument();
});

it('render a SqlEditorLeftBar', async () => {
Expand All @@ -145,14 +144,13 @@ describe('SqlEditor', () => {
});

it('render an AceEditorWrapper', async () => {
const wrapper = buildWrapper();
await waitForComponentToPaint(wrapper);
expect(wrapper.find(AceEditorWrapper)).toExist();
const { findByTestId } = setup(mockedProps, store);
expect(await findByTestId('react-ace')).toBeInTheDocument();
});

it('renders sql from unsaved change', () => {
it('renders sql from unsaved change', async () => {
const expectedSql = 'SELECT updated_column\nFROM updated_table\nWHERE';
const { getByTestId } = setup(
const { findByTestId } = setup(
mockedProps,
mockStore({
...initialState,
Expand Down Expand Up @@ -181,15 +179,16 @@ describe('SqlEditor', () => {
}),
);

expect(getByTestId('react-ace')).toHaveTextContent(
expect(await findByTestId('react-ace')).toHaveTextContent(
JSON.stringify({ value: expectedSql }).slice(1, -1),
);
});

it('render a SouthPane', async () => {
const wrapper = buildWrapper();
await waitForComponentToPaint(wrapper);
expect(wrapper.find(ConnectedSouthPane)).toExist();
const { findByText } = setup(mockedProps, store);
expect(
await findByText(/run a query to display results/i),
).toBeInTheDocument();
});

it('runs query action with ctas false', async () => {
Expand Down Expand Up @@ -263,8 +262,8 @@ describe('SqlEditor', () => {
it('render a Limit Dropdown', async () => {
const defaultQueryLimit = 101;
const updatedProps = { ...mockedProps, defaultQueryLimit };
const wrapper = buildWrapper(updatedProps);
await waitForComponentToPaint(wrapper);
expect(wrapper.find(AntdDropdown)).toExist();
const { findByText } = setup(updatedProps, store);
fireEvent.click(await findByText('LIMIT:'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most projects have a few use cases for fireEvent, but the majority of the time you should probably use @testing-library/user-event.

Should we use user-event here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should! I will switch that over and push up the changes.

expect(await findByText('10 000')).toBeInTheDocument();
});
});