Skip to content

Commit

Permalink
[#3256] - add tests for exporting stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Kome committed Oct 23, 2019
1 parent deab96a commit d34bc35
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Dashboard/app/js/lib/components/stats/__tests__/NewStats.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import { render, cleanup, fireEvent } from '@testing-library/react';
import NewStats from '../NewStats';
import '@testing-library/jest-dom/extend-expect';

// https://github.com/testing-library/react-testing-library#suppressing-unnecessary-warnings-on-react-dom-168
// eslint-disable-next-line no-console
const originalError = console.error;
beforeAll(() => {
// eslint-disable-next-line no-console
console.error = (...args) => {
if (/supports * the "act"/.test(args[0])) {
return;
}
originalError.call(console, ...args);
};
});

afterAll(() => {
// eslint-disable-next-line no-console
console.error = originalError;
});

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

const generateReport = jest.fn();

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

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

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

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

// select date on inputs
fireEvent.change(startDate, { target: { value: '2019-10-01' } });
fireEvent.change(endDate, { target: { value: '2019-10-10' } });

// click on submit button
fireEvent.click(wrapper.getByText('Download Stats'));

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

exports[`News Stats Tests +++ renders snapshots 1`] = `
<div>
<div
id="stats-page"
>
<h2>
Generate form submission stats
</h2>
<p>
Form submission time frame
</p>
<div
class="date-picker"
>
<label
for="startDate"
>
<p>
Start Date:
</p>
<input
class="datePicker"
id="startDate"
style="width: 95%;"
type="date"
value=""
/>
</label>
<label
for="endDate"
>
<p>
To Date:
</p>
<input
class="datePicker"
id="endDate"
min=""
style="width: 95%;"
type="date"
value=""
/>
</label>
</div>
<button
class="standardBtn"
type="button"
>
Download Stats
</button>
</div>
</div>
`;

0 comments on commit d34bc35

Please sign in to comment.