From baf9711a787d8f2716507ec422c9ea225550795b Mon Sep 17 00:00:00 2001 From: Arash Date: Thu, 20 May 2021 12:36:52 -0400 Subject: [PATCH] added testing --- .../javascripts/sqllab/ResultSet_spec.jsx | 92 +++++++++++-------- .../spec/javascripts/sqllab/fixtures.ts | 61 ++++++++++++ .../src/SqlLab/components/ResultSet.tsx | 1 - 3 files changed, 115 insertions(+), 39 deletions(-) diff --git a/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx b/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx index 69e87f97e6b2b..7aee845dd8fc5 100644 --- a/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx +++ b/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx @@ -19,6 +19,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import { styledMount } from 'spec/helpers/theming'; +import { render } from 'spec/helpers/testing-library'; +import { screen } from '@testing-library/react'; import { Provider } from 'react-redux'; import sinon from 'sinon'; import Alert from 'src/components/Alert'; @@ -38,49 +40,48 @@ import { stoppedQuery, initialState, user, + queryWithNoQueryLimit, } from './fixtures'; const mockStore = configureStore([thunk]); const store = mockStore(initialState); - -describe('ResultSet', () => { - const clearQuerySpy = sinon.spy(); - const fetchQuerySpy = sinon.spy(); - const reRunQuerySpy = sinon.spy(); - const mockedProps = { - actions: { - clearQueryResults: clearQuerySpy, - fetchQueryResults: fetchQuerySpy, - reRunQuery: reRunQuerySpy, - }, - 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 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 }], - }, +const clearQuerySpy = sinon.spy(); +const fetchQuerySpy = sinon.spy(); +const reRunQuerySpy = sinon.spy(); +const mockedProps = { + actions: { + clearQueryResults: clearQuerySpy, + fetchQueryResults: fetchQuerySpy, + reRunQuery: reRunQuerySpy, + }, + 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 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 }], }, - }; - + }, +}; +describe('ResultSet', () => { it('is valid', () => { expect(React.isValidElement()).toBe(true); }); @@ -182,3 +183,18 @@ describe('ResultSet', () => { }); }); }); + +describe('RTL ResultSet tests', () => { + it('renders if there props has no limit in query.results but has queryLimit', () => { + render(, { useRedux: true }); + const grid = screen.getAllByRole('grid'); + expect(grid.length).toBe(1); + }); + + it('Renders if there is a limit in query.results but not queryLimit', () => { + const props = { ...mockedProps, query: queryWithNoQueryLimit }; + render(, { useRedux: true }); + const grid = screen.getAllByRole('grid'); + expect(grid.length).toBe(1); + }); +}); diff --git a/superset-frontend/spec/javascripts/sqllab/fixtures.ts b/superset-frontend/spec/javascripts/sqllab/fixtures.ts index 911a89d5fed7e..b4b68454fa309 100644 --- a/superset-frontend/spec/javascripts/sqllab/fixtures.ts +++ b/superset-frontend/spec/javascripts/sqllab/fixtures.ts @@ -283,6 +283,67 @@ export const queries = [ results: null, }, ]; +export const queryWithNoQueryLimit = { + dbId: 1, + sql: 'SELECT * FROM superset.slices', + sqlEditorId: 'SJ8YO72R', + tab: 'Demo', + runAsync: false, + ctas: false, + cached: false, + id: 'BkA1CLrJg', + progress: 100, + startDttm: 1476910566092.96, + state: 'success', + changedOn: 1476910566000, + tempTable: null, + userId: 1, + executedSql: null, + changed_on: '2016-10-19T20:56:06', + rows: 42, + endDttm: 1476910566798, + limit_reached: false, + schema: 'test_schema', + errorMessage: null, + db: 'main', + user: 'admin', + limit: 1000, + serverId: 141, + resultsKey: null, + results: { + columns: [ + { + is_date: true, + name: 'ds', + type: 'STRING', + }, + { + is_date: false, + name: 'gender', + type: 'STRING', + }, + ], + selected_columns: [ + { + is_date: true, + name: 'ds', + type: 'STRING', + }, + { + is_date: false, + name: 'gender', + type: 'STRING', + }, + ], + data: [ + { col1: 0, col2: 1 }, + { col1: 2, col2: 3 }, + ], + query: { + limit: 100, + }, + }, +}; export const queryWithBadColumns = { ...queries[0], results: { diff --git a/superset-frontend/src/SqlLab/components/ResultSet.tsx b/superset-frontend/src/SqlLab/components/ResultSet.tsx index 3b466c20973b7..a8fe019c7e6a0 100644 --- a/superset-frontend/src/SqlLab/components/ResultSet.tsx +++ b/superset-frontend/src/SqlLab/components/ResultSet.tsx @@ -528,7 +528,6 @@ export default class ResultSet extends React.PureComponent< const limitReached = results?.displayLimitReached; const limit = queryLimit || results.query.limit; const isAdmin = !!this.props.user?.roles.Admin; - const limit = queryLimit || results.query.limit; const displayMaxRowsReachedMessage = { withAdmin: t( `The number of results displayed is limited to %(rows)d by the configuration DISPLAY_MAX_ROWS. `,