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

@@ -22,7 +22,6 @@ import configureStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import fetchMock from 'fetch-mock';
import * as featureFlags from 'src/featureFlags';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import { styledMount as mount } from 'spec/helpers/theming';
@@ -38,10 +37,11 @@ const store = mockStore({});
const chartsInfoEndpoint = 'glob:*/api/v1/chart/_info*';
const chartssOwnersEndpoint = 'glob:*/api/v1/chart/related/owners*';
const chartsCreatedByEndpoint = 'glob:*/api/v1/chart/related/created_by*';
const chartsEndpoint = 'glob:*/api/v1/chart/?*';
const chartsEndpoint = 'glob:*/api/v1/chart/*';
const chartsVizTypesEndpoint = 'glob:*/api/v1/chart/viz_types';
const chartsDatasourcesEndpoint = 'glob:*/api/v1/chart/datasources';
const chartFavoriteStatusEndpoint = 'glob:*/api/v1/chart/favorite_status*';
const datasetEndpoint = 'glob:*/api/v1/dataset/*';
const mockCharts = [...new Array(3)].map((_, i) => ({
changed_on: new Date().toISOString(),
@@ -86,6 +86,8 @@ fetchMock.get(chartsDatasourcesEndpoint, {
count: 0,
});
fetchMock.get(datasetEndpoint, {});
global.URL.createObjectURL = jest.fn();
fetchMock.get('/thumbnail', { body: new Blob(), sendAsJson: false });
@@ -98,6 +100,7 @@ describe('ChartList', () => {
isFeatureEnabledMock.restore();
});
const mockedProps = {};
const wrapper = mount(
<Provider store={store}>
<ChartList {...mockedProps} user={mockUser} />
@@ -134,19 +137,22 @@ describe('ChartList', () => {
expect(wrapper.find(ListViewCard)).toExist();
});
it('renders a table view', () => {
it('renders a table view', async () => {
wrapper.find('[data-test="list-view"]').first().simulate('click');
await waitForComponentToPaint(wrapper);
expect(wrapper.find('table')).toExist();
});
it('edits', () => {
it('edits', async () => {
expect(wrapper.find(PropertiesModal)).not.toExist();
wrapper.find('[data-test="edit-alt"]').first().simulate('click');
await waitForComponentToPaint(wrapper);
expect(wrapper.find(PropertiesModal)).toExist();
});
it('delete', () => {
it('delete', async () => {
wrapper.find('[data-test="trash"]').first().simulate('click');
await waitForComponentToPaint(wrapper);
expect(wrapper.find(ConfirmStatusChange)).toExist();
});
});

View File

@@ -43,6 +43,7 @@ const dashboardCreatedByEndpoint =
const dashboardFavoriteStatusEndpoint =
'glob:*/api/v1/dashboard/favorite_status*';
const dashboardsEndpoint = 'glob:*/api/v1/dashboard/?*';
const dashboardEndpoint = 'glob:*/api/v1/dashboard/*';
const mockDashboards = [...new Array(3)].map((_, i) => ({
id: i,
@@ -54,7 +55,7 @@ const mockDashboards = [...new Array(3)].map((_, i) => ({
published: true,
changed_on_utc: new Date().toISOString(),
changed_on_delta_humanized: '5 minutes ago',
owners: [{ first_name: 'admin', last_name: 'admin_user' }],
owners: [{ id: 1, first_name: 'admin', last_name: 'admin_user' }],
thumbnail_url: '/thumbnail',
}));
@@ -80,6 +81,10 @@ fetchMock.get(dashboardsEndpoint, {
dashboard_count: 3,
});
fetchMock.get(dashboardEndpoint, {
result: mockDashboards[0],
});
global.URL.createObjectURL = jest.fn();
fetchMock.get('/thumbnail', { body: new Blob(), sendAsJson: false });
@@ -129,35 +134,40 @@ describe('DashboardList', () => {
expect(wrapper.find(ListViewCard)).toExist();
});
it('renders a table view', () => {
it('renders a table view', async () => {
wrapper.find('[data-test="list-view"]').first().simulate('click');
await waitForComponentToPaint(wrapper);
expect(wrapper.find('table')).toExist();
});
it('edits', () => {
it('edits', async () => {
expect(wrapper.find(PropertiesModal)).not.toExist();
wrapper.find('[data-test="edit-alt"]').first().simulate('click');
await waitForComponentToPaint(wrapper);
expect(wrapper.find(PropertiesModal)).toExist();
});
it('card view edits', () => {
it('card view edits', async () => {
wrapper.find('[data-test="edit-alt"]').last().simulate('click');
await waitForComponentToPaint(wrapper);
expect(wrapper.find(PropertiesModal)).toExist();
});
it('delete', () => {
it('delete', async () => {
wrapper
.find('[data-test="dashboard-list-trash-icon"]')
.first()
.simulate('click');
await waitForComponentToPaint(wrapper);
expect(wrapper.find(ConfirmStatusChange)).toExist();
});
it('card view delete', () => {
it('card view delete', async () => {
wrapper
.find('[data-test="dashboard-list-trash-icon"]')
.last()
.simulate('click');
await waitForComponentToPaint(wrapper);
expect(wrapper.find(ConfirmStatusChange)).toExist();
});
});

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: {