-
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 stats list page
- Loading branch information
Marvin Kome
committed
Oct 23, 2019
1 parent
e2ed9e8
commit deab96a
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
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
58 changes: 58 additions & 0 deletions
58
Dashboard/app/js/lib/components/stats/__tests__/StatsLists.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,58 @@ | ||
import React from 'react'; | ||
import { render, cleanup, fireEvent } from '@testing-library/react'; | ||
import StatsList from '../StatsLists'; | ||
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('Stats Lists Tests', () => { | ||
afterEach(cleanup); | ||
|
||
const stats = [ | ||
{ | ||
id: 345598, | ||
name: 'Test export', | ||
startDate: '2019-10-01', | ||
endDate: '2019-10-11', | ||
status: 'Finished Error', | ||
}, | ||
]; | ||
|
||
const goToNewExports = jest.fn(); | ||
|
||
it('+++ renders snapshots', () => { | ||
const wrapper = render( | ||
<StatsList stats={stats} goToExport={goToNewExports} /> | ||
); | ||
|
||
expect(wrapper.container).toMatchSnapshot(); | ||
}); | ||
|
||
it('+++ goes to export page on button press', () => { | ||
const wrapper = render( | ||
<StatsList stats={stats} goToExport={goToNewExports} /> | ||
); | ||
|
||
// find and click on button | ||
const button = wrapper.getByTestId('newStatsBtn'); | ||
fireEvent.click(button); | ||
|
||
expect(goToNewExports).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
Dashboard/app/js/lib/components/stats/__tests__/__snapshots__/StatsLists.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,63 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Stats Lists Tests +++ renders snapshots 1`] = ` | ||
<div> | ||
<div | ||
id="stats-listing-page" | ||
> | ||
<div | ||
class="page-header" | ||
> | ||
<h2> | ||
Generated stats | ||
</h2> | ||
<button | ||
class="standardBtn newStats" | ||
data-testid="newStatsBtn" | ||
type="button" | ||
> | ||
Export stats | ||
</button> | ||
</div> | ||
<div | ||
class="main-page" | ||
> | ||
<div | ||
class="generated-stats" | ||
> | ||
<div | ||
class="generated-stat" | ||
> | ||
<div | ||
class="stats-details" | ||
> | ||
<span | ||
class="stat-icon" | ||
/> | ||
<div> | ||
<a | ||
href="/" | ||
> | ||
Test export | ||
</a> | ||
<span | ||
class="stat-date" | ||
> | ||
2019-10-01 | ||
- | ||
2019-10-11 | ||
Submissions | ||
</span> | ||
</div> | ||
</div> | ||
<p | ||
class="stats-status" | ||
> | ||
Finished Error | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |