-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#3256] - add tests for exporting stats
- Loading branch information
Marvin Kome
committed
Oct 23, 2019
1 parent
deab96a
commit d34bc35
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
Dashboard/app/js/lib/components/stats/__tests__/NewStats.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
Dashboard/app/js/lib/components/stats/__tests__/__snapshots__/NewStats.test.jsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |