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

Flakey unit tests fix #339

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions public/components/Main/__snapshots__/main.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,8 @@ exports[`<Main /> spec click run button, and response is not ok 1`] = `
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="SQL"
title="SQL"
>
<input
checked=""
Expand All @@ -995,6 +997,8 @@ exports[`<Main /> spec click run button, and response is not ok 1`] = `
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="PPL"
title="PPL"
>
<input
class="euiScreenReaderOnly"
Expand Down Expand Up @@ -1407,6 +1411,8 @@ exports[`<Main /> spec click run button, and response is ok 1`] = `
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="SQL"
title="SQL"
>
<input
checked=""
Expand All @@ -1431,6 +1437,8 @@ exports[`<Main /> spec click run button, and response is ok 1`] = `
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="PPL"
title="PPL"
>
<input
class="euiScreenReaderOnly"
Expand Down Expand Up @@ -1843,6 +1851,8 @@ exports[`<Main /> spec click run button, response fills null and missing values
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="SQL"
title="SQL"
>
<input
checked=""
Expand All @@ -1867,6 +1877,8 @@ exports[`<Main /> spec click run button, response fills null and missing values
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="PPL"
title="PPL"
>
<input
class="euiScreenReaderOnly"
Expand Down
35 changes: 19 additions & 16 deletions public/components/Main/main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
mockOpenSearchTreeQuery,
mockQueryResultJDBCResponse,
mockQueryTranslationResponse,
mockResultWithNull
mockResultWithNull,
} from '../../../test/mocks/mockData';
import { Main } from './main';

Expand Down Expand Up @@ -89,8 +89,7 @@ describe('<Main /> spec', () => {
});
expect(document.body.children[0]).toMatchSnapshot();
});



it('renders the component and checks if side tree is loaded', async () => {
const client = httpClientMock;
client.post = jest.fn().mockResolvedValue(mockHttpQuery);
Expand All @@ -115,13 +114,14 @@ describe('<Main /> spec', () => {
client.get = jest.fn().mockResolvedValue(mockDatasourcesQuery);
client.post = jest.fn().mockResolvedValue(mockQueryResultJDBCResponse);

const { getByText, getByTestId } = await render(
const { getByText } = await render(
<Main httpClient={client} setBreadcrumbs={setBreadcrumbsMock} />
);
const onRunButton = getByText('Run');
const pplbutton =getByTestId('PPL');
const sqlbutton = getByText('SQL');
waitFor(() => {
expect(pplbutton).toBeInTheDocument();
expect(sqlbutton).toBeInTheDocument();
fireEvent.click(sqlbutton);
});
const asyncTest = () => {
fireEvent.click(onRunButton);
Expand All @@ -135,12 +135,13 @@ describe('<Main /> spec', () => {
client.post = jest.fn().mockResolvedValue(mockResultWithNull);
client.get = jest.fn().mockResolvedValue(mockDatasourcesQuery);

const { getByText ,getByTestId } = await render(
const { getByText } = await render(
<Main httpClient={client} setBreadcrumbs={setBreadcrumbsMock} />
);
const pplbutton = getByTestId('PPL');
const sqlbutton = getByText('SQL');
waitFor(() => {
expect(pplbutton).toBeInTheDocument();
expect(sqlbutton).toBeInTheDocument();
fireEvent.click(sqlbutton);
});
const onRunButton = getByText('Run');
const asyncTest = () => {
Expand Down Expand Up @@ -179,12 +180,13 @@ describe('<Main /> spec', () => {
});
client.get = jest.fn().mockResolvedValue(mockDatasourcesQuery);

const { getByText, getByTestId } = await render(
const { getByText } = await render(
<Main httpClient={client} setBreadcrumbs={setBreadcrumbsMock} />
);
const pplbutton = getByTestId("PPL");
const sqlbutton = getByText('SQL');
waitFor(() => {
expect(pplbutton).toBeInTheDocument();
expect(sqlbutton).toBeInTheDocument();
fireEvent.click(sqlbutton);
});
const onRunButton = getByText('Run');
const asyncTest = () => {
Expand All @@ -206,12 +208,13 @@ describe('<Main /> spec', () => {
}
});

const { getByText,getByTestId } = await render(
const { getByText } = await render(
<Main httpClient={client} setBreadcrumbs={setBreadcrumbsMock} />
);
const pplbutton = getByTestId("PPL");
const sqlbutton = getByText('SQL');
waitFor(() => {
expect(pplbutton).toBeInTheDocument();
expect(sqlbutton).toBeInTheDocument();
fireEvent.click(sqlbutton);
});
const onTranslateButton = getByText('Explain');
const asyncTest = () => {
Expand All @@ -238,4 +241,4 @@ describe('<Main /> spec', () => {
await asyncTest();
expect(document.body.children[0]).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Compatible with OpenSearch and OpenSearch Dashboards 2.15.0
### Bug Fixes

- added fix for runAsync query without mds id ([#323](https://github.com/opensearch-project/dashboards-query-workbench/pull/323))

- Flakey unit tests fix ([#339](https://github.com/opensearch-project/dashboards-query-workbench/pull/339))

### Maintenance

Expand Down
Loading