Skip to content

Commit

Permalink
fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Nov 30, 2021
1 parent dc843ca commit aae37fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
23 changes: 23 additions & 0 deletions superset-frontend/src/components/TableLoader/TableLoader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fetchMock.get('glob:*/api/v1/mock', [
const defaultProps: TableLoaderProps = {
dataEndpoint: '/api/v1/mock',
addDangerToast: jest.fn(),
noDataText: 'No data available',
};

function renderWithProps(props: TableLoaderProps = defaultProps) {
Expand Down Expand Up @@ -83,6 +84,28 @@ test('renders with mutator', async () => {
expect(await screen.findAllByRole('heading', { level: 4 })).toHaveLength(2);
});

test('renders empty message', async () => {
fetchMock.mock('glob:*/api/v1/mock', [], {
overwriteRoutes: true,
});

renderWithProps();

expect(await screen.findByText('No data available')).toBeInTheDocument();
});

test('renders blocked message', async () => {
fetchMock.mock('glob:*/api/v1/mock', 403, {
overwriteRoutes: true,
});

renderWithProps();

expect(
await screen.findByText('Access to user activity data is restricted'),
).toBeInTheDocument();
});

test('renders error message', async () => {
fetchMock.mock('glob:*/api/v1/mock', 500, {
overwriteRoutes: true,
Expand Down
14 changes: 6 additions & 8 deletions superset-frontend/src/components/TableLoader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ const TableLoader = (props: TableLoaderProps) => {
})
.catch(response => {
setIsLoading(false);
response.json().then(() => {
if (response.status === 403) {
setIsBlocked(true);
} else {
setIsBlocked(false);
props.addDangerToast(t('An error occurred'));
}
});
if (response.status === 403) {
setIsBlocked(true);
} else {
setIsBlocked(false);
props.addDangerToast(t('An error occurred'));
}
});
}
}, [props]);
Expand Down

0 comments on commit aae37fa

Please sign in to comment.