{"size": 1825, "ext": "js", "max_stars_repo_path": "tests/e2e/components/test-redux/components/ToggleProductButton/ToggleProductButton.spec.js", "max_stars_repo_name": "notonthehighstreet/toga", "max_stars_repo_stars_event_min_datetime": "2016-08-24T15:14:38.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-23T09:54:56.000Z", "max_issues_repo_path": "tests/e2e/components/test-redux/components/ToggleProductButton/ToggleProductButton.spec.js", "max_issues_repo_name": "notonthehighstreet/toga", "max_issues_repo_issues_event_min_datetime": "2016-08-24T14:45:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T22:27:40.000Z", "max_forks_repo_path": "tests/e2e/components/test-redux/components/ToggleProductButton/ToggleProductButton.spec.js", "max_forks_repo_name": "notonthehighstreet/toga", "max_forks_repo_forks_event_min_datetime": "2017-11-21T21:03:02.000Z", "max_forks_repo_forks_event_max_datetime": "2017-11-21T21:03:02.000Z"}
{"max_stars_count": 26, "max_issues_count": 153, "max_forks_count": 1, "avg_line_length": 33.1818181818, "max_line_length": 139, "alphanum_fraction": 0.6564383562}
import helper from '../../../../../../tests/helper';
import React from 'react';
import {shallow} from 'enzyme';
import ToggleProductButton from './ToggleProductButton';

const {expect, sandbox, chance} = helper;

describe('Toggle product button component', () => {
  beforeEach(() => {
    sandbox.reset();
  });
  it('clicking calls toggleProducts', () => {
    const listId = chance.word();
    const productCode = chance.natural();

    const toggleProductsSpy = sandbox.spy();
    const wrapper = shallow(
      <ToggleProductButton listId={listId} productCode={productCode} productRemoved={false} actions={{toggleProduct: toggleProductsSpy}} />
    );

    wrapper.simulate('click');
    expect(toggleProductsSpy.withArgs(
      {
        listId,
        productCode: productCode,
        productRemoved: false
      }, {
        event: 'toggleProduct',
        productCode: productCode,
        triggerSource: 'heart'
      }
    )).to.have.been.calledOnce;
  });

  it('renders active image when marked as favourite', () => {
    const listId = chance.word();
    const productCode = chance.natural();
    const wrapper = shallow(
      <ToggleProductButton listId={listId} productCode={productCode} productRemoved={false} actions={{}} />
    );

    expect(wrapper.hasClass('toga-toggle-product-button--active')).to.equal(true, 'expected the component to have \'active\' class');
  });

  it('renders inactive image when marked as removed', () => {
    const listId = chance.word();
    const productCode = chance.natural();
    const wrapper = shallow(
      <ToggleProductButton listId={listId} productCode={productCode} productRemoved={true} actions={{}} />
    );

    expect(wrapper.hasClass('toga-toggle-product-button--inactive')).to.equal(true, 'expected the component to have \'inactive\' class');
  });
});
