[SPEC] Add tests for sidebarUser component (#4301) [ci skip]

This commit is contained in:
Karin Hendrikse 2019-10-07 22:01:59 +02:00 committed by Mac Siri
parent e6b1d6d882
commit a9adeee11f
2 changed files with 80 additions and 0 deletions

View file

@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<SidebarUser /> renders properly 1`] = `
<div
class="widget-list-item__suggestions"
>
<div
class="widget-list-item__content"
>
<a
href="/undefined"
>
<img
class="widget-list-item__profile-pic"
/>
</a>
<button
class="widget-list-item__follow-button"
id="widget-list-item__follow-button-undefined"
onClick={[Function]}
type="button"
>
+ FOLLOW
</button>
</div>
<hr />
</div>
`;

View file

@ -0,0 +1,52 @@
import { h } from 'preact';
import { shallow } from 'preact-render-spy';
import render from 'preact-render-to-json';
import SidebarUser from '../sidebarUser';
const user = {
id: 1234
}
const followUser = jest.fn();
const renderedSideBar = props => shallow(
<SidebarUser
key={user.id}
user={user}
followUser={followUser}
index={0}
{...props}
/>
)
describe('<SidebarUser />', () => {
it('renders properly', () => {
const tree = render(
<SidebarUser
key={user.id}
user={user}
followUser={followUser}
index={0}
/>);
expect(tree).toMatchSnapshot();
});
it('triggers the onClick', () => {
renderedSideBar().find('.widget-list-item__follow-button').simulate('click');
expect(followUser).toHaveBeenCalled();
});
it('shows if the user is followed or not', () => {
expect(renderedSideBar({ user: { following: true } }).contains('✓ FOLLOWING')).toBe(true);
expect(renderedSideBar({ user: { following: false } }).contains('+ FOLLOW')).toBe(true);
});
it('shows a <br /> if the index equals 2', () => {
expect(renderedSideBar({ index: 2 }).find(<br />).length > 0).toBe(true);
expect(renderedSideBar({ index: 2 }).find(<hr />).length > 0).toBe(false);
});
it('shows a <hr /> if the index differs from 2', () => {
expect(renderedSideBar({ index: 1 }).find(<hr />).length > 0).toBe(true);
expect(renderedSideBar({ index: 3 }).find(<br />).length > 0).toBe(false);
});
});