var _templateObject;
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render } from '@testing-library/react';
import { Alert, ALERT_VARIANT } from '.';
describe('Alert', function () {
  var wrapper;
  describe('when minimal props are provided', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Alert, null, "Description"));
    });
    it('should not set the `aria-labelledby` attribute', function () {
      expect(wrapper.getByTestId('alert')).not.toHaveAttribute('aria-labelledby');
    });
    it('should set the `role` attribute to `alert`', function () {
      expect(wrapper.getByTestId('alert')).toHaveAttribute('role', 'alert');
    });
    it('should render the close button', function () {
      expect(wrapper.getByTestId('close')).toBeInTheDocument();
    });
    it('should not render the content title', function () {
      expect(wrapper.queryAllByTestId('content-title')).toHaveLength(0);
    });
    it('should render the state icon', function () {
      expect(wrapper.getByTestId('state-icon')).toBeInTheDocument();
    });
    it('should render the default info icon', function () {
      expect(wrapper.getByTestId('icon-info')).toBeInTheDocument();
    });
    it('should render the content description', function () {
      expect(wrapper.getByTestId('content-description')).toHaveTextContent('Description');
    });
    describe('when the close button is clicked', function () {
      beforeEach(function () {
        wrapper.getByTestId('close').click();
      });
      it('should hide the alert', function () {
        expect(wrapper.queryAllByTestId('alert')).toHaveLength(0);
      });
    });
  });
  describe('when composing with different variants', function () {
    it.each(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n      variant\n      ", "\n      ", "\n      ", "\n      ", "\n    "])), ALERT_VARIANT.DANGER, ALERT_VARIANT.INFO, ALERT_VARIANT.SUCCESS, ALERT_VARIANT.WARNING)('should render the $variant icon', function (_ref) {
      var variant = _ref.variant;
      wrapper = render( /*#__PURE__*/React.createElement(Alert, {
        title: "Title",
        variant: variant
      }, "Description"));
      expect(wrapper.getByTestId("icon-".concat(variant))).toBeInTheDocument();
    });
  });
  describe('when all props are provided', function () {
    var onCloseSpy;
    beforeEach(function () {
      onCloseSpy = jest.fn();
      wrapper = render( /*#__PURE__*/React.createElement(Alert, {
        "data-arbitrary": "arbitrary",
        onClose: onCloseSpy,
        title: "Title",
        variant: ALERT_VARIANT.DANGER
      }, "Description"));
    });
    it('should spread arbitrary props', function () {
      expect(wrapper.getByTestId('alert')).toHaveAttribute('data-arbitrary', 'arbitrary');
    });
    it('should set the `aria-labelledby` attribute to the ID of the title', function () {
      var titleId = wrapper.getByTestId('content-title').getAttribute('id');
      expect(wrapper.getByTestId('alert')).toHaveAttribute('aria-labelledby', titleId);
    });
    it('should set the `aria-describedby` attribute to the ID of the content', function () {
      var contentId = wrapper.getByTestId('content-description').getAttribute('id');
      expect(wrapper.getByTestId('alert')).toHaveAttribute('aria-describedby', contentId);
    });
    it('should render the state icon', function () {
      expect(wrapper.getByTestId('state-icon')).toBeInTheDocument();
    });
    it('should set the `aria-hidden` attribute on the state icon', function () {
      expect(wrapper.getByTestId('state-icon')).toHaveAttribute('aria-hidden', 'true');
    });
    it('should render the danger icon', function () {
      expect(wrapper.getByTestId("icon-".concat(ALERT_VARIANT.DANGER))).toBeInTheDocument();
    });
    it('should render the content title', function () {
      expect(wrapper.getByTestId('content-title')).toHaveTextContent('Title');
    });
    it('should render the content description', function () {
      expect(wrapper.getByTestId('content-description')).toHaveTextContent('Description');
    });
    describe('when the close button is clicked', function () {
      beforeEach(function () {
        wrapper.getByTestId('close').click();
      });
      it('should call the callback once', function () {
        expect(onCloseSpy).toHaveBeenCalledTimes(1);
      });
    });
  });
  describe('when the Alert content changes', function () {
    var initialContentId;
    var initialTitleId;
    var ExampleAlert = function ExampleAlert(_ref2) {
      var content = _ref2.content;
      return /*#__PURE__*/React.createElement(Alert, {
        title: "Example title"
      }, content);
    };
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(ExampleAlert, {
        content: "initial content"
      }));
      initialContentId = wrapper.getByTestId('content-description').id;
      initialTitleId = wrapper.getByTestId('content-title').id;
      wrapper.rerender( /*#__PURE__*/React.createElement(ExampleAlert, {
        content: "new content"
      }));
    });
    it('does not generate a new content `id`', function () {
      expect(wrapper.getByTestId('content-description')).toHaveAttribute('id', initialContentId);
    });
    it('does not generate a new title `id`', function () {
      expect(wrapper.getByTestId('content-title')).toHaveAttribute('id', initialTitleId);
    });
  });
});