import { newSpecPage } from '@stencil/core/testing';
import { BsTextareaField } from '../bs-textarea-field';
import { faker } from '@faker-js/faker';
const id = faker.random.word();
const label = faker.random.words();
const hint = faker.random.words();
const max = faker.datatype.number();
describe('bs-textarea-field', () => {
  it('passes attributes correctly', async () => {
    const page = await newSpecPage({
      components: [BsTextareaField],
      html: `<bs-textarea-field
        id="${id}"
        label="${label}"
      ></bs-textarea-field>`,
    });
    const component = page.root;
    const field = component.querySelector('bs-field-layout');
    const textarea = component.querySelector('bs-textarea');
    expect(field.getAttribute('labelfor')).toBe(id);
    expect(textarea.getAttribute('id')).toBe(id);
  });
  it('handles the charMax prop', async () => {
    const page = await newSpecPage({
      components: [BsTextareaField],
      html: `<bs-textarea-field></bs-textarea-field>`,
    });
    const component = page.root;
    const field = component.querySelector('bs-field-layout');
    component.charMax = max;
    await page.waitForChanges();
    expect(field.getAttribute('charmax')).toBe(`${max}`);
  });
  it('handles the disabled prop', async () => {
    const page = await newSpecPage({
      components: [BsTextareaField],
      html: `<bs-textarea-field
        id="${id}"
        label="${label}"
        disabled="true"
      ></bs-textarea-field>`,
    });
    const component = page.root;
    let textarea = component.querySelector('bs-textarea');
    let field = component.querySelector('bs-field-layout');
    expect(textarea).toHaveAttribute('disabled');
    expect(field).toHaveAttribute('disabled');
    component.disabled = false;
    await page.waitForChanges();
    expect(textarea).not.toHaveAttribute('disabled');
    expect(field).not.toHaveAttribute('disabled');
  });
  it('handles the error prop', async () => {
    const page = await newSpecPage({
      components: [BsTextareaField],
      html: `<bs-textarea-field
        id="${id}"
        label="${label}"
        error="true"
      ></bs-textarea-field>`,
    });
    const component = page.root;
    const textarea = component.querySelector('bs-textarea');
    const field = component.querySelector('bs-field-layout');
    expect(textarea).toHaveAttribute('error');
    expect(field).toHaveAttribute('error');
    component.error = false;
    await page.waitForChanges();
    expect(textarea).not.toHaveAttribute('error');
    expect(field).not.toHaveAttribute('error');
  });
  it('handles the hints prop', async () => {
    const page = await newSpecPage({
      components: [BsTextareaField],
      html: `<bs-textarea-field id="${id}" hints="${hint}"></bs-textarea-field>`,
    });
    const component = page.root;
    const field = component.querySelector('bs-field-layout');
    const textarea = component.querySelector('bs-textarea');
    expect(field.getAttribute('hints')).toBe(hint);
    expect(field.getAttribute('hintid')).toBeTruthy();
    expect(field.getAttribute('hintid')).toBe(textarea.getAttribute('hintid'));
  });
  it('handles the label prop', async () => {
    const page = await newSpecPage({
      components: [BsTextareaField],
      html: `<bs-textarea-field
        id="${id}"
        label="${label}"
      ></bs-textarea-field>`,
    });
    const component = page.root;
    const field = component.querySelector('bs-field-layout');
    expect(field.getAttribute('label')).toBe(label);
  });
  it('handles the required prop', async () => {
    const page = await newSpecPage({
      components: [BsTextareaField],
      html: `<bs-textarea-field
        id="${id}"
        label="${label}"
        required="true"
      ></bs-textarea-field>`,
    });
    const component = page.root;
    const textarea = component.querySelector('bs-textarea');
    const field = component.querySelector('bs-field-layout');
    expect(textarea).toHaveAttribute('required');
    expect(field).toHaveAttribute('required');
    component.required = false;
    await page.waitForChanges();
    expect(textarea).not.toHaveAttribute('required');
    expect(field).not.toHaveAttribute('required');
  });
});
//# sourceMappingURL=bs-textarea-field.spec.js.map
