Skip to content

Commit

Permalink
[#3256] - add tests for stats list page
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Kome committed Oct 23, 2019
1 parent e2ed9e8 commit deab96a
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dashboard/app/js/lib/components/stats/StatsLists.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class StatsList extends React.Component {
className="standardBtn newStats"
type="button"
onClick={this.props.goToExport}
data-testid="newStatsBtn"
>
Export stats
</button>
Expand Down
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);
});
});
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>
`;

0 comments on commit deab96a

Please sign in to comment.