2018-09-03 07:54:45 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
import fetch from 'node-fetch';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { TableCard } from '@woocommerce/components';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-09-03 15:25:38 +00:00
|
|
|
import { RevenueReport } from '../';
|
2018-09-03 07:54:45 +00:00
|
|
|
import mockData from '../__mocks__/mock-data';
|
|
|
|
import mockCSV from '../__mocks__/mock-csv';
|
|
|
|
import { downloadCSVFile } from 'lib/csv';
|
|
|
|
|
|
|
|
jest.mock( 'lib/csv', () => ( {
|
|
|
|
...require.requireActual( 'lib/csv' ),
|
|
|
|
downloadCSVFile: jest.fn(),
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
window.fetch = fetch;
|
|
|
|
|
|
|
|
describe( 'RevenueReport', () => {
|
|
|
|
test( 'should save CSV when clicking on download', () => {
|
|
|
|
global.Blob = ( content, options ) => ( { content, options } );
|
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
const primaryData = {
|
|
|
|
data: mockData,
|
2018-10-10 13:57:16 +00:00
|
|
|
totalResults: 7,
|
|
|
|
totalPages: 1,
|
2018-09-03 15:25:38 +00:00
|
|
|
};
|
|
|
|
|
2018-09-03 07:54:45 +00:00
|
|
|
const revenueReport = shallow(
|
2018-09-03 15:25:38 +00:00
|
|
|
<RevenueReport
|
|
|
|
params={ { report: 'revenue' } }
|
2018-10-10 13:57:16 +00:00
|
|
|
path="/analytics/revenue"
|
|
|
|
query={ {} }
|
2018-09-03 15:25:38 +00:00
|
|
|
primaryData={ primaryData }
|
2018-10-10 13:57:16 +00:00
|
|
|
tableData={ primaryData }
|
2018-09-03 15:25:38 +00:00
|
|
|
secondaryData={ primaryData }
|
|
|
|
/>
|
2018-09-03 07:54:45 +00:00
|
|
|
);
|
2018-09-03 15:25:38 +00:00
|
|
|
|
2018-09-03 07:54:45 +00:00
|
|
|
const tableCard = revenueReport.find( TableCard );
|
|
|
|
tableCard.props().onClickDownload();
|
|
|
|
|
|
|
|
expect( downloadCSVFile ).toHaveBeenCalledWith(
|
2018-10-10 13:57:16 +00:00
|
|
|
'revenue-' + moment().format( 'YYYY-MM-DD' ) + '.csv',
|
2018-09-03 07:54:45 +00:00
|
|
|
mockCSV
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|