// jshint esversion: 6
'use strict';

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

var _react = _interopRequireDefault(require("react"));

var _enzyme = require("../../build/enzyme");

var _DismissibleAlert = require("./DismissibleAlert");

describe('DismissibleAlert', function () {
  var opts = {
    message: {
      text: 'warning text'
    },
    delayInterval: 1000
  };
  it('check the state after mounting', function (done) {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_DismissibleAlert.DismissibleAlert, opts));
    expect(wrapper.state('show')).toBe(true);
    setTimeout(function () {
      expect(wrapper.state('show')).toBe(false);
      done();
    }, opts.delayInterval + 100);
  });
  it('check the state after clicking close button', function (done) {
    var wrapper = null;

    var _opts = Object.assign({}, opts, {
      onHide: function onHide() {
        expect(wrapper.state('show')).toBe(false);
        done();
      }
    });

    wrapper = (0, _enzyme.mount)(_react.default.createElement(_DismissibleAlert.DismissibleAlert, _opts));
    expect(wrapper.state('show')).toBe(true);
    wrapper.find('.close').hostNodes().simulate('click');
  });
  it('check the state onHide', function (done) {
    var _opts = Object.assign({}, opts, {
      onHide: function onHide() {
        expect(wrapper.state('show')).toBe(false);
        done();
      }
    });

    var wrapper = (0, _enzyme.shallow)(_react.default.createElement(_DismissibleAlert.DismissibleAlert, _opts));
    setTimeout(function () {
      wrapper.setProps({
        message: {
          text: ''
        }
      });
    }, 100);
  });
  it('check the state onShow', function (done) {
    var _opts = Object.assign({}, opts, {
      onShow: function onShow() {
        expect(wrapper.state('show')).toBe(true);
        done();
      }
    });

    var wrapper = (0, _enzyme.shallow)(_react.default.createElement(_DismissibleAlert.DismissibleAlert, _opts));
    setTimeout(function () {
      wrapper.setProps({
        message: {
          text: 'another text'
        }
      });
    }, 100);
  });
});