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

import { assert } from '~/test/utils';

import { LabeledSwitch } from './labeled-switch';
import { Switch } from './switch';

describe('Switch', () => {
  it('simulates press calls onToggle with true as initial value', () => {
    const onToggle = sinon.spy();
    const wrapper = shallow(<Switch value onToggle={onToggle} />);

    wrapper.find(TouchableWithoutFeedback).prop('onPress')(null);

    assert.calledOnceWithExactly(onToggle, false);
  });
  it('simulates press calls onToggle with false as initial value', () => {
    const onToggle = sinon.spy();
    const wrapper = shallow(<Switch value={false} onToggle={onToggle} />);

    wrapper.find(TouchableWithoutFeedback).prop('onPress')(null);

    assert.calledOnceWithExactly(onToggle, true);
  });
});

describe('LabeledSwitch', () => {
  it('simulates toggle calls onToggle', () => {
    const onToggle = sinon.spy();
    const wrapper = shallow(<LabeledSwitch onToggle={onToggle} />);

    wrapper.find(Switch).prop('onToggle')(true);

    assert.calledOnceWithExactly(onToggle, true);
  });
});
