Test: add test for ItemListItem and ItemListItemArchiveButton (#4391)
This commit is contained in:
parent
cb87cfd36e
commit
7ab10e709a
2 changed files with 46 additions and 26 deletions
|
|
@ -1,39 +1,57 @@
|
|||
import { h } from 'preact';
|
||||
import render from 'preact-render-to-json';
|
||||
import { shallow } from 'preact-render-spy';
|
||||
import { ItemListItem } from '../ItemListItem';
|
||||
|
||||
const historyItem = {
|
||||
article_path: '/article',
|
||||
article_title: 'Title',
|
||||
article_user: {
|
||||
username: 'bob',
|
||||
profile_image_90: 'https://dummyimage.com/90x90',
|
||||
name: 'Bob',
|
||||
},
|
||||
article_reading_time: 1,
|
||||
readable_visited_at: 'Jun 29',
|
||||
article_tags: ['discuss'],
|
||||
};
|
||||
|
||||
const item = {
|
||||
searchable_reactable_path: '/article',
|
||||
searchable_reactable_title: 'Title',
|
||||
reactable_user: {
|
||||
username: 'bob',
|
||||
profile_image_90: 'https://dummyimage.com/90x90',
|
||||
name: 'Bob',
|
||||
},
|
||||
reading_time: 1,
|
||||
reactable_published_date: 'Jun 29',
|
||||
reactable_tags: ['discuss'],
|
||||
};
|
||||
|
||||
describe('<ItemListItem />', () => {
|
||||
it('renders properly with a history item', () => {
|
||||
const item = {
|
||||
article_path: '/article',
|
||||
article_title: 'Title',
|
||||
article_user: {
|
||||
username: 'bob',
|
||||
profile_image_90: 'https://dummyimage.com/90x90',
|
||||
name: 'Bob',
|
||||
},
|
||||
article_reading_time: 1,
|
||||
readable_visited_at: 'Jun 29',
|
||||
article_tags: ['discuss'],
|
||||
};
|
||||
const tree = render(<ItemListItem item={item} />);
|
||||
const tree = render(<ItemListItem item={historyItem} />);
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('renders properly with a readinglist item', () => {
|
||||
const item = {
|
||||
searchable_reactable_path: '/article',
|
||||
searchable_reactable_title: 'Title',
|
||||
reactable_user: {
|
||||
username: 'bob',
|
||||
profile_image_90: 'https://dummyimage.com/90x90',
|
||||
name: 'Bob',
|
||||
},
|
||||
reading_time: 1,
|
||||
reactable_published_date: 'Jun 29',
|
||||
reactable_tags: ['discuss'],
|
||||
};
|
||||
const tree = render(<ItemListItem item={item} />);
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('renders with readingtime of 1 min if reading time is less than 1 min.', () => {
|
||||
const wrapper = shallow(<ItemListItem item={{...item, reading_time: 0.5 }} />);
|
||||
expect(wrapper.find('.item-user').text()).toContain('1 min read');
|
||||
});
|
||||
|
||||
it('renders with readingtime of 1 min if reading time is null.', () => {
|
||||
const wrapper = shallow(<ItemListItem item={{...item, reading_time: null }} />);
|
||||
expect(wrapper.find('.item-user').text()).toContain('1 min read');
|
||||
});
|
||||
|
||||
it('renders without any tags if the tags array is empty.', () => {
|
||||
const wrapper = shallow(<ItemListItem item={{...item, reactable_tags: [] }} />);
|
||||
expect(wrapper.find('.item-user').text()).toContain('1 min read');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ describe('<ItemListItemArchiveButton />', () => {
|
|||
<ItemListItemArchiveButton text="archive" onClick={onClick} />,
|
||||
);
|
||||
context.find('a').simulate('keyup', { key: 'Enter' });
|
||||
expect(onClick).toBeCalled();
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
context.find('a').simulate('keyup', { key: 'Space' });
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue