Skip to content

Commit

Permalink
Update ppl editor readonly property (#248)
Browse files Browse the repository at this point in the history
* update ppl editor readonly property & fix flaky test

Signed-off-by: Shenoy Pratik <[email protected]>

* lint update

Signed-off-by: Shenoy Pratik <[email protected]>

* lint fixes for test file

Signed-off-by: Shenoy Pratik <[email protected]>

---------

Signed-off-by: Shenoy Pratik <[email protected]>
  • Loading branch information
ps48 authored Jan 19, 2024
1 parent 6408277 commit 0709b43
Show file tree
Hide file tree
Showing 3 changed files with 745 additions and 812 deletions.
5 changes: 2 additions & 3 deletions public/components/PPLPage/PPLPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import {
EuiText,
} from '@elastic/eui';
import React from 'react';
import { ResponseDetail, TranslateResult } from '../Main/main';
import { SAMPLE_PPL_QUERY } from '../../../common/constants';
import { ResponseDetail, TranslateResult } from '../Main/main';

interface PPLPageProps {
onRun: (query: string) => void;
onTranslate: (query: string) => void;
onClear: () => void;
updatePPLQueries: (query: string) => void;
pplQuery: string;
pplTranslations: ResponseDetail<TranslateResult>[];
pplTranslations: Array<ResponseDetail<TranslateResult>>;
selectedDatasource: EuiComboBoxOptionOption[];
asyncLoading: boolean;
}
Expand Down Expand Up @@ -122,7 +122,6 @@ export class PPLPage extends React.Component<PPLPageProps, PPLPageState> {
showGutter: false,
}}
aria-label="Code Editor"
isReadOnly={this.props.asyncLoading}
/>
<EuiSpacer />
<EuiFlexGroup className="action-container" gutterSize="m">
Expand Down
53 changes: 25 additions & 28 deletions public/components/QueryResults/QueryResultsBody.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import '@testing-library/jest-dom/extend-expect';
import { cleanup, fireEvent, render } from '@testing-library/react';
import { act, cleanup, fireEvent, render, waitFor } from '@testing-library/react';
import React from 'react';
import QueryResultsBody from './QueryResultsBody';
// @ts-ignore
Expand Down Expand Up @@ -72,7 +72,7 @@ function renderSQLQueryResultsBody(
};
}

describe('<QueryResultsBody /> spec', () => {
describe('<QueryResultsBody with SQL language/> spec', () => {
afterEach(cleanup);
const onQueryChange = jest.fn();
const updateExpandedMap = jest.fn();
Expand All @@ -87,7 +87,7 @@ describe('<QueryResultsBody /> spec', () => {
[
{
name: '',
getValue: (item: any) => '',
getValue: () => '',
isAscending: true,
},
],
Expand Down Expand Up @@ -128,7 +128,6 @@ describe('<QueryResultsBody /> spec', () => {

const {
getAllByText,
getAllByTestId,
getAllByLabelText,
getByText,
getByPlaceholderText,
Expand All @@ -154,10 +153,10 @@ describe('<QueryResultsBody /> spec', () => {

// Test pagination
await fireEvent.click(getAllByText('Rows per page', { exact: false })[0]);
expect(getByText('10 rows'));
expect(getByText('20 rows'));
expect(getByText('50 rows'));
expect(getByText('100 rows'));
expect(getByText('10 rows')).toBeInTheDocument();
expect(getByText('20 rows')).toBeInTheDocument();
expect(getByText('50 rows')).toBeInTheDocument();
expect(getByText('100 rows')).toBeInTheDocument();
await fireEvent.click(getByText('20 rows'));
expect(onChangeItemsPerPage).toHaveBeenCalled();

Expand All @@ -174,20 +173,24 @@ describe('<QueryResultsBody /> spec', () => {
const downloadButton = getAllByText('Download')[0];
expect(downloadButton).not.toBe(null);
await fireEvent.click(downloadButton);
expect(getByText('Download JSON'));
expect(getByText('Download JDBC'));
expect(getByText('Download CSV'));
expect(getByText('Download Text'));
expect(getByText('Download JSON')).toBeInTheDocument();
expect(getByText('Download JDBC')).toBeInTheDocument();
expect(getByText('Download CSV')).toBeInTheDocument();
expect(getByText('Download Text')).toBeInTheDocument();
await fireEvent.click(getByText('Download JSON'));
await fireEvent.click(getByText('Download JDBC'));
await fireEvent.click(getByText('Download CSV'));
await fireEvent.click(getByText('Download Text'));

// Test search field
const searchField = getByPlaceholderText('Search keyword');
expect(searchField).not.toBe(null);
await userEvent.type(searchField, 'Test');
expect(onQueryChange).toHaveBeenCalled();
expect(searchField).toBeInTheDocument();
act(() => {
userEvent.type(searchField, 'Test');
});
waitFor(() => {
expect(onQueryChange).toHaveBeenCalled();
});

// Test collapse button
expect(document.body.children[0]).toMatchSnapshot();
Expand Down Expand Up @@ -246,7 +249,7 @@ function renderPPLQueryResultsBody(
};
}

describe('<QueryResultsBody /> spec', () => {
describe('<QueryResultsBody with PPL language/> spec', () => {
afterEach(cleanup);
const onQueryChange = jest.fn();
const updateExpandedMap = jest.fn();
Expand All @@ -261,7 +264,7 @@ describe('<QueryResultsBody /> spec', () => {
[
{
name: '',
getValue: (item: any) => '',
getValue: () => '',
isAscending: true,
},
],
Expand Down Expand Up @@ -300,13 +303,7 @@ describe('<QueryResultsBody /> spec', () => {

(window as any).HTMLElement.prototype.scrollIntoView = function () {};

const {
getAllByText,
getAllByTestId,
getAllByLabelText,
getByText,
getByPlaceholderText,
} = renderPPLQueryResultsBody(
const { getAllByText, getAllByLabelText, getByText } = renderPPLQueryResultsBody(
undefined,
mockQueryResults[0].data,
mockQueryResultJDBCResponse.data.resp,
Expand All @@ -328,10 +325,10 @@ describe('<QueryResultsBody /> spec', () => {

// Test pagination
await fireEvent.click(getAllByText('Rows per page', { exact: false })[0]);
expect(getByText('10 rows'));
expect(getByText('20 rows'));
expect(getByText('50 rows'));
expect(getByText('100 rows'));
expect(getByText('10 rows')).toBeInTheDocument();
expect(getByText('20 rows')).toBeInTheDocument();
expect(getByText('50 rows')).toBeInTheDocument();
expect(getByText('100 rows')).toBeInTheDocument();
await fireEvent.click(getByText('20 rows'));
expect(onChangeItemsPerPage).toHaveBeenCalled();

Expand Down
Loading

0 comments on commit 0709b43

Please sign in to comment.