"use strict";

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

var _chai = require("chai");

var _alertTimerMiddleware = _interopRequireDefault(require("../alertTimerMiddleware"));

var _constants = require("@instructure/quiz-common/lib/constants");

var _alerts = require("../../actions/alerts");

var dispatchStub = sinon.stub();
var fakeStore = {
  dispatch: dispatchStub
};
describe('alertTimerMiddleware', function () {
  it('sets a timeout to remove an alert', function () {
    var timeToWait = 1000;
    var alertID = '12345';
    var fakeAction = {
      type: _constants.ADD_ALERT,
      payload: {
        uuid: alertID,
        removeIn: timeToWait
      }
    };
    var expectedAction = (0, _alerts.removeAlert)(alertID);

    var callSyncAndAssertTime = function callSyncAndAssertTime(fn, time) {
      fn();
      (0, _chai.expect)(time).to.be.equal(timeToWait);
    };

    (0, _alertTimerMiddleware.default)(fakeStore)(function () {})(fakeAction, callSyncAndAssertTime);
    (0, _chai.expect)(dispatchStub.calledWith(expectedAction)).to.be.true();
    dispatchStub.resetHistory();
  });
});