Skip to content

Commit

Permalink
test: Fixes act errors in ReportModal test (#21420)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Sep 9, 2022
1 parent c3527da commit 741d1d7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions superset-frontend/src/components/ReportModal/ReportModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as React from 'react';
import userEvent from '@testing-library/user-event';
import sinon from 'sinon';
import fetchMock from 'fetch-mock';
import { render, screen } from 'spec/helpers/testing-library';
import { render, screen, waitFor } from 'spec/helpers/testing-library';
import * as featureFlags from 'src/featureFlags';
import * as actions from 'src/reports/actions/reports';
import { FeatureFlag } from '@superset-ui/core';
Expand All @@ -33,6 +33,8 @@ fetchMock.get(REPORT_ENDPOINT, {});

const NOOP = () => {};

jest.mock('src/components/Icons/Icon', () => () => <span />);

const defaultProps = {
addDangerToast: NOOP,
addSuccessToast: NOOP,
Expand Down Expand Up @@ -156,24 +158,23 @@ describe('Email Report Modal', () => {

// Click "Add" button to create a new email report
const addButton = screen.getByRole('button', { name: /add/i });
userEvent.click(addButton);
await waitFor(() => userEvent.click(addButton));

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

return makeRequest().then(() => {
// 🐞 ----- There are 2 POST calls at this point ----- 🐞
await makeRequest();

// 🐞 ----- There are 2 POST calls at this point ----- 🐞

// addReport's mocked POST return should match the mocked values
expect(fetchMock.lastOptions()?.body).toEqual(stringyReportValues);
// Dispatch should be called once for addReport
expect(dispatch.callCount).toBe(2);
const reportCalls = fetchMock.calls(REPORT_ENDPOINT);
expect(reportCalls).toHaveLength(2);
});
// addReport's mocked POST return should match the mocked values
expect(fetchMock.lastOptions()?.body).toEqual(stringyReportValues);
expect(dispatch.callCount).toBe(2);
const reportCalls = fetchMock.calls(REPORT_ENDPOINT);
expect(reportCalls).toHaveLength(2);
});
});
});

0 comments on commit 741d1d7

Please sign in to comment.