import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render } from '@testing-library/react';
import { Breadcrumbs, BreadcrumbsItem } from '.';
import { Link } from '../Link';
describe('Breadcrumbs', function () {
  var wrapper;
  describe('when called with regular links', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Breadcrumbs, {
        "data-arbitrary": "arbitrary-breadcrumbs"
      }, /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        "data-arbitrary": "arbitrary-breadcrumbs-item",
        link: /*#__PURE__*/React.createElement(Link, {
          href: "#home"
        }, "Home")
      }), /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        link: /*#__PURE__*/React.createElement(Link, {
          href: "#reports"
        }, "Reports")
      }), /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        link: /*#__PURE__*/React.createElement(Link, {
          href: "#stuff"
        }, "Stuff")
      }), /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        link: /*#__PURE__*/React.createElement(Link, {
          href: "#22"
        }, "22nd April 2019")
      })));
    });
    it('should spread arbitrary props for breadcrumbs', function () {
      expect(wrapper.getByTestId('breadcrumb-wrapper')).toHaveAttribute('data-arbitrary', 'arbitrary-breadcrumbs');
    });
    it('should spread arbitrary props for breadcrumbs items', function () {
      expect(wrapper.getAllByTestId('breadcrumb')[0]).toHaveAttribute('data-arbitrary', 'arbitrary-breadcrumbs-item');
    });
    it('should set the `aria-label` attribute to `breadcrumb`', function () {
      expect(wrapper.getByTestId('breadcrumb-wrapper')).toHaveAttribute('aria-label', 'Breadcrumb');
    });
    it('should apply the `aria-hidden` attribute to seperators', function () {
      expect(wrapper.getAllByTestId('breadcrumb-separator')[0]).toHaveAttribute('aria-hidden');
    });
    it('should apply the `aria-current` attribute to the last crumb', function () {
      expect(wrapper.getByTestId('breadcrumb-end-title')).toHaveAttribute('aria-current', 'page');
    });
    it('should render a list of breadcrumbs', function () {
      var linkElements = wrapper.queryAllByTestId('breadcrumb');
      expect(linkElements).toHaveLength(4);
    });
    it('should render four separators', function () {
      var linkElements = wrapper.queryAllByTestId('breadcrumb-separator');
      expect(linkElements).toHaveLength(3);
    });
    it('should render the first 4 links as anchors', function () {
      var linkElements = wrapper.queryAllByTestId('link');
      expect(linkElements).toHaveLength(3);
    });
    it('should render the last link as a title', function () {
      var endTitle = wrapper.getByTestId('breadcrumb-end-title');
      expect(endTitle).toBeInTheDocument();
    });
    it('should only include separators in for all but the first link', function () {
      expect(wrapper.queryAllByTestId('link')).toHaveLength(3);
    });
  });
  describe('when `isFirst` and `isLast` are specified for items', function () {
    var consoleWarnSpy;
    beforeEach(function () {
      consoleWarnSpy = jest.spyOn(global.console, 'warn');
      wrapper = render( /*#__PURE__*/React.createElement(Breadcrumbs, null, /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        isFirst: true,
        link: /*#__PURE__*/React.createElement(Link, {
          href: "#first"
        }, "First")
      }), /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        isLast: true,
        link: /*#__PURE__*/React.createElement(Link, {
          href: "#last"
        }, "Last")
      })));
    });
    it('should warn the consumer twice about specifying props that will be overwritten', function () {
      expect(consoleWarnSpy).toHaveBeenCalledTimes(2);
    });
    it('should warn the consumer `isFirst` will be overwritten', function () {
      expect(consoleWarnSpy).toHaveBeenCalledWith('WARN - MODDS - Prop `isFirst` on `BreadcrumbsItem` will be overwritten');
    });
    it('should warn the consumer `isLast` will be overwritten', function () {
      expect(consoleWarnSpy).toHaveBeenCalledWith('WARN - MODDS - Prop `isLast` on `BreadcrumbsItem` will be overwritten');
    });
  });
  describe('when there is only one breadcrumb', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Breadcrumbs, null, /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        link: /*#__PURE__*/React.createElement(Link, {
          href: "#home"
        }, "Home")
      })));
    });
    it('should render one breadcrumb', function () {
      var linkElements = wrapper.queryAllByTestId('breadcrumb');
      expect(linkElements).toHaveLength(1);
    });
  });
  describe('when href and children are used', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Breadcrumbs, null, /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        href: "#home"
      }, "Home"), /*#__PURE__*/React.createElement(BreadcrumbsItem, {
        href: "#reports"
      }, "Reports")));
    });
    it('should render the breadcrumb title', function () {
      expect(wrapper.queryByText('Home')).toBeInTheDocument();
    });
    it('sould apply the `href` attribute', function () {
      expect(wrapper.queryByText('Home')).toHaveAttribute('href', '#home');
    });
  });
  it('does not throw an error if there are no children', function () {
    expect(function () {
      return render( /*#__PURE__*/React.createElement(Breadcrumbs, null));
    }).not.toThrow();
  });
});