Skip to content

Commit

Permalink
Fix 'renders sql from unsaved change' test
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneTorap committed Sep 27, 2022
1 parent 93ce681 commit dc69bbe
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,6 @@ describe('AceEditorWrapper', () => {
);
});

it('renders sql from unsaved change', () => {
// TODO: need to rewrite the test because we retrieve 'currentQueryEditor' in SqlEditor
return;

const expectedSql = 'SELECT updated_column\nFROM updated_table\nWHERE';
const { getByTestId } = setup(
defaultQueryEditor,
mockStore({
...initialState,
sqlLab: {
...initialState.sqlLab,
unsavedQueryEditor: {
id: defaultQueryEditor.id,
sql: expectedSql,
},
},
}),
);

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

it('renders current sql for unrelated unsaved changes', () => {
const expectedSql = 'SELECT updated_column\nFROM updated_table\nWHERE';
const { getByTestId } = setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import React from 'react';
import { mount } from 'enzyme';
import { render } from 'spec/helpers/testing-library';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
Expand Down Expand Up @@ -48,6 +49,13 @@ import {
defaultQueryEditor,
} from 'src/SqlLab/fixtures';

jest.mock('src/components/AsyncAceEditor', () => ({
...jest.requireActual('src/components/AsyncAceEditor'),
FullSQLEditor: props => (
<div data-test="react-ace">{JSON.stringify(props)}</div>
),
}));

const MOCKED_SQL_EDITOR_HEIGHT = 500;

fetchMock.get('glob:*/api/v1/database/*', { result: [] });
Expand Down Expand Up @@ -79,6 +87,12 @@ const store = mockStore({
},
});

const setup = (props = {}, store) =>
render(<SqlEditor {...props} />, {
useRedux: true,
...(store && { store }),
});

describe('SqlEditor', () => {
const mockedProps = {
actions: {
Expand Down Expand Up @@ -118,21 +132,61 @@ describe('SqlEditor', () => {
const wrapper = buildWrapper(updatedProps);
expect(wrapper.find(EmptyStateBig)).toExist();
});

it('render a SqlEditorLeftBar', async () => {
const wrapper = buildWrapper();
await waitForComponentToPaint(wrapper);
expect(wrapper.find(SqlEditorLeftBar)).toExist();
});

it('render an AceEditorWrapper', async () => {
const wrapper = buildWrapper();
await waitForComponentToPaint(wrapper);
expect(wrapper.find(AceEditorWrapper)).toExist();
});

it('renders sql from unsaved change', () => {
const expectedSql = 'SELECT updated_column\nFROM updated_table\nWHERE';
const { getByTestId } = setup(
mockedProps,
mockStore({
...initialState,
sqlLab: {
...initialState.sqlLab,
databases: {
dbid1: {
allow_ctas: false,
allow_cvas: false,
allow_dml: false,
allow_file_upload: false,
allow_run_async: false,
backend: 'postgresql',
database_name: 'examples',
expose_in_sqllab: true,
force_ctas_schema: null,
id: 1,
},
},
unsavedQueryEditor: {
id: defaultQueryEditor.id,
dbId: 'dbid1',
sql: expectedSql,
},
},
}),
);

expect(getByTestId('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();
});

// TODO eschutho convert tests to RTL
// eslint-disable-next-line jest/no-disabled-tests
it.skip('does not overflow the editor window', async () => {
Expand All @@ -146,6 +200,7 @@ describe('SqlEditor', () => {
SQL_EDITOR_GUTTER_HEIGHT;
expect(totalSize).toEqual(MOCKED_SQL_EDITOR_HEIGHT);
});

// eslint-disable-next-line jest/no-disabled-tests
it.skip('does not overflow the editor window after resizing', async () => {
const wrapper = buildWrapper();
Expand All @@ -159,6 +214,7 @@ describe('SqlEditor', () => {
SQL_EDITOR_GUTTER_HEIGHT;
expect(totalSize).toEqual(450);
});

it('render a Limit Dropdown', async () => {
const defaultQueryLimit = 101;
const updatedProps = { ...mockedProps, defaultQueryLimit };
Expand Down

0 comments on commit dc69bbe

Please sign in to comment.