"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

var _immutable = require("immutable");

var _index = _interopRequireWildcard(require("../index"));

var _noop = _interopRequireDefault(require("../../../../../util/noop"));

var _sidebar = require("../../../../../actions/sidebar");

var styles = {
  componentId: 'cUqra',
  template: function template(theme) {
    return "\n\n.HeaderMenuButton__styles__title {\n  \n  display: none;\n  height: inherit;\n}\n\n@media screen and (--phoneBreakPoint) {\n  .HeaderMenuButton__styles__title {\n    display: flex;\n    align-items: center;\n  }\n}\n\n.HeaderMenuButton__styles__menuButton {\n  border: none;\n  font-size: ".concat(theme.menuButtonFontSize || 'inherit', ";\n  color: ").concat(theme.menuButtonColor || 'inherit', ";\n  background: transparent;\n  height: inherit;\n}\n\n.HeaderMenuButton__styles__menuButton:hover {\n  opacity: ").concat(theme.menuButtonHoverOpacity || 'inherit', ";\n}\n");
  },
  'title': 'HeaderMenuButton__styles__title',
  'menuButton': 'HeaderMenuButton__styles__menuButton'
};
describe('HeaderMenuButton', function () {
  describe('mapStateToProps', function () {
    context('on take', function () {
      context('with no backtracking', function () {
        it('hides the menu button', function () {
          var fakeState = (0, _immutable.fromJS)({
            quizSessions: {
              activeQuizSessionId: '1',
              '1': {
                oneAtATimeType: 'question',
                allowBacktracking: false
              }
            }
          });
          var props = (0, _index.mapStateToProps)(fakeState, {
            onTake: true
          });
          expect(props.hidden).to.be.true();
        });
      });
      context('with backtracking', function () {
        it('shows the menu button', function () {
          var fakeState = (0, _immutable.fromJS)({
            quizSessions: {
              activeQuizSessionId: '1',
              '1': {
                oneAtATimeType: 'question',
                allowBacktracking: true
              }
            }
          });
          var props = (0, _index.mapStateToProps)(fakeState, {
            onTake: true
          });
          expect(props.hidden).to.be.false();
        });
      });
      context('with an unloaded quizSession', function () {
        it('hides the menu button', function () {
          var fakeState = (0, _immutable.fromJS)({
            quizSessions: {
              activeQuizSessionId: '0'
            }
          });
          var props = (0, _index.mapStateToProps)(fakeState, {
            onTake: true
          });
          expect(props.hidden).to.be.true();
        });
      });
    });
    context('not on take', function () {
      context('with an unloaded quizSession', function () {
        it('shows the menu button', function () {
          var fakeState = (0, _immutable.fromJS)({
            quizSessions: {
              activeQuizSessionId: '0'
            }
          });
          var props = (0, _index.mapStateToProps)(fakeState, {
            onTake: false
          });
          expect(props.hidden).to.be.false();
        });
      });
    });
  });
  describe('mapDispatchToProps', function () {
    var dispatch = sinon.spy();
    afterEach(function () {
      return dispatch.resetHistory();
    });
    context('when component receives sidebarMenuClick prop', function () {
      it('passes sidebarMenuClick prop through', function () {
        var props = {
          sidebarMenuClick: function sidebarMenuClick() {}
        };
        expect((0, _index.mapDispatchToProps)(dispatch, props)).to.deep.equal(props);
      });
    });
    context('when component does not receive sidebarMenuClick prop', function () {
      it('uses toggleSidebar action creator', function () {
        (0, _index.mapDispatchToProps)(dispatch, {}).sidebarMenuClick();
        expect(dispatch).to.have.been.calledWith((0, _sidebar.toggleSidebar)());
      });
    });
  });
  var testbed = createTestbed(withContext(_index.default, {
    quizSessions: {
      activeQuizSessionId: '1',
      '1': {
        oneAtATimeType: 'question',
        allowBacktracking: false
      }
    }
  }), {
    sidebarMenuClick: _noop.default
  });
  it('should toggle the menu if the button is clicked', function () {
    var toggleMenuSpy = sinon.spy();
    testbed.render({
      sidebarMenuClick: toggleMenuSpy
    });
    var menuButton = testbed.findChildrenByClass(styles.menuButton)[0];

    _testUtils.default.Simulate.click(menuButton);

    expect(toggleMenuSpy).to.have.been.calledOnce();
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render();
      testbed.checkA11yStandards(done);
    });
  });
});