Skip to content

Commit

Permalink
[#3256] - update new stats page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Kome committed Nov 5, 2019
1 parent f40ca9f commit 0be8bd8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
25 changes: 17 additions & 8 deletions Dashboard/app/js/lib/components/stats/__tests__/NewStats.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,32 @@ afterAll(() => {
console.error = originalError;
});

describe('News Stats Tests', () => {
describe('New Stats Tests', () => {
afterEach(cleanup);

const generateReport = jest.fn();
const props = {
strings: {
generateStats: 'Generate form submission stats',
formTimeFrame: 'Form submission time frame',
startDate: 'Start date',
toDate: 'To date',
downloadStats: 'Download Stats',
},
generateReport: jest.fn(),
};

it('+++ renders snapshots', () => {
const wrapper = render(<NewStats generateReport={generateReport} />);
const wrapper = render(<NewStats {...props} />);

expect(wrapper.container).toMatchSnapshot();
});

it('+++ handles inputs and submit forms', () => {
const wrapper = render(<NewStats generateReport={generateReport} />);
const wrapper = render(<NewStats {...props} />);

// get start and end date input
const startDate = wrapper.getByLabelText('Start Date:');
const endDate = wrapper.getByLabelText('To Date:');
const startDate = wrapper.getByLabelText('Start date:');
const endDate = wrapper.getByLabelText('To date:');

// select date on inputs
fireEvent.change(startDate, { target: { value: '2019-10-01' } });
Expand All @@ -47,8 +56,8 @@ describe('News Stats Tests', () => {
fireEvent.click(wrapper.getByText('Download Stats'));

// expectations
expect(generateReport).toHaveBeenCalledTimes(1);
expect(generateReport).toHaveBeenCalledWith({
expect(props.generateReport).toHaveBeenCalledTimes(1);
expect(props.generateReport).toHaveBeenCalledWith({
// be called with ISO strings
startDate: '2019-10-01T00:00:00.000Z',
endDate: '2019-10-10T00:00:00.000Z',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`News Stats Tests +++ renders snapshots 1`] = `
exports[`New Stats Tests +++ renders snapshots 1`] = `
<div>
<div
id="stats-page"
Expand All @@ -18,7 +18,8 @@ exports[`News Stats Tests +++ renders snapshots 1`] = `
for="startDate"
>
<p>
Start Date:
Start date
:
</p>
<input
class="datePicker"
Expand All @@ -32,7 +33,8 @@ exports[`News Stats Tests +++ renders snapshots 1`] = `
for="endDate"
>
<p>
To Date:
To date
:
</p>
<input
class="datePicker"
Expand Down

0 comments on commit 0be8bd8

Please sign in to comment.