From 7ab10e709a1142f8b6963115af482b84e05d117b Mon Sep 17 00:00:00 2001 From: Karin Hendrikse <30577427+khendrikse@users.noreply.github.com> Date: Mon, 14 Oct 2019 14:54:07 +0200 Subject: [PATCH] Test: add test for ItemListItem and ItemListItemArchiveButton (#4391) --- .../ItemList/__tests__/ItemListItem.test.jsx | 68 ++++++++++++------- .../ItemListItemArchiveButton.test.jsx | 4 +- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/app/javascript/src/components/ItemList/__tests__/ItemListItem.test.jsx b/app/javascript/src/components/ItemList/__tests__/ItemListItem.test.jsx index dfe384c4f..f3f090700 100644 --- a/app/javascript/src/components/ItemList/__tests__/ItemListItem.test.jsx +++ b/app/javascript/src/components/ItemList/__tests__/ItemListItem.test.jsx @@ -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('', () => { 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(); + const tree = render(); 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(); expect(tree).toMatchSnapshot(); }); + + it('renders with readingtime of 1 min if reading time is less than 1 min.', () => { + const wrapper = shallow(); + 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(); + expect(wrapper.find('.item-user').text()).toContain('1 min read'); + }); + + it('renders without any tags if the tags array is empty.', () => { + const wrapper = shallow(); + expect(wrapper.find('.item-user').text()).toContain('1 min read'); + }); }); diff --git a/app/javascript/src/components/ItemList/__tests__/ItemListItemArchiveButton.test.jsx b/app/javascript/src/components/ItemList/__tests__/ItemListItemArchiveButton.test.jsx index 74a9ba375..fd8046174 100644 --- a/app/javascript/src/components/ItemList/__tests__/ItemListItemArchiveButton.test.jsx +++ b/app/javascript/src/components/ItemList/__tests__/ItemListItemArchiveButton.test.jsx @@ -15,6 +15,8 @@ describe('', () => { , ); 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); }); });