import { newSpecPage } from '@stencil/core/testing';
import { BsCheckbox } from '../bs-checkbox';
import { faker } from '@faker-js/faker';
const id = faker.datatype.uuid();
const name = faker.random.word();
const label = faker.random.word();
describe('bs-checkbox', () => {
  it('passes expected attributes', async () => {
    const page = await newSpecPage({
      components: [BsCheckbox],
      html: `<bs-checkbox
        input-id="${id}"
        name="${name}"
        form="asdf"
      ></bs-checkbox>`,
    });
    let component = page.root;
    let input = component.querySelector('input');
    expect(input.getAttribute('id')).toBe(id);
    expect(input.getAttribute('name')).toBe(name);
  });
  it('handles checked prop', async () => {
    const page = await newSpecPage({
      components: [BsCheckbox],
      html: `<bs-checkbox checked="true"></bs-checkbox>`,
    });
    const component = page.root;
    const input = component.querySelector('input');
    expect(input).toHaveProperty('checked', true);
    component.checked = false;
    await page.waitForChanges();
    expect(input).toHaveProperty('checked', false);
  });
  it('handles checkedPartially prop', async () => {
    const page = await newSpecPage({
      components: [BsCheckbox],
      html: `<bs-checkbox></bs-checkbox>`,
    });
    const component = page.root;
    const input = component.querySelector('input');
    component.checkedPartially = true;
    await page.waitForChanges();
    expect(input.indeterminate).toBe(true);
    component.checkedPartially = false;
    await page.waitForChanges();
    expect(input.indeterminate).toBe(false);
    component.checked = true;
    component.checkedPartially = true;
    await page.waitForChanges();
    expect(input.indeterminate).toBe(false);
  });
  it('handles error prop', async () => {
    const page = await newSpecPage({
      components: [BsCheckbox],
      html: `<bs-checkbox error="true"></bs-checkbox>`,
    });
    const component = page.root;
    const input = component.querySelector('input');
    expect(input).toHaveAttribute('data-error');
    component.error = false;
    await page.waitForChanges();
    expect(input).not.toHaveAttribute('data-error');
  });
  it('handles disabled prop', async () => {
    const page = await newSpecPage({
      components: [BsCheckbox],
      html: `<bs-checkbox disabled="true"></bs-checkbox>`,
    });
    const component = page.root;
    const input = component.querySelector('input');
    expect(input).toHaveAttribute('disabled');
    component.disabled = false;
    await page.waitForChanges();
    expect(input).not.toHaveAttribute('disabled');
    component.disabled = undefined;
    await page.waitForChanges();
    expect(input).not.toHaveAttribute('disabled');
  });
  it('handles size prop by passing value to bs-checkbox data-size attr', async () => {
    const size = 'sm';
    const page = await newSpecPage({
      components: [BsCheckbox],
      html: `<bs-checkbox size='${size}'></bs-checkbox>`,
    });
    const component = page.root;
    expect(component.getAttribute('data-size')).toBe(size);
  });
  it('sets disabled state on checkbox if given prop', async () => {
    const page = await newSpecPage({
      components: [BsCheckbox],
      html: `<bs-checkbox disabled="true" label="${label}"></bs-checkbox>`,
    });
    const component = page.root;
    const inputEl = component.querySelector('input');
    expect(inputEl).toHaveAttribute('disabled');
    component.disabled = false;
    await page.waitForChanges();
    expect(inputEl).not.toHaveAttribute('disabled');
  });
  it('sets data-disabled attribute on label if given prop', async () => {
    const page = await newSpecPage({
      components: [BsCheckbox],
      html: `<bs-checkbox disabled="true" label="${label}"></bs-checkbox>`,
    });
    const component = page.root;
    const bsLabel = component.querySelector('bs-label');
    expect(bsLabel).toHaveAttribute('disabled');
    component.disabled = false;
    await page.waitForChanges();
    expect(bsLabel).not.toHaveAttribute('disabled');
  });
});
//# sourceMappingURL=bs-checkbox.spec.js.map
