-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Additional ResultSet tests #14741
Changes from 7 commits
5800efc
baf9711
663d3f6
85320b7
753c6b4
5da9ecf
1497624
526d51a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { styledMount } from 'spec/helpers/theming'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import { Provider } from 'react-redux'; | ||
import sinon from 'sinon'; | ||
import Alert from 'src/components/Alert'; | ||
|
@@ -38,49 +39,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(<ResultSet {...mockedProps} />)).toBe(true); | ||
}); | ||
|
@@ -182,3 +182,16 @@ describe('ResultSet', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('RTL ResultSet tests', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as my other comment concerning the usage of describe |
||
it('renders if there is no limit in query.results but has queryLimit', () => { | ||
render(<ResultSet {...mockedProps} />, { useRedux: true }); | ||
expect(screen.getByRole('grid')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders if there is a limit in query.results but not queryLimit', () => { | ||
const props = { ...mockedProps, query: queryWithNoQueryLimit }; | ||
render(<ResultSet {...props} />, { useRedux: true }); | ||
expect(screen.getByRole('grid')).toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -526,34 +526,32 @@ export default class ResultSet extends React.PureComponent< | |
const { results, rows, queryLimit, limitingFactor } = this.props.query; | ||
let limitMessage; | ||
const limitReached = results?.displayLimitReached; | ||
const isAdmin = !!this.props.user?.roles.Admin; | ||
const limit = queryLimit || results.query.limit; | ||
const isAdmin = !!this.props.user?.roles.Admin; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm getting an error in SQLLab here if the this.props.user.roles is undefined. Changing this code to the below fixes the issue. If roles is undefined assume it's not admin. I'm not sure why roles wouldn't be populated though. I was logged in as an Administrator.
Since this is only used to change the display message, I don't think the above fix will break any functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that makes sense to me, @eschutho what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks good. @suddjian did make a fix whereby localstorage was overwriting user roles, but I think this works as a guard against any other issues that may be creeping up. At some point maybe we can take another look into why or when a user wouldn't have any roles. |
||
const displayMaxRowsReachedMessage = { | ||
withAdmin: t( | ||
`The number of results displayed is limited to %(rows)d by the configuration DISPLAY_MAX_ROWS. `, | ||
{ rows }, | ||
).concat( | ||
t( | ||
`Please add additional limits/filters or download to csv to see more rows up to the`, | ||
`Please add additional limits/filters or download to csv to see more rows up to `, | ||
), | ||
t(`the %(limit)d limit.`, { | ||
limit, | ||
}), | ||
t(`the %(limit)d limit.`, { limit }), | ||
), | ||
withoutAdmin: t( | ||
`The number of results displayed is limited to %(rows)d. `, | ||
{ rows }, | ||
).concat( | ||
t( | ||
`Please add additional limits/filters, download to csv, or contact an admin`, | ||
`Please add additional limits/filters, download to csv, or contact an admin `, | ||
), | ||
t(`to see more rows up to the the %(limit)d limit.`, { | ||
t(`to see more rows up to the %(limit)d limit.`, { | ||
limit, | ||
}), | ||
), | ||
}; | ||
const shouldUseDefaultDropdownAlert = | ||
queryLimit === this.props.defaultQueryLimit && | ||
limit === this.props.defaultQueryLimit && | ||
limitingFactor === LIMITING_FACTOR.DROPDOWN; | ||
|
||
if (limitingFactor === LIMITING_FACTOR.QUERY && this.props.csv) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go straight to the test without nesting in describe. That's the approach we have been trying to use lately