lyndsiWilliams commented on code in PR #21186:
URL: https://github.com/apache/superset/pull/21186#discussion_r956413885


##########
superset-frontend/src/SqlLab/components/ExploreCtasResultsButton/index.tsx:
##########
@@ -17,36 +17,35 @@
  * under the License.
  */
 import React from 'react';
-import { useSelector } from 'react-redux';
-import { t } from '@superset-ui/core';
+import { useSelector, useDispatch } from 'react-redux';
+import { t, JsonObject } from '@superset-ui/core';
+import {
+  createCtasDatasource,
+  addInfoToast,
+  addDangerToast,
+} from 'src/SqlLab/actions/sqlLab';
 import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
 import Button from 'src/components/Button';
 import { exploreChart } from 'src/explore/exploreUtils';
 import { SqlLabRootState } from 'src/SqlLab/types';
 
 interface ExploreCtasResultsButtonProps {
-  actions: {
-    createCtasDatasource: Function;
-    addInfoToast: Function;
-    addDangerToast: Function;
-  };
   table: string;
   schema?: string | null;
   dbId: number;
   templateParams?: string;
 }
 
 const ExploreCtasResultsButton = ({
-  actions,
   table,
   schema,
   dbId,
   templateParams,
 }: ExploreCtasResultsButtonProps) => {
-  const { createCtasDatasource, addInfoToast, addDangerToast } = actions;
   const errorMessage = useSelector(
     (state: SqlLabRootState) => state.sqlLab.errorMessage,
   );
+  const dispatch = useDispatch<(dispatch: any) => Promise<JsonObject>>();

Review Comment:
   Define `any`



##########
superset-frontend/src/SqlLab/components/ResultSet/ResultSet.test.tsx:
##########
@@ -0,0 +1,212 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import React from 'react';
+import { render } from 'spec/helpers/testing-library';
+import configureStore from 'redux-mock-store';
+import { Store } from 'redux';
+import thunk from 'redux-thunk';
+import fetchMock from 'fetch-mock';
+import ResultSet from 'src/SqlLab/components/ResultSet';
+import {
+  cachedQuery,
+  failedQueryWithErrorMessage,
+  failedQueryWithErrors,
+  queries,
+  runningQuery,
+  stoppedQuery,
+  initialState,
+  user,
+  queryWithNoQueryLimit,
+} from 'src/SqlLab/fixtures';
+
+const mockedProps = {
+  cache: true,
+  query: queries[0],
+  height: 140,
+  database: { allows_virtual_table_explore: true },
+  user,
+  defaultQueryLimit: 1000,
+};
+const stoppedQueryProps = { ...mockedProps, query: stoppedQuery };
+const runningQueryProps = { ...mockedProps, query: runningQuery };
+const fetchingQueryProps = {
+  ...mockedProps,
+  query: {
+    dbId: 1,
+    cached: false,
+    ctas: false,
+    id: 'ryhHUZCGb',
+    progress: 100,
+    state: 'fetching',
+    startDttm: Date.now() - 500,
+  },
+};
+const cachedQueryProps = { ...mockedProps, query: cachedQuery };
+const failedQueryWithErrorMessageProps = {
+  ...mockedProps,
+  query: failedQueryWithErrorMessage,
+};
+const failedQueryWithErrorsProps = {
+  ...mockedProps,
+  query: failedQueryWithErrors,
+};
+const newProps = {
+  query: {
+    cached: false,
+    resultsKey: 'new key',
+    results: {
+      data: [{ a: 1 }],
+    },
+  },
+};
+fetchMock.get('glob:*/api/v1/dataset?*', { result: [] });
+
+const middlewares = [thunk];
+const mockStore = configureStore(middlewares);
+const setup = (props?: any, store?: Store) =>
+  render(<ResultSet {...props} />, {
+    useRedux: true,
+    ...(store && { store }),
+  });
+
+describe('ResultSet', () => {
+  it('renders a Table', async () => {
+    const { getByTestId } = setup(mockedProps, mockStore(initialState));
+    const table = getByTestId('table-container');
+    expect(table).toBeInTheDocument();
+  });
+
+  it('should render success query', async () => {
+    const { queryAllByText, getByTestId } = setup(
+      mockedProps,
+      mockStore(initialState),
+    );
+
+    const table = getByTestId('table-container');
+    expect(table).toBeInTheDocument();
+
+    const firstColumn = queryAllByText(
+      mockedProps.query.results?.columns[0].name ?? '',
+    )[0];
+    const secondColumn = queryAllByText(
+      mockedProps.query.results?.columns[1].name ?? '',
+    )[0];
+    expect(firstColumn).toBeInTheDocument();
+    expect(secondColumn).toBeInTheDocument();
+
+    const exploreButton = getByTestId('explore-results-button');
+    expect(exploreButton).toBeInTheDocument();
+  });
+
+  it('should render empty results', async () => {
+    const props = {
+      ...mockedProps,
+      query: { ...mockedProps.query, results: { data: [] } },
+    };
+    const { getByRole } = setup(props, mockStore(initialState));
+
+    const alert = getByRole('alert');
+    expect(alert).toBeInTheDocument();
+    expect(alert).toHaveTextContent('The query returned no data');
+  });
+
+  it('should call reRunQuery if timed out', async () => {
+    const store = mockStore(initialState);
+    const propsWithError = {
+      ...mockedProps,
+      query: { ...queries[0], errorMessage: 'Your session timed out' },
+    };
+
+    setup(propsWithError, store);
+    expect(store.getActions()).toHaveLength(1);
+    expect(store.getActions()[0].query.errorMessage).toEqual(
+      'Your session timed out',
+    );
+    expect(store.getActions()[0].type).toEqual('START_QUERY');
+  });
+
+  it('should not call reRunQuery if no error', async () => {
+    const store = mockStore(initialState);
+    setup(mockedProps, store);
+    expect(store.getActions()).toEqual([]);
+  });
+
+  it('should render cached query', async () => {
+    const store = mockStore(initialState);
+    const { rerender } = setup(cachedQueryProps, store);
+
+    // @ts-ignore

Review Comment:
   What is the TS error here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to