File size: 1,972 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/**
* Test the repo list item
*/
import React from 'react';
import { getByText, render } from 'react-testing-library';
import { IntlProvider } from 'react-intl';
import { RepoListItem } from '../index';
const renderComponent = (props = {}) =>
render(
<IntlProvider locale="en">
<RepoListItem {...props} />
</IntlProvider>,
);
describe('<RepoListItem />', () => {
let item;
// Before each test reset the item data for safety
beforeEach(() => {
item = {
owner: {
login: 'mxstbr',
},
html_url: 'https://github.com/react-boilerplate/react-boilerplate',
name: 'react-boilerplate',
open_issues_count: 20,
full_name: 'react-boilerplate/react-boilerplate',
};
});
it('should render a ListItem', () => {
const { container } = renderComponent({ item });
expect(container.firstChild).toMatchSnapshot();
});
it('should not render the current username', () => {
const { queryByText } = renderComponent({
item,
currentUser: item.owner.login,
});
expect(queryByText(item.owner.login)).toBeNull();
});
it('should render usernames that are not the current one', () => {
const { container } = renderComponent({
item,
currentUser: 'nikgraf',
});
expect(
getByText(container, content => content.startsWith(item.owner.login)),
).not.toBeNull();
});
it('should render the repo name', () => {
const { container } = renderComponent({ item });
expect(
getByText(container, content => content.endsWith(item.name)),
).not.toBeNull();
});
it('should render the issue count', () => {
const { container } = renderComponent({ item });
expect(
getByText(container, item.open_issues_count.toString(10)),
).not.toBeNull();
});
it('should render the IssueIcon', () => {
const { container } = renderComponent({ item });
expect(container.querySelector('svg')).not.toBeNull();
});
});
|