import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render, fireEvent } from '@testing-library/react';
import { Toast } from '.';
describe('Toast', function () {
  var wrapper;
  var onDismissSpy;
  var onMouseEnterSpy;
  var onMouseLeaveSpy;
  var LABEL = 'Example label';
  var DESCRIPTION = 'This is an example toast message';
  describe('default props', function () {
    onDismissSpy = jest.fn();
    onMouseEnterSpy = jest.fn();
    onMouseLeaveSpy = jest.fn();
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Toast, {
        appearance: "info",
        autoDismiss: false,
        autoDismissTimeout: 300,
        "data-arbitrary": "arbitrary",
        label: LABEL,
        isRunning: false,
        onDismiss: onDismissSpy,
        onMouseEnter: onMouseEnterSpy,
        onMouseLeave: onMouseLeaveSpy,
        placement: "top-right",
        transitionDuration: 300,
        transitionState: "entered"
      }, DESCRIPTION));
    });
    it('should spread arbitrary props', function () {
      expect(wrapper.getByTestId('toast-wrapper')).toHaveAttribute('data-arbitrary', 'arbitrary');
    });
    it('should set the `role` attribute to `alert`', function () {
      expect(wrapper.getByTestId('toast-wrapper')).toHaveAttribute('role', 'alert');
    });
    it('should set the `aria-labelledby` attribute to the ID of the title', function () {
      var titleId = wrapper.getByTestId('toast-title').getAttribute('id');
      expect(wrapper.getByTestId('toast-wrapper')).toHaveAttribute('aria-labelledby', titleId);
    });
    it('should set the `aria-describedby` attribute to the ID of the content', function () {
      var contentId = wrapper.getByTestId('toast-description').getAttribute('id');
      expect(wrapper.getByTestId('toast-wrapper')).toHaveAttribute('aria-describedby', contentId);
    });
    it('should set the `aria-hidden` attribute on the state icon', function () {
      expect(wrapper.getByTestId('toast-icon')).toHaveAttribute('aria-hidden', 'true');
    });
    it('renders the toast to the DOM', function () {
      expect(wrapper.queryByTestId('toast-wrapper')).toBeInTheDocument();
    });
    it('displays the label text', function () {
      expect(wrapper.queryByText(LABEL)).toBeInTheDocument();
    });
    describe('and the user clicks on the dismiss button', function () {
      beforeEach(function () {
        fireEvent(wrapper.getByTestId('toast-dismiss'), new MouseEvent('click', {
          bubbles: true,
          cancelable: true
        }));
      });
      it('invokes the onDismiss callback', function () {
        expect(onDismissSpy).toHaveBeenCalledTimes(1);
      });
    });
  });
});