import { faker } from '@faker-js/faker';
import { newSpecPage } from '@stencil/core/testing';
import { queryByText } from '@testing-library/dom';
import { BsCharacterCount } from '../bs-character-count';
const charMax = parseInt(faker.random.numeric(4));
const current = faker.datatype.number({ min: 0, max: charMax });
describe('bs-character-count', () => {
  it('renders a default count of 0.', async () => {
    const page = await newSpecPage({
      components: [BsCharacterCount],
      html: `<bs-character-count char-max="${charMax}"></bs-character-count>`,
    });
    expect(queryByText(page.root, `0 / ${charMax}`)).toBeTruthy();
  });
  it('renders a current character count and a max character count.', async () => {
    const page = await newSpecPage({
      components: [BsCharacterCount],
      html: `<bs-character-count char-count="${current}" char-max="${charMax}"></bs-character-count>`,
    });
    expect(queryByText(page.root, `${current} / ${charMax}`)).toBeTruthy();
  });
  it('renders a current character count and a max character count.', async () => {
    const updatedCount = faker.datatype.number({ min: 0, max: charMax });
    const page = await newSpecPage({
      components: [BsCharacterCount],
      html: `<bs-character-count char-count="${current}" char-max="${charMax}"></bs-character-count>`,
    });
    const component = page.root;
    expect(queryByText(page.root, `${current} / ${charMax}`)).toBeTruthy();
    component.charCount = updatedCount;
    await page.waitForChanges();
    expect(queryByText(page.root, `${updatedCount} / ${charMax}`)).toBeTruthy();
  });
  it('sets the error state when the character count exceeds the max.', async () => {
    const errorCount = faker.datatype.number({ min: charMax, max: charMax + 100 });
    const page = await newSpecPage({
      components: [BsCharacterCount],
      html: `<bs-character-count char-count="${errorCount}" char-max="${charMax}"></bs-character-count>`,
    });
    const component = page.root;
    expect(component).toHaveAttribute('data-error');
  });
});
//# sourceMappingURL=bs-character-count.spec.js.map
