Fix tests errors and warnings - iteration 6 (#12212) (#12227)

This commit is contained in:
Michael S. Molina
2021-01-26 04:34:05 -03:00
committed by GitHub
parent 4d04565c9a
commit 20503f92ae
10 changed files with 92 additions and 69 deletions

View File

@@ -24,6 +24,7 @@ import configureStore from 'redux-mock-store';
import { act } from 'react-dom/test-utils';
import ChartTable from 'src/views/CRUD/welcome/ChartTable';
import { ReactWrapper } from 'enzyme';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
const mockStore = configureStore([thunk]);
@@ -31,6 +32,7 @@ const store = mockStore({});
const chartsEndpoint = 'glob:*/api/v1/chart/?*';
const chartsInfoEndpoint = 'glob:*/api/v1/chart/_info*';
const chartFavoriteStatusEndpoint = 'glob:*/api/v1/chart/favorite_status*';
const mockCharts = [...new Array(3)].map((_, i) => ({
changed_on_utc: new Date().toISOString(),
@@ -51,13 +53,26 @@ fetchMock.get(chartsInfoEndpoint, {
permissions: ['can_add', 'can_edit', 'can_delete'],
});
fetchMock.get(chartFavoriteStatusEndpoint, {
result: [],
});
describe('ChartTable', () => {
const mockedProps = {
user: {
userId: '2',
},
};
const wrapper = mount(<ChartTable store={store} {...mockedProps} />);
let wrapper: ReactWrapper;
beforeEach(async () => {
act(() => {
wrapper = mount(<ChartTable store={store} {...mockedProps} />);
});
await waitForComponentToPaint(wrapper);
});
it('renders', () => {
expect(wrapper.find(ChartTable)).toExist();
});
@@ -74,9 +89,7 @@ describe('ChartTable', () => {
expect(wrapper.find('ChartCard')).toExist();
});
it('display EmptyState if there is no data', () => {
fetchMock.resetHistory();
const wrapper = mount(<ChartTable store={store} {...mockedProps} />);
it('display EmptyState if there is no data', async () => {
expect(wrapper.find('EmptyState')).toExist();
});
});

View File

@@ -59,7 +59,7 @@ describe('DashboardTable', () => {
},
mine: mockDashboards,
};
const wrapper = mount(<DashboardTable store={store} {...dashboardProps} />);
let wrapper = mount(<DashboardTable store={store} {...dashboardProps} />);
beforeAll(async () => {
await waitForComponentToPaint(wrapper);
@@ -87,15 +87,18 @@ describe('DashboardTable', () => {
expect(wrapper.find(DashboardCard)).toExist();
});
it('display EmptyState if there is no data', () => {
const wrapper = mount(
<DashboardTable
dashboardFilter="Mine"
user={{ userId: '2' }}
mine={[]}
store={store}
/>,
);
it('display EmptyState if there is no data', async () => {
await act(async () => {
wrapper = mount(
<DashboardTable
dashboardFilter="Mine"
user={{ userId: '2' }}
mine={[]}
store={store}
/>,
);
});
expect(wrapper.find('EmptyState')).toExist();
});
});

View File

@@ -32,7 +32,7 @@ const mockStore = configureStore([thunk]);
const store = mockStore({});
const queriesEndpoint = 'glob:*/api/v1/saved_query/?*';
const savedQueriesInfo = 'glob:*/api/v1/saved_query/_info';
const savedQueriesInfo = 'glob:*/api/v1/saved_query/_info*';
const mockqueries = [...new Array(3)].map((_, i) => ({
created_by: {