Skip to content

Commit

Permalink
Flakey unit tests fix (#339)
Browse files Browse the repository at this point in the history
* fixed flakey tests

Signed-off-by: sumukhswamy <sumukhhs@amazon.com>

* fixed linter issues

Signed-off-by: sumukhswamy <sumukhhs@amazon.com>

* added pr in release notes

Signed-off-by: sumukhswamy <sumukhhs@amazon.com>

---------

Signed-off-by: sumukhswamy <sumukhhs@amazon.com>
  • Loading branch information
sumukhswamy committed Jun 11, 2024
1 parent e22d6b4 commit 2bb8eb0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
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

0 comments on commit 2bb8eb0

Please sign in to comment.