diff --git a/public/components/QueryResults/QueryResults.test.tsx b/public/components/QueryResults/QueryResults.test.tsx index 336bf0a8..d712dbdd 100644 --- a/public/components/QueryResults/QueryResults.test.tsx +++ b/public/components/QueryResults/QueryResults.test.tsx @@ -3,20 +3,20 @@ * SPDX-License-Identifier: Apache-2.0 */ - -import React from "react"; -import "regenerator-runtime"; -import "mutationobserver-shim"; -import "@testing-library/jest-dom/extend-expect"; -import { render, fireEvent, configure } from "@testing-library/react"; -import { mockQueryResults, mockQueries } from "../../../test/mocks/mockData"; -import { MESSAGE_TAB_LABEL } from "../../utils/constants"; -import QueryResults from "./QueryResults"; -import { Tab, ItemIdToExpandedRowMap, ResponseDetail, QueryResult } from "../Main/main"; +import React from 'react'; +import 'regenerator-runtime'; +import 'mutationobserver-shim'; +import '@testing-library/jest-dom/extend-expect'; +import { render, fireEvent, configure } from '@testing-library/react'; +import { mockQueryResults, mockQueries } from '../../../test/mocks/mockData'; +import { MESSAGE_TAB_LABEL } from '../../utils/constants'; +import QueryResults from './QueryResults'; +import { Tab, ItemIdToExpandedRowMap, ResponseDetail, QueryResult } from '../Main/main'; configure({ testIdAttribute: 'data-test-subj' }); -function renderSQLQueryResults(mockQueryResults: ResponseDetail[], +function renderSQLQueryResults( + mockQueryResults: ResponseDetail[], mockQueries: string[] = [], mockSearchQuery: string = '', onSelectedTabIdChange: (tab: Tab) => void, @@ -26,12 +26,12 @@ function renderSQLQueryResults(mockQueryResults: ResponseDetail[], getJdbc: (queries: string[]) => void, getCsv: (queries: string[]) => void, getText: (queries: string[]) => void, - setIsResultFullScreen: (isFullScreen: boolean) => void) { - + setIsResultFullScreen: (isFullScreen: boolean) => void +) { return { ...render( [], getText={getText} isResultFullScreen={false} setIsResultFullScreen={setIsResultFullScreen} + asyncLoadingStatus="SUCCESS" + asyncQueryError="" + selectedDatasource={[{ label: 'OpenSearch' }]} + cancelAsyncQuery={() => {}} /> ), }; } -describe(" spec", () => { - it("renders the component with no data", async () => { - (window as any).HTMLElement.prototype.scrollBy = function () { }; +describe(' spec', () => { + it('renders the component with no data', async () => { + (window as any).HTMLElement.prototype.scrollBy = function () {}; expect(document.body.children[0]).toMatchSnapshot(); }); }); -describe(" spec", () => { +describe(' spec', () => { const onSelectedTabIdChange = jest.fn(); const onQueryChange = jest.fn(); const updateExpandedMap = jest.fn(); - const mockSearchQuery = ""; + const mockSearchQuery = ''; const getRawResponse = jest.fn(); const getJdbc = jest.fn(); const getCsv = jest.fn(); @@ -77,10 +81,26 @@ describe(" spec", () => { const setIsResultFullScreen = jest.fn(); (window as any).HTMLElement.prototype.scrollBy = jest.fn(); - it("renders the component with mock query results", async () => { - const { getAllByRole, getByText, getAllByText, getAllByTestId, getAllByLabelText } = - renderSQLQueryResults(mockQueryResults, mockQueries, mockSearchQuery, onSelectedTabIdChange, onQueryChange, - updateExpandedMap, getRawResponse, getJdbc, getCsv, getText, setIsResultFullScreen); + it('renders the component with mock query results', async () => { + const { + getAllByRole, + getByText, + getAllByText, + getAllByTestId, + getAllByLabelText, + } = renderSQLQueryResults( + mockQueryResults, + mockQueries, + mockSearchQuery, + onSelectedTabIdChange, + onQueryChange, + updateExpandedMap, + getRawResponse, + getJdbc, + getCsv, + getText, + setIsResultFullScreen + ); expect(document.body.children[0]).toMatchSnapshot(); @@ -101,16 +121,27 @@ describe(" spec", () => { // It tests pagination await fireEvent.click(getAllByLabelText('Page 2 of 2')[0]); 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")); - await fireEvent.click(getByText("20 rows")); + expect(getByText('10 rows')); + expect(getByText('20 rows')); + expect(getByText('50 rows')); + expect(getByText('100 rows')); + await fireEvent.click(getByText('20 rows')); }); - it("renders the component to test tabs down arrow", async () => { - const { getAllByTestId } = renderSQLQueryResults(mockQueryResults, mockQueries, mockSearchQuery, onSelectedTabIdChange, - onQueryChange, updateExpandedMap, getRawResponse, getJdbc, getCsv, getText, setIsResultFullScreen); + it('renders the component to test tabs down arrow', async () => { + const { getAllByTestId } = renderSQLQueryResults( + mockQueryResults, + mockQueries, + mockSearchQuery, + onSelectedTabIdChange, + onQueryChange, + updateExpandedMap, + getRawResponse, + getJdbc, + getCsv, + getText, + setIsResultFullScreen + ); expect(document.body.children[0]).toMatchSnapshot(); @@ -118,11 +149,10 @@ describe(" spec", () => { expect(getAllByTestId('slide-down')); await fireEvent.click(getAllByTestId('slide-down')[0]); }); - }); - -function renderPPLQueryResults(mockQueryResults: ResponseDetail[], +function renderPPLQueryResults( + mockQueryResults: ResponseDetail[], mockQueries: string[] = [], mockSearchQuery: string = '', onSelectedTabIdChange: (tab: Tab) => void, @@ -132,12 +162,12 @@ function renderPPLQueryResults(mockQueryResults: ResponseDetail[], getJdbc: (queries: string[]) => void, getCsv: (queries: string[]) => void, getText: (queries: string[]) => void, - setIsResultFullScreen: (isFullScreen: boolean) => void) { - + setIsResultFullScreen: (isFullScreen: boolean) => void +) { return { ...render( [], getText={getText} isResultFullScreen={false} setIsResultFullScreen={setIsResultFullScreen} + asyncLoadingStatus="SUCCESS" + asyncQueryError="" + selectedDatasource={[{ label: 'OpenSearch' }]} + cancelAsyncQuery={() => {}} /> ), }; } -describe(" spec", () => { - it("renders the component with no data", async () => { - (window as any).HTMLElement.prototype.scrollBy = function () { }; +describe(' spec', () => { + it('renders the component with no data', async () => { + (window as any).HTMLElement.prototype.scrollBy = function () {}; expect(document.body.children[0]).toMatchSnapshot(); }); }); -describe(" spec", () => { +describe(' spec', () => { const onSelectedTabIdChange = jest.fn(); const onQueryChange = jest.fn(); const updateExpandedMap = jest.fn(); - const mockSearchQuery = ""; + const mockSearchQuery = ''; const getRawResponse = jest.fn(); const getJdbc = jest.fn(); const getCsv = jest.fn(); @@ -184,10 +218,26 @@ describe(" spec", () => { const setIsResultFullScreen = jest.fn(); (window as any).HTMLElement.prototype.scrollBy = jest.fn(); - it("renders the component with mock query results", async () => { - const { getAllByRole, getByText, getAllByText, getAllByTestId, getAllByLabelText } = - renderPPLQueryResults(mockQueryResults, mockQueries, mockSearchQuery, onSelectedTabIdChange, onQueryChange, - updateExpandedMap, getRawResponse, getJdbc, getCsv, getText, setIsResultFullScreen); + it('renders the component with mock query results', async () => { + const { + getAllByRole, + getByText, + getAllByText, + getAllByTestId, + getAllByLabelText, + } = renderPPLQueryResults( + mockQueryResults, + mockQueries, + mockSearchQuery, + onSelectedTabIdChange, + onQueryChange, + updateExpandedMap, + getRawResponse, + getJdbc, + getCsv, + getText, + setIsResultFullScreen + ); expect(document.body.children[0]).toMatchSnapshot(); @@ -208,16 +258,27 @@ describe(" spec", () => { // It tests pagination await fireEvent.click(getAllByLabelText('Page 2 of 2')[0]); 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")); - await fireEvent.click(getByText("20 rows")); + expect(getByText('10 rows')); + expect(getByText('20 rows')); + expect(getByText('50 rows')); + expect(getByText('100 rows')); + await fireEvent.click(getByText('20 rows')); }); - it("renders the component to test tabs down arrow", async () => { - const { getAllByTestId } = renderPPLQueryResults(mockQueryResults, mockQueries, mockSearchQuery, onSelectedTabIdChange, - onQueryChange, updateExpandedMap, getRawResponse, getJdbc, getCsv, getText, setIsResultFullScreen); + it('renders the component to test tabs down arrow', async () => { + const { getAllByTestId } = renderPPLQueryResults( + mockQueryResults, + mockQueries, + mockSearchQuery, + onSelectedTabIdChange, + onQueryChange, + updateExpandedMap, + getRawResponse, + getJdbc, + getCsv, + getText, + setIsResultFullScreen + ); expect(document.body.children[0]).toMatchSnapshot(); @@ -225,5 +286,4 @@ describe(" spec", () => { expect(getAllByTestId('slide-down')); await fireEvent.click(getAllByTestId('slide-down')[0]); }); - }); diff --git a/public/components/QueryResults/QueryResults.tsx b/public/components/QueryResults/QueryResults.tsx index f17cc0ee..55f4f2ce 100644 --- a/public/components/QueryResults/QueryResults.tsx +++ b/public/components/QueryResults/QueryResults.tsx @@ -45,7 +45,7 @@ import { ResponseDetail, Tab, } from '../Main/main'; -import { AsyncQueryBody } from './AsyncQueryBody'; +import { AsyncQueryBody } from './async_query_body'; import QueryResultsBody from './QueryResultsBody'; interface QueryResultsProps { diff --git a/public/components/QueryResults/__snapshots__/QueryResults.test.tsx.snap b/public/components/QueryResults/__snapshots__/QueryResults.test.tsx.snap index 5c99ca41..44fc7d0c 100644 --- a/public/components/QueryResults/__snapshots__/QueryResults.test.tsx.snap +++ b/public/components/QueryResults/__snapshots__/QueryResults.test.tsx.snap @@ -328,6 +328,52 @@ exports[` spec renders the component to test tabs down +
+
+
+
+ +
+
+
+
spec renders the component with mock query re
+
+
+
+
+ +
+
+
+