import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render } from '@testing-library/react';
import { Tooltip, TOOLTIP_POSITION } from '.';
describe('Tooltip', function () {
  var wrapper;
  describe('minimal props', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Tooltip, null, "Content"));
    });
    it('should render the tooltip without an `id` attribute', function () {
      expect(wrapper.getByTestId('tooltip')).not.toHaveAttribute('id');
    });
    it('should render the tooltip with an `aria-describedby` attribute', function () {
      var contentId = wrapper.getByTestId('tooltip-content').getAttribute('id');
      expect(wrapper.getByTestId('tooltip')).toHaveAttribute('aria-describedby', contentId);
    });
    it('should render the tooltip without an `aria-labelledby` attribute', function () {
      expect(wrapper.getByTestId('tooltip')).not.toHaveAttribute('aria-labelledby');
    });
    it('should render the tooltip with a `role` attribute', function () {
      expect(wrapper.getByTestId('tooltip')).toHaveAttribute('role', 'tooltip');
    });
    it('should render the tooltip without extra style', function () {
      expect(wrapper.getByTestId('tooltip')).not.toHaveAttribute('style');
    });
    it('should render the content', function () {
      expect(wrapper.getByText('Content')).toBeInTheDocument();
    });
  });
  describe('all props', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Tooltip, {
        bottom: 1,
        "data-arbitrary": "arbitrary",
        id: "123",
        left: 2,
        position: TOOLTIP_POSITION.BELOW,
        right: 3,
        title: "title",
        top: 4,
        width: 100
      }, "Content"));
    });
    it('should spread arbitrary props', function () {
      expect(wrapper.getByTestId('tooltip')).toHaveAttribute('data-arbitrary', 'arbitrary');
    });
    it('should render the tooltip with an `id` attribute', function () {
      expect(wrapper.getByTestId('tooltip')).toHaveAttribute('id', '123');
    });
    it('should render the tooltip with an `aria-describedby` attribute', function () {
      var contentId = wrapper.getByTestId('tooltip-content').getAttribute('id');
      expect(wrapper.getByTestId('tooltip')).toHaveAttribute('aria-describedby', contentId);
    });
    it('should render the tooltip with an `aria-labelledby` attribute', function () {
      var titleId = wrapper.getByText('title').getAttribute('id');
      expect(wrapper.getByTestId('tooltip')).toHaveAttribute('aria-labelledby', titleId);
    });
    it('should render the tooltip with a `role` attribute', function () {
      expect(wrapper.getByTestId('tooltip')).toHaveAttribute('role', 'tooltip');
    });
    it('should render the tooltip with extra style', function () {
      expect(wrapper.getByTestId('tooltip')).toHaveStyleRule('bottom', '1px');
      expect(wrapper.getByTestId('tooltip')).toHaveStyleRule('left', '2px');
      expect(wrapper.getByTestId('tooltip')).toHaveStyleRule('right', '3px');
      expect(wrapper.getByTestId('tooltip')).toHaveStyleRule('top', '4px');
      expect(wrapper.getByTestId('tooltip')).toHaveStyleRule('width', '100px');
    });
    it('should render the title', function () {
      expect(wrapper.getByText('title')).toBeInTheDocument();
    });
    it('should render the content', function () {
      expect(wrapper.getByText('Content')).toBeInTheDocument();
    });
  });
  describe('when the default `id` is used and the content changes', function () {
    var initialTitleId;
    var initialContentId;
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Tooltip, {
        title: "Title"
      }, "Initial content"));
      initialTitleId = wrapper.getByTestId('tooltip-title').id;
      initialContentId = wrapper.getByTestId('tooltip-content').id;
      wrapper.rerender( /*#__PURE__*/React.createElement(Tooltip, {
        title: "Title"
      }, "New content"));
    });
    it('does not generate new title `id`', function () {
      expect(wrapper.getByTestId('tooltip-title')).toHaveAttribute('id', initialTitleId);
    });
    it('does not generate new content `id`', function () {
      expect(wrapper.getByTestId('tooltip-content')).toHaveAttribute('id', initialContentId);
    });
  });
});