MetaPhase-Consulting/State-TalentMAP

View on GitHub
src/Containers/HomePage/HomePage.test.jsx

Summary

Maintainability
A
0 mins
Test Coverage
import { shallow } from 'enzyme';
import sinon from 'sinon';
import HomePage from './HomePage';
import { DEFAULT_HOME_PAGE_POSITIONS } from '../../Constants/DefaultProps';
import bidListObject from '../../__mocks__/bidListObject';

describe('HomePageComponent', () => {
  const items = [{
    item: { title: 'title', selectionRef: 'ref' },
    data: [{ isSelected: true }],
  },
  {
    item: { title: 'Region', selectionRef: 'ref2' },
    data: [{ isSelected: false }],
  },
  ];

  it('is defined', () => {
    const wrapper = shallow(<HomePage
      filters={items}
      onNavigateTo={() => {}}
      homePagePositions={DEFAULT_HOME_PAGE_POSITIONS}
      bidList={bidListObject.results}
    />);
    expect(wrapper).toBeDefined();
  });

  it('can receive props', () => {
    const wrapper = shallow(<HomePage
      filters={items}
      onNavigateTo={() => {}}
      homePagePositions={DEFAULT_HOME_PAGE_POSITIONS}
      bidList={bidListObject.results}
    />);
    expect(wrapper.instance().props.filters[0].item.title).toBe(items[0].item.title);
  });

  it('can call the onNavigateTo function', () => {
    const spy = sinon.spy();
    const wrapper = shallow(<HomePage
      filters={items}
      onNavigateTo={spy}
      homePagePositions={DEFAULT_HOME_PAGE_POSITIONS}
      bidList={bidListObject.results}
    />);
    wrapper.instance().props.onNavigateTo();
    sinon.assert.calledOnce(spy);
  });
});