Skip to content

Commit

Permalink
updated tests for main
Browse files Browse the repository at this point in the history
Signed-off-by: sumukhswamy <[email protected]>
  • Loading branch information
sumukhswamy committed Apr 30, 2024
1 parent dc95c8c commit 0e09356
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
44 changes: 28 additions & 16 deletions public/components/Main/__snapshots__/main.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ exports[`<Main /> spec click clear button 1`] = `
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -82,6 +83,7 @@ exports[`<Main /> spec click clear button 1`] = `
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
Expand All @@ -107,6 +109,7 @@ exports[`<Main /> spec click clear button 1`] = `
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
Expand Down Expand Up @@ -508,6 +511,7 @@ exports[`<Main /> spec click run button, and response causes an error 1`] = `
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -519,6 +523,7 @@ exports[`<Main /> spec click run button, and response causes an error 1`] = `
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
Expand All @@ -544,6 +549,7 @@ exports[`<Main /> spec click run button, and response causes an error 1`] = `
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
Expand Down Expand Up @@ -945,6 +951,7 @@ exports[`<Main /> spec click run button, and response is not ok 1`] = `
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -956,15 +963,14 @@ exports[`<Main /> spec click run button, and response is not ok 1`] = `
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
class="euiButtonContent euiButton__content"
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="SQL"
title="SQL"
>
<input
checked=""
Expand All @@ -981,15 +987,14 @@ exports[`<Main /> spec click run button, and response is not ok 1`] = `
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
class="euiButtonContent euiButton__content"
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="PPL"
title="PPL"
>
<input
class="euiScreenReaderOnly"
Expand Down Expand Up @@ -1382,6 +1387,7 @@ exports[`<Main /> spec click run button, and response is ok 1`] = `
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -1393,15 +1399,14 @@ exports[`<Main /> spec click run button, and response is ok 1`] = `
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
class="euiButtonContent euiButton__content"
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="SQL"
title="SQL"
>
<input
checked=""
Expand All @@ -1418,15 +1423,14 @@ exports[`<Main /> spec click run button, and response is ok 1`] = `
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
class="euiButtonContent euiButton__content"
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="PPL"
title="PPL"
>
<input
class="euiScreenReaderOnly"
Expand Down Expand Up @@ -1819,6 +1823,7 @@ exports[`<Main /> spec click run button, response fills null and missing values
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -1830,15 +1835,14 @@ exports[`<Main /> spec click run button, response fills null and missing values
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
class="euiButtonContent euiButton__content"
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="SQL"
title="SQL"
>
<input
checked=""
Expand All @@ -1855,15 +1859,14 @@ exports[`<Main /> spec click run button, response fills null and missing values
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
class="euiButtonContent euiButton__content"
>
<span
class="euiButton__text euiButtonGroupButton__textShift"
data-text="PPL"
title="PPL"
>
<input
class="euiScreenReaderOnly"
Expand Down Expand Up @@ -2186,10 +2189,7 @@ exports[`<Main /> spec click run button, response fills null and missing values
`;

exports[`<Main /> spec click translation button, and response is ok 1`] = `
<div
aria-hidden="true"
data-aria-hidden="true"
>
<div>
<div
class="euiPage euiPage--grow"
>
Expand Down Expand Up @@ -2259,6 +2259,7 @@ exports[`<Main /> spec click translation button, and response is ok 1`] = `
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -2270,6 +2271,7 @@ exports[`<Main /> spec click translation button, and response is ok 1`] = `
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
Expand All @@ -2295,6 +2297,7 @@ exports[`<Main /> spec click translation button, and response is ok 1`] = `
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
Expand Down Expand Up @@ -2696,6 +2699,7 @@ exports[`<Main /> spec renders the component 1`] = `
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -2707,6 +2711,7 @@ exports[`<Main /> spec renders the component 1`] = `
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
Expand All @@ -2732,6 +2737,7 @@ exports[`<Main /> spec renders the component 1`] = `
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
Expand Down Expand Up @@ -4161,6 +4167,7 @@ exports[`<Main /> spec renders the component and checks if side tree is loaded 1
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -4172,6 +4179,7 @@ exports[`<Main /> spec renders the component and checks if side tree is loaded 1
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
Expand All @@ -4197,6 +4205,7 @@ exports[`<Main /> spec renders the component and checks if side tree is loaded 1
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
Expand Down Expand Up @@ -4598,6 +4607,7 @@ exports[`<Main /> spec renders the component and toggles ppl 1`] = `
>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -4609,6 +4619,7 @@ exports[`<Main /> spec renders the component and toggles ppl 1`] = `
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
Expand All @@ -4634,6 +4645,7 @@ exports[`<Main /> spec renders the component and toggles ppl 1`] = `
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
Expand Down
24 changes: 20 additions & 4 deletions public/components/Main/main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ describe('<Main /> spec', () => {
client.get = jest.fn().mockResolvedValue(mockDatasourcesQuery);
client.post = jest.fn().mockResolvedValue(mockQueryResultJDBCResponse);

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

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

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

const { getByText } = await render(
const { getByText,getByTestId } = await render(
<Main httpClient={client} setBreadcrumbs={setBreadcrumbsMock} />
);
const pplbutton = getByTestId("PPL");
waitFor(() => {
expect(pplbutton).toBeInTheDocument();
});
const onTranslateButton = getByText('Explain');
const asyncTest = () => {
fireEvent.click(onTranslateButton);
Expand Down
3 changes: 1 addition & 2 deletions public/components/QueryLanguageSwitch/ClusterTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class ClusterTabs extends React.Component<SwitchProps> {
render() {
return (
<EuiButtonGroup
className="query-language-switch"
legend="query-language-swtich"
legend='cluster-selector'
options={toggleButtons}
onChange={(id) => this.props.onChange(id)}
idSelected={this.props.cluster}
Expand Down
3 changes: 3 additions & 0 deletions public/components/QueryLanguageSwitch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ const toggleButtons = [
{
id: 'SQL',
label: 'SQL',
"data-test-subj":'switch-button-sql'
},
{
id: 'PPL',
label: 'PPL',
"data-test-subj":'switch-button-ppl'
},
];

Expand All @@ -39,6 +41,7 @@ class Switch extends React.Component<SwitchProps, SwitchState> {
render() {
return (
<EuiButtonGroup
data-test-subj='switch-button'
className="query-language-switch"
legend="query-language-swtich"
options={toggleButtons}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`<Switch /> spec renders the component 1`] = `
<div>
<fieldset
class="euiButtonGroup euiButtonGroup--small euiButtonGroup--text query-language-switch"
data-test-subj="switch-button"
>
<legend
class="euiScreenReaderOnly"
Expand All @@ -15,6 +16,7 @@ exports[`<Switch /> spec renders the component 1`] = `
>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton--fill euiButtonGroupButton-isSelected"
data-test-subj="switch-button-sql"
for="some_html_id"
>
<span
Expand All @@ -40,6 +42,7 @@ exports[`<Switch /> spec renders the component 1`] = `
</label>
<label
class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small"
data-test-subj="switch-button-ppl"
for="some_html_id"
>
<span
Expand Down

0 comments on commit 0e09356

Please sign in to comment.