import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { DismissibleBanner } from '.';
describe('DismissibleBanner', function () {
  var wrapper;
  var onDismissSpy;
  describe('default props', function () {
    beforeEach(function () {
      var props = {
        children: 'content',
        title: 'title',
        onDismiss: function onDismiss() {
          return true;
        }
      };
      onDismissSpy = jest.spyOn(props, 'onDismiss');
      wrapper = render( /*#__PURE__*/React.createElement(DismissibleBanner, props));
    });
    it('should render the title', function () {
      expect(wrapper.getByTestId('dimissiblebanner-title')).toHaveTextContent('title');
    });
    it('should render the content', function () {
      expect(wrapper.getByTestId('dimissiblebanner-description')).toHaveTextContent('content');
    });
    describe('when the component is dismissed', function () {
      beforeEach(function () {
        wrapper.getByText('Dismiss').click();
      });
      it('should call the `onDismiss` callback', function () {
        expect(onDismissSpy).toHaveBeenCalledTimes(1);
        expect(onDismissSpy.mock.calls[0][1]).toEqual(true);
      });
    });
    describe("when the `Don't show this again` checkbox is clicked before the component is dismissed", function () {
      beforeEach(function () {
        wrapper.getByTestId('checkbox-input').click();
        wrapper.getByText('Dismiss').click();
      });
      it('should call the `onDismiss` callback', function () {
        expect(onDismissSpy).toHaveBeenCalledTimes(1);
        expect(onDismissSpy.mock.calls[0][1]).toEqual(false);
      });
    });
  });
  describe('arbitrary content', function () {
    beforeEach(function () {
      var props = {
        children: /*#__PURE__*/React.createElement("div", null, "arbitrary content"),
        onDismiss: function onDismiss() {
          return true;
        }
      };
      wrapper = render( /*#__PURE__*/React.createElement(DismissibleBanner, props));
    });
    it('should render the title', function () {
      expect(wrapper.queryAllByTestId('dimissiblebanner-title')).toHaveLength(0);
    });
    it('should render the content', function () {
      expect(wrapper.queryAllByTestId('dimissiblebanner-description')).toHaveLength(0);
    });
    it('should render the arbitrary content', function () {
      expect(wrapper.getByText('arbitrary content')).toBeInTheDocument();
    });
  });
  describe('without checkbox', function () {
    beforeEach(function () {
      var props = {
        children: 'content',
        hasCheckbox: false,
        title: 'title',
        onDismiss: function onDismiss() {
          return true;
        }
      };
      wrapper = render( /*#__PURE__*/React.createElement(DismissibleBanner, props));
    });
    it("should not render the `Don't show this again` checkbox", function () {
      expect(wrapper.queryAllByTestId('checkbox')).toHaveLength(0);
    });
  });
  describe('with arbitrary props', function () {
    beforeEach(function () {
      var props = {
        children: 'content',
        'data-arbitrary': 'arbitrary',
        title: 'title',
        onDismiss: function onDismiss() {
          return true;
        }
      };
      wrapper = render( /*#__PURE__*/React.createElement(DismissibleBanner, props));
    });
    it('should spread arbitrary props', function () {
      expect(wrapper.getByTestId('dimissiblebanner-wrapper')).toHaveAttribute('data-arbitrary', 'arbitrary');
    });
  });
  describe('when onDismiss is not set', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(DismissibleBanner, null, "Content"));
    });
    it('does not throw an error when the dismiss button is clicked', function () {
      expect(function () {
        return userEvent.click(wrapper.getByTestId('dimissiblebanner-dismiss'));
      }).not.toThrow();
    });
  });
});