diff --git a/app/components/HackerNewsList/HackerNewsList.scss b/app/components/HackerNewsList/HackerNewsList.scss index 454f320..afc075a 100644 --- a/app/components/HackerNewsList/HackerNewsList.scss +++ b/app/components/HackerNewsList/HackerNewsList.scss @@ -6,6 +6,10 @@ } } +.HackerNewsList__noti { + text-align: center; +} + .HackerNewsList__item { margin: 30px 0; } diff --git a/app/components/HackerNewsList/HackerNewsList.spec.jsx b/app/components/HackerNewsList/HackerNewsList.spec.jsx index 39d4545..54ae352 100644 --- a/app/components/HackerNewsList/HackerNewsList.spec.jsx +++ b/app/components/HackerNewsList/HackerNewsList.spec.jsx @@ -40,4 +40,9 @@ describe('', () => { const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); + + it('should have .HackerNewsList__noti when have no items', () => { + const wrapper = shallow(); + expect(wrapper.find('.HackerNewsList__noti')).toHaveLength(1); + }); }); diff --git a/app/components/HackerNewsList/HackerNewsList.stories.jsx b/app/components/HackerNewsList/HackerNewsList.stories.jsx index 6d6455a..cf1b07d 100644 --- a/app/components/HackerNewsList/HackerNewsList.stories.jsx +++ b/app/components/HackerNewsList/HackerNewsList.stories.jsx @@ -13,7 +13,9 @@ stories {story()} )) - .add('default', () => ( + .add('fetching data', () => ) + .add('no data', () => ) + .add('with data', () => ( should match snapshot when render default 1`] = ` className="HackerNewsList" > should match snapshot when render default 1`] = ` } } /> +

+ There are no items to show. +

`; diff --git a/app/components/HackerNewsList/index.jsx b/app/components/HackerNewsList/index.jsx index fdebf35..6b20bc8 100644 --- a/app/components/HackerNewsList/index.jsx +++ b/app/components/HackerNewsList/index.jsx @@ -9,20 +9,25 @@ import './HackerNewsList.scss'; const propTypes = { feeds: PropTypes.object, // eslint-disable-line react/forbid-prop-types + isFetching: PropTypes.bool, }; const defaultProps = { feeds: Immutable.List(), + isFetching: false, }; -function HackerNewsList({ feeds }) { +function HackerNewsList({ feeds, isFetching }) { + const haveNoItems = !isFetching && feeds.size === 0; + return (
    - {feeds.map((feed, index) => ( + {haveNoItems &&

    There are no items to show.

    } + {!isFetching && feeds.map((feed, index) => (
  • {index + 1} diff --git a/app/components/Pagination/Pagination.spec.jsx b/app/components/Pagination/Pagination.spec.jsx index a71cce2..6774da5 100644 --- a/app/components/Pagination/Pagination.spec.jsx +++ b/app/components/Pagination/Pagination.spec.jsx @@ -9,6 +9,18 @@ describe('', () => { expect(wrapper).toMatchSnapshot(); }); + it('should have .Pagination__button--disabled when props.currentPage === 1', () => { + const wrapper = shallow(); + const button = wrapper.find('.Pagination__button--disabled'); + expect(button.props()['data-button']).toBe('prev'); + }); + + it('should have .Pagination__button--disabled when props.currentPage === 10', () => { + const wrapper = shallow(); + const button = wrapper.find('.Pagination__button--disabled'); + expect(button.props()['data-button']).toBe('next'); + }); + it('should calls onPaginate with currentPage - 1 when simulate prev button click event', () => { const currentPage = 3; const onPaginate = jest.fn(); @@ -20,8 +32,8 @@ describe('', () => { /> )); wrapper.find('.Pagination__button').at(0).simulate('click'); - expect(onPaginate.mock.calls.length).toBe(1); - expect(onPaginate.mock.calls[0]).toEqual([currentPage - 1]); + expect(onPaginate).toHaveBeenCalledTimes(1); + expect(onPaginate).toHaveBeenCalledWith(currentPage - 1); }); it('should calls onPaginate with currentPage + 1 when simulate next button click event', () => { @@ -35,7 +47,7 @@ describe('', () => { /> )); wrapper.find('.Pagination__button').at(1).simulate('click'); - expect(onPaginate.mock.calls.length).toBe(1); - expect(onPaginate.mock.calls[0]).toEqual([currentPage + 1]); + expect(onPaginate).toHaveBeenCalledTimes(1); + expect(onPaginate).toHaveBeenCalledWith(currentPage + 1); }); }); diff --git a/app/components/Pagination/__snapshots__/Pagination.spec.jsx.snap b/app/components/Pagination/__snapshots__/Pagination.spec.jsx.snap index f439d37..b0d4e2d 100644 --- a/app/components/Pagination/__snapshots__/Pagination.spec.jsx.snap +++ b/app/components/Pagination/__snapshots__/Pagination.spec.jsx.snap @@ -9,6 +9,7 @@ exports[` should match snapshot when render default 1`] = ` > + 1 + / 10 + {currentPage} / 10 {' '}