import { mount } from '@vue/test-utils';
import BmsInputCheckboxCaption from './BmsInputCheckboxCaption.vue';
import { field } from '@/plugins/field';

const factory = (props: any) => {
  return mount(BmsInputCheckboxCaption, {
    props,
    global: {
      plugins: [field],
    },
  });
};

describe('BmsInputCheckboxCaption', () => {
  it('should return an array with element if element is clicked and model is an array', async () => {
    const wrapper = factory({ modelValue: [], value: 'toto', name: 'name' });
    await wrapper.trigger('click');
    expect(wrapper.emitted()['update:modelValue'][0]).toEqual([['toto']]);
  });
  it('should return an array without element if element is clicked and model is an array', async () => {
    const wrapper = factory({
      modelValue: ['toto'],
      value: 'toto',
      name: 'name',
    });
    await wrapper.trigger('click');
    expect(wrapper.emitted()['update:modelValue'][0]).toEqual([[]]);
  });
  it('should return a boolean true if model is a boolean', async () => {
    const wrapper = factory({
      modelValue: false,
      name: 'name',
    });
    await wrapper.trigger('click');
    expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]);
  });
  it('should return a boolean false if model is a boolean', async () => {
    const wrapper = factory({
      modelValue: true,
      name: 'name',
    });
    await wrapper.trigger('click');
    expect(wrapper.emitted()['update:modelValue'][0]).toEqual([false]);
  });
});
