Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Sep 24, 2021
1 parent 310bccb commit 902e57f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ describe('PropertiesModal', () => {
const wrapper = setup();
const modalInstance = wrapper.find('PropertiesModal').instance();
const spy = jest.spyOn(modalInstance, 'updateFormState');
modalInstance.onOwnersChange('foo');
expect(spy).toHaveBeenCalledWith('owners', 'foo');
const newOwners = [{ value: 1, label: 'foo' }];
modalInstance.onOwnersChange(newOwners);
expect(spy).toHaveBeenCalledWith('owners', newOwners);
});
});
describe('onMetadataChange', () => {
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Alert from 'src/components/Alert';
import ProgressBar from 'src/components/ProgressBar';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock from 'fetch-mock';
import FilterableTable from 'src/components/FilterableTable/FilterableTable';
import ExploreResultsButton from 'src/SqlLab/components/ExploreResultsButton';
import ResultSet from 'src/SqlLab/components/ResultSet';
Expand Down Expand Up @@ -80,6 +81,7 @@ const newProps = {
},
},
};
fetchMock.get('glob:*/api/v1/dataset?*', { result: [] });

test('is valid', () => {
expect(React.isValidElement(<ResultSet {...mockedProps} />)).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ const mockedProps = {
const middlewares = [thunk];
const mockStore = configureStore(middlewares);
const store = mockStore(initialState);
const DATABASE_ENDPOINT = 'glob:*/api/v1/database/?*';
fetchMock.get(DATABASE_ENDPOINT, []);
fetchMock.get('glob:*/api/v1/database/*/schemas/?*', { result: [] });
describe('SqlEditorLeftBar', () => {
let wrapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('AlteredSliceTag', () => {
const th = getTableWrapperFromModalBody(modalBody).find('th');
expect(th).toHaveLength(3);
['Control', 'Before', 'After'].forEach(async (v, i) => {
await expect(th.find('span').get(i).props.children[0]).toBe(v);
await expect(th.at(i).find('span').get(0).props.children[0]).toBe(v);
});
});

Expand Down
36 changes: 19 additions & 17 deletions superset-frontend/src/dashboard/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import sinon from 'sinon';
import fetchMock from 'fetch-mock';
import * as actions from 'src/reports/actions/reports';
import * as featureFlags from 'src/featureFlags';
import { ReportObject } from 'src/components/ReportModal';
import mockState from 'spec/fixtures/mockStateWithoutUser';
import { HeaderProps } from './types';
import Header from '.';
Expand Down Expand Up @@ -345,24 +344,27 @@ describe('Email Report Modal', () => {
render(setup(mockedProps), { useRedux: true });

const reportValues = {
active: true,
creation_method: 'dashboards',
crontab: '0 12 * * 1',
dashboard: mockedProps.dashboardInfo.id,
name: 'Weekly Report',
owners: [mockedProps.user.userId],
recipients: [
{
recipient_config_json: {
target: mockedProps.user.email,
id: 1,
result: {
active: true,
creation_method: 'dashboards',
crontab: '0 12 * * 1',
dashboard: mockedProps.dashboardInfo.id,
name: 'Weekly Report',
owners: [mockedProps.user.userId],
recipients: [
{
recipient_config_json: {
target: mockedProps.user.email,
},
type: 'Email',
},
type: 'Email',
},
],
type: 'Report',
],
type: 'Report',
},
};
// This is needed to structure the reportValues to match the fetchMock return
const stringyReportValues = `{"active":true,"creation_method":"dashboards","crontab":"0 12 * * 1","dashboard":${mockedProps.dashboardInfo.id},"name":"Weekly Report","owners":[${mockedProps.user.userId}],"recipients":[{"recipient_config_json":{"target":"${mockedProps.user.email}"},"type":"Email"}],"type":"Report"}`;
const stringyReportValues = `{"id":1,"result":{"active":true,"creation_method":"dashboards","crontab":"0 12 * * 1","dashboard":${mockedProps.dashboardInfo.id},"name":"Weekly Report","owners":[${mockedProps.user.userId}],"recipients":[{"recipient_config_json":{"target":"${mockedProps.user.email}"},"type":"Email"}],"type":"Report"}}`;
// Watch for report POST
fetchMock.post(REPORT_ENDPOINT, reportValues);

Expand All @@ -380,7 +382,7 @@ describe('Email Report Modal', () => {

// Mock addReport from Redux
const makeRequest = () => {
const request = actions.addReport(reportValues as ReportObject);
const request = actions.addReport(reportValues);
return request(dispatch);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const dbProps = {
const DATABASE_FETCH_ENDPOINT = 'glob:*/api/v1/database/10';
// const DATABASE_POST_ENDPOINT = 'glob:*/api/v1/database/';
const AVAILABLE_DB_ENDPOINT = 'glob:*/api/v1/database/available*';
const VALIDATE_PARAMS_ENDPOINT = 'glob:*/api/v1/database/validate_parameters*';

fetchMock.config.overwriteRoutes = true;
fetchMock.get(DATABASE_FETCH_ENDPOINT, {
result: {
Expand Down Expand Up @@ -194,6 +196,9 @@ fetchMock.mock(AVAILABLE_DB_ENDPOINT, {
},
],
});
fetchMock.post(VALIDATE_PARAMS_ENDPOINT, {
message: 'OK',
});

describe('DatabaseModal', () => {
const renderAndWait = async () => {
Expand Down

0 comments on commit 902e57f

Please sign in to comment.