From b38dd05102719d5328a9e5f6a9a4928034d4b4ff Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 19 Jan 2024 16:02:18 +0000 Subject: [PATCH] Update ppl editor readonly property (#248) * update ppl editor readonly property & fix flaky test Signed-off-by: Shenoy Pratik * lint update Signed-off-by: Shenoy Pratik * lint fixes for test file Signed-off-by: Shenoy Pratik --------- Signed-off-by: Shenoy Pratik (cherry picked from commit 0709b434dd8750ac704759eee9269bccf1fe2a64) Signed-off-by: github-actions[bot] --- public/components/PPLPage/PPLPage.tsx | 5 +- .../QueryResults/QueryResultsBody.test.tsx | 53 +- .../QueryResultsBody.test.tsx.snap | 1499 ++++++++--------- 3 files changed, 745 insertions(+), 812 deletions(-) diff --git a/public/components/PPLPage/PPLPage.tsx b/public/components/PPLPage/PPLPage.tsx index 58f39dd7..db244fea 100644 --- a/public/components/PPLPage/PPLPage.tsx +++ b/public/components/PPLPage/PPLPage.tsx @@ -21,8 +21,8 @@ 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; @@ -30,7 +30,7 @@ interface PPLPageProps { onClear: () => void; updatePPLQueries: (query: string) => void; pplQuery: string; - pplTranslations: ResponseDetail[]; + pplTranslations: Array>; selectedDatasource: EuiComboBoxOptionOption[]; asyncLoading: boolean; } @@ -122,7 +122,6 @@ export class PPLPage extends React.Component { showGutter: false, }} aria-label="Code Editor" - isReadOnly={this.props.asyncLoading} /> diff --git a/public/components/QueryResults/QueryResultsBody.test.tsx b/public/components/QueryResults/QueryResultsBody.test.tsx index b9f5aa1c..34e4ddb6 100644 --- a/public/components/QueryResults/QueryResultsBody.test.tsx +++ b/public/components/QueryResults/QueryResultsBody.test.tsx @@ -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 @@ -72,7 +72,7 @@ function renderSQLQueryResultsBody( }; } -describe(' spec', () => { +describe(' spec', () => { afterEach(cleanup); const onQueryChange = jest.fn(); const updateExpandedMap = jest.fn(); @@ -87,7 +87,7 @@ describe(' spec', () => { [ { name: '', - getValue: (item: any) => '', + getValue: () => '', isAscending: true, }, ], @@ -128,7 +128,6 @@ describe(' spec', () => { const { getAllByText, - getAllByTestId, getAllByLabelText, getByText, getByPlaceholderText, @@ -154,10 +153,10 @@ describe(' 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(); @@ -174,10 +173,10 @@ describe(' 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')); @@ -185,9 +184,13 @@ describe(' spec', () => { // 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(); @@ -246,7 +249,7 @@ function renderPPLQueryResultsBody( }; } -describe(' spec', () => { +describe(' spec', () => { afterEach(cleanup); const onQueryChange = jest.fn(); const updateExpandedMap = jest.fn(); @@ -261,7 +264,7 @@ describe(' spec', () => { [ { name: '', - getValue: (item: any) => '', + getValue: () => '', isAscending: true, }, ], @@ -300,13 +303,7 @@ describe(' 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, @@ -328,10 +325,10 @@ describe(' 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(); diff --git a/public/components/QueryResults/__snapshots__/QueryResultsBody.test.tsx.snap b/public/components/QueryResults/__snapshots__/QueryResultsBody.test.tsx.snap index c2a1fd09..d75233d4 100644 --- a/public/components/QueryResults/__snapshots__/QueryResultsBody.test.tsx.snap +++ b/public/components/QueryResults/__snapshots__/QueryResultsBody.test.tsx.snap @@ -1,127 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` spec renders component with mock QueryResults data 1`] = ` +exports[` spec renders component with mock QueryResults data 1`] = `
-
-
-

- Messages - - (13) - -

-
-
- -
-
-
-
-
-
- -
-
-
-
-
+ />
@@ -177,7 +62,6 @@ exports[` spec renders component with mock QueryResults data > category @@ -194,7 +78,6 @@ exports[` spec renders component with mock QueryResults data > currency @@ -211,7 +94,6 @@ exports[` spec renders component with mock QueryResults data > customer_first_name @@ -228,7 +110,6 @@ exports[` spec renders component with mock QueryResults data > customer_full_name @@ -245,7 +126,6 @@ exports[` spec renders component with mock QueryResults data > customer_gender @@ -262,7 +142,6 @@ exports[` spec renders component with mock QueryResults data > customer_id @@ -279,7 +158,6 @@ exports[` spec renders component with mock QueryResults data > customer_last_name @@ -296,7 +174,6 @@ exports[` spec renders component with mock QueryResults data > customer_phone @@ -313,7 +190,6 @@ exports[` spec renders component with mock QueryResults data > day_of_week @@ -330,7 +206,6 @@ exports[` spec renders component with mock QueryResults data > day_of_week_i @@ -347,7 +222,6 @@ exports[` spec renders component with mock QueryResults data > email @@ -364,7 +238,6 @@ exports[` spec renders component with mock QueryResults data > manufacturer @@ -381,7 +254,6 @@ exports[` spec renders component with mock QueryResults data > order_date @@ -398,7 +270,6 @@ exports[` spec renders component with mock QueryResults data > order_id @@ -415,7 +286,6 @@ exports[` spec renders component with mock QueryResults data > products @@ -432,7 +302,6 @@ exports[` spec renders component with mock QueryResults data > sku @@ -449,7 +318,6 @@ exports[` spec renders component with mock QueryResults data > taxful_total_price @@ -466,7 +334,6 @@ exports[` spec renders component with mock QueryResults data > taxless_total_price @@ -483,7 +350,6 @@ exports[` spec renders component with mock QueryResults data > total_quantity @@ -500,7 +366,6 @@ exports[` spec renders component with mock QueryResults data > total_unique_products @@ -517,7 +382,6 @@ exports[` spec renders component with mock QueryResults data > type @@ -534,7 +398,6 @@ exports[` spec renders component with mock QueryResults data > user @@ -551,7 +414,6 @@ exports[` spec renders component with mock QueryResults data > geoip @@ -582,7 +444,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -963,7 +826,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -1344,7 +1208,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -1725,7 +1590,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -2106,7 +1972,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -2487,7 +2354,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -2868,7 +2736,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -3249,7 +3118,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -3630,7 +3500,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -4011,7 +3882,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -4392,7 +4264,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -4783,7 +4656,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -4846,7 +4721,7 @@ exports[` spec renders component with mock QueryResults data > spec renders component with mock QueryResults data xmlns="http://www.w3.org/2000/svg" > @@ -4867,23 +4743,145 @@ exports[` spec renders component with mock QueryResults data
`; -exports[` spec renders component with mock QueryResults data 2`] = ` +exports[` spec renders the component 1`] = `
-
+
+
+