import { newSpecPage } from '@stencil/core/testing';
import { BsToast } from '../bs-toast';
import { faker } from '@faker-js/faker';
import { fireEvent } from '@testing-library/dom';
describe('bs-toast', () => {
  describe('rendering', () => {
    let toastId;
    beforeEach(() => {
      toastId = faker.random.alphaNumeric(20);
    });
    // renders basic
    it('renders', async () => {
      const dummyContent = faker.random.words(5);
      const page = await newSpecPage({
        components: [BsToast],
        html: `<bs-toast toast-id="${toastId}">${dummyContent}</bs-toast>`
      });
      expect(page.root).toEqualHtml(`<bs-toast toast-id="${toastId}">
        <bs-transition enterattribute="data-shown" enterduration="200">
        <div aria-role="alert" class="bs-toast">
          ${dummyContent}
        </div>
        </bs-transition>
      </bs-toast>`);
    });
  });
  describe('event handling', () => {
    let toastId;
    let dummyContent;
    beforeEach(() => {
      toastId = faker.random.alphaNumeric(20);
      dummyContent = faker.random.words(5);
    });
    // enter end
    it('should emit when transition enter ends', async () => {
      const page = await newSpecPage({
        components: [BsToast],
        html: `<bs-toast toast-id="${toastId}" duration="0">${dummyContent}</bs-toast>`
      });
      const handler = jest.fn();
      page.root.addEventListener('enterend', handler);
      const transition = page.root.querySelector('bs-transition');
      fireEvent(transition, new CustomEvent('enterend'));
      expect(handler).toHaveBeenCalled();
    });
    // leave end
    it('should emit when transition leave ends', async () => {
      const page = await newSpecPage({
        components: [BsToast],
        html: `<bs-toast toast-id="${toastId}">${dummyContent}</bs-toast>`
      });
      const handler = jest.fn();
      page.root.addEventListener('leaveend', handler);
      const transition = page.root.querySelector('bs-transition');
      fireEvent(transition, new CustomEvent('leaveend'));
      expect(handler).toHaveBeenCalled();
    });
    // auto-dismiss
    it('should emit when auto-dismissed', async () => {
      const page = await newSpecPage({
        components: [BsToast],
        html: `<bs-toast toast-id="${toastId}" duration="1000">${dummyContent}</bs-toast>`
      });
      const handler = jest.fn();
      page.root.addEventListener('dismiss', handler);
      const transition = page.root.querySelector('bs-transition');
      fireEvent(transition, new CustomEvent('enterend'));
      // Wait for auto-dismiss timer
      await new Promise(resolve => setTimeout(resolve, 1000));
      expect(handler).toHaveBeenCalled();
    });
    // default dismiss
    it('should emit when default dismissed', async () => {
      const page = await newSpecPage({
        components: [BsToast],
        html: `<bs-toast toast-id="${toastId}" duration="10000">${dummyContent}</bs-toast>`
      });
      const handler = jest.fn();
      page.root.addEventListener('dismiss', handler);
      fireEvent(page.root, new CustomEvent('defaultDismiss'));
      expect(handler).toHaveBeenCalled();
    });
  });
});
//# sourceMappingURL=bs-toast.spec.js.map
