"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _reactDom = _interopRequireDefault(require("react-dom"));

var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));

var _presenter = _interopRequireDefault(require("../presenter"));

var styles = {
  componentId: 'dhBxf',
  template: function template(theme) {
    return "\n\n.Summary__styles__middleSection {\n  flex-grow: 2;\n}\n\n.Summary__styles__endSection {\n  flex-grow: 1;\n  text-align: right;\n}\n\n[dir=\"ltr\"] .Summary__styles__endSection {\n  text-align: right;\n}\n\n[dir=\"rtl\"] .Summary__styles__endSection {\n  text-align: right;\n}\n\n.Summary__styles__questionCount {\n  flex-grow: 1;\n}\n\n.Summary__styles__itemsContainer {\n  color: ".concat(theme.itemContainerColor || 'inherit', ";\n  display: flex;\n  width: 100%;\n  padding: ").concat(theme.itemContainerPadding || 'inherit', ";\n  border: dotted ").concat(theme.itemContainerBorderWidth || 'inherit', ";\n  border-color: ").concat(theme.itemContainerBorderColor || 'inherit', ";\n}\n\n.Summary__styles__summary {\n  margin: ").concat(theme.summaryMargin || 'inherit', ";\n  margin-left: ").concat(theme.summaryMarginLeft || 'inherit', ";\n  display: flex;\n  flex-grow: 1;\n}\n");
  },
  'middleSection': 'Summary__styles__middleSection',
  'endSection': 'Summary__styles__endSection',
  'questionCount': 'Summary__styles__questionCount',
  'itemsContainer': 'Summary__styles__itemsContainer',
  'summary': 'Summary__styles__summary'
};
describe('Common Stimulus Sidebar Summary Presenter', function () {
  var setSidebarStimulusIsShowingStub = sinon.stub();
  var props = {
    startPosition: 1,
    isDragging: false,
    isShowingItems: false,
    sidebarOpen: true,
    numberOfItems: 6,
    stimulusId: '1',
    setSidebarStimulusIsShowing: setSidebarStimulusIsShowingStub
  };
  var testbed = createTestbed(_presenter.default, props);
  afterEach(function () {
    setSidebarStimulusIsShowingStub.resetHistory();
  });
  context('with more than 5 items', function () {
    context('isDragging', function () {
      it('renders a box with the word Included in message', function () {
        testbed.render({
          isDragging: true
        });
        expect(testbed.getText()).to.include('Included');
      });
    });
    context('isShowingItems', function () {
      it('renders a box with the word Collapse in message', function () {
        testbed.render({
          isShowingItems: true
        });
        expect(testbed.getText()).to.include('Collapse');
      });
    });
    it('renders a box with the word Expand in message', function () {
      testbed.render();
      expect(testbed.getText()).to.include('Expand');
    });
    it('renders the question count', function () {
      testbed.render();
      var questionCount = testbed.findChildrenByClass(styles.questionCount)[0];
      expect(questionCount.innerText).to.eq('Questions 1 - 6');
    });
  });
  context('with fewer than 6 items', function () {
    context('isDragging', function () {
      it('renders a box with the word Included in message', function () {
        testbed.render({
          isDragging: true,
          numberOfItems: 3
        });
        expect(testbed.getText()).to.include('Included');
      });
      context('with one item', function () {
        it('renders a box with the correct wording', function () {
          testbed.render({
            isDragging: true,
            numberOfItems: 1
          });
          expect(testbed.getText()).to.include('Question 1 Included');
        });
      });
    });
    it('renders an empty div', function () {
      testbed.render({
        numberOfItems: 5
      });
      expect(testbed.findChildrenByClass(styles.itemsContainer)).to.be.empty();
    });
  });
  it('sets showingItems to false when clicked and isShowingItems true', function () {
    testbed.render({
      isShowingItems: true
    });

    var container = _reactDom.default.findDOMNode(testbed.findChildrenByClass(styles.summary)[0]);

    _testUtils.default.Simulate.click(container);

    expect(setSidebarStimulusIsShowingStub.calledWith('1', false)).to.be.true();
  });
  it('sets showingItems to true when clicked and isShowingItems false', function () {
    testbed.render();

    var container = _reactDom.default.findDOMNode(testbed.findChildrenByClass(styles.summary)[0]);

    _testUtils.default.Simulate.click(container);

    expect(setSidebarStimulusIsShowingStub.calledWith('1', true)).to.be.true();
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render();
      testbed.checkA11yStandards(done);
    });
  });
});