"use strict";

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

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

var _IconClock = _interopRequireDefault(require("@instructure/ui-icons/lib/Line/IconClock"));

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

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

var _FormattedDuration = _interopRequireDefault(require("../../../../shared/FormattedDuration"));

describe('Timer component', function () {
  var updateTimerMinimizedStub = sinon.stub();
  var screenreaderNotificationStub = sinon.stub();
  var testbed = createTestbed(_presenter.default, {
    screenreaderNotification: screenreaderNotificationStub,
    updateTimerMinimized: updateTimerMinimizedStub,
    timerRunning: true
  });
  afterEach(function () {
    screenreaderNotificationStub.resetHistory();
    updateTimerMinimizedStub.resetHistory();
  });
  it('renders with nothing when timerRunning is false', function () {
    testbed.render({
      timerRunning: false
    });
    var results = testbed.findChildrenByType(_FormattedDuration.default);
    expect(results.length).to.eq(0);
  });
  it('renders with a formatted duration when timerRunning is true', function () {
    testbed.render({
      timeLeftInSeconds: 100
    });
    var results = testbed.findChildrenByType(_FormattedDuration.default);
    expect(results.length).to.eq(1);
  });
  it('renders with an icon when timer is running and minimized', function () {
    testbed.render({
      timerRunning: true,
      timeLeftInSeconds: 100,
      timerMinimized: true
    });
    var icon = testbed.findChildrenByType(_IconClock.default)[0];
    expect(icon).to.not.be.undefined();
  });
  it('minimizes the timer when currently maximized', function () {
    testbed.render({
      timerMinimized: false
    });
    var button = testbed.findChildrenByTagName('button')[0];

    _testUtils.default.Simulate.click(button);

    expect(updateTimerMinimizedStub.calledWith(true)).to.be.true();
  });
  it('maximizes the timer when currently minimized', function () {
    testbed.render({
      timerMinimized: true
    });
    var button = testbed.findChildrenByTagName('button')[0];

    _testUtils.default.Simulate.click(button);

    expect(updateTimerMinimizedStub.calledWith(false)).to.be.true();
  });
  it('calls the screenreader and refocuses when timerMinimized changes', function () {
    testbed.render({
      timerMinimized: false
    });
    var focusOnShowStub = sinon.stub(testbed.subject, 'focusOnShow');
    var focusOnHideStub = sinon.stub(testbed.subject, 'focusOnHide');
    expect(screenreaderNotificationStub.called).to.be.false();
    testbed.render({
      timerMinimized: true
    });
    expect(screenreaderNotificationStub.calledWith('timer minimized')).to.be.true();
    expect(focusOnShowStub.called).to.be.true();
    testbed.render({
      timerMinimized: false
    });
    expect(screenreaderNotificationStub.calledWith('timer showing')).to.be.true();
    expect(focusOnHideStub.called).to.be.true();
    testbed.subject.focusOnShow.resetHistory();
    testbed.subject.focusOnHide.resetHistory();
  });
  describe('test with connect', function () {
    var connectedTestbed = createTestbed(withContext(_index.default), {});
    shouldRenderComponent(connectedTestbed, {}, _presenter.default);
  });
});