import { shallow } from 'enzyme';
import * as React from 'react';
import sinon from 'sinon';

import { modelFixtures } from '~/test/fixtures';
import { assert, noop } from '~/test/utils';

import { PackageListItem } from './package-list-item';
import { renderPackageListItem } from './package-list-item.render';

describe('PackageListItem', () => {
  describe('renders', function () {
    it('can be pressed', async function () {
      const onPressSpy = sinon.spy();
      const wrapper = shallow(
        <PackageListItem barcode={'PACKAGE_BARCODE'} bulletPreset="success" onPress={onPressSpy} />,
      );

      wrapper.props().onPress();

      assert.calledOnceWithExactly(onPressSpy, 'PACKAGE_BARCODE');
    });
  });
});

describe('renderPackageListItem', function () {
  const pckg = modelFixtures.Space.packages[0];

  it.each([['paired'], ['unpaired'], ['wrong-space']])('with %s bullet', function (state) {
    const wrapper = shallow(renderPackageListItem(noop)({ ...pckg, state }, 0));
    expect(wrapper).toMatchSnapshot();
  });

  it('can be pressed', function () {
    const onPressSpy = sinon.spy();
    const dataItem = renderPackageListItem(onPressSpy)(pckg, 0);

    dataItem.props.onPress();

    assert.calledOnce(onPressSpy);
  });
});
