Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Dec 9, 2024
1 parent 9647ced commit 6687af3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import { Store } from 'redux';
import thunk from 'redux-thunk';
import fetchMock from 'fetch-mock';
import ResultSet from 'src/SqlLab/components/ResultSet';
import ErrorMessageWithStackTrace from 'src/components/ErrorMessage/ErrorMessageWithStackTrace';
import {
cachedQuery,
failedQueryWithErrorMessage,
failedQueryWithErrors,
queries,
runningQuery,
Expand All @@ -41,6 +41,11 @@ import {
failedQueryWithFrontendTimeoutErrors,
} from 'src/SqlLab/fixtures';

jest.mock(
'src/components/ErrorMessage/ErrorMessageWithStackTrace',
() => () => <div data-test="error-message">Error</div>,
);

const mockedProps = {
cache: true,
queryId: queries[0].id,
Expand Down Expand Up @@ -93,15 +98,6 @@ const cachedQueryState = {
},
},
};
const failedQueryWithErrorMessageState = {
...initialState,
sqlLab: {
...initialState.sqlLab,
queries: {
[failedQueryWithErrorMessage.id]: failedQueryWithErrorMessage,
},
},
};
const failedQueryWithErrorsState = {
...initialState,
sqlLab: {
Expand Down Expand Up @@ -314,26 +310,17 @@ describe('ResultSet', () => {
expect(getByText('fetching')).toBeInTheDocument();
});

test('should render a failed query with an error message', async () => {
await waitFor(() => {
setup(
{ ...mockedProps, queryId: failedQueryWithErrorMessage.id },
mockStore(failedQueryWithErrorMessageState),
);
});

expect(screen.getByText('Database error')).toBeInTheDocument();
expect(screen.getByText('Something went wrong')).toBeInTheDocument();
});

test('should render a failed query with an errors object', async () => {
const { errors } = failedQueryWithErrors;

await waitFor(() => {
setup(
{ ...mockedProps, queryId: failedQueryWithErrors.id },
mockStore(failedQueryWithErrorsState),
);
});
expect(screen.getByText('Database error')).toBeInTheDocument();
const errorMessages = screen.getAllByTestId('error-message');
expect(errorMessages).toHaveLength(errors.length);
});

test('should render a timeout error with a retrial button', async () => {
Expand Down
6 changes: 6 additions & 0 deletions superset-frontend/src/SqlLab/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ export const failedQueryWithErrors = {
level: 'error',
extra: null,
},
{
message: 'Something else wrong',
error_type: 'TEST_ERROR',
level: 'error',
extra: null,
},
],
id: 'ryhMUZCGb',
progress: 0,
Expand Down

0 comments on commit 6687af3

Please sign in to comment.