import { mount } from '@vue/test-utils';
import Checkbox from '@/components/ui/BaseInput.vue';

describe('Checkbox.vue', () => {
  it('should display the provided props', async () => {
    const props = {
      label: 'Lonely label',
      checked: false,
      item: null,
    };
    const wrapper = mount(Checkbox, {
      props,
    });

    const input = wrapper.find('[data-cy="base-input-input"]');
    const label = wrapper.find('[data-cy="base-input-label"]');

    expect(input.element.checked).toEqual(props.checked);
    expect(label.element.textContent).toEqual(props.label);
  });

  it.skip('should emit updated value', async () => {
    // todo: failed after update from jest@25 to jest@27, probably already at jest@26
    const labelText = 'Lonely label';
    const item = { name: 'bla' };
    const props = {
      label: labelText,
      checked: false,
      item,
    };
    const wrapper = mount(Checkbox, {
      props,
    });

    wrapper.element.click();

    expect(wrapper.emitted()['input'][0]).toEqual([!props.checked, item]);
  });
});
