// jshint esversion: 6
'use strict';

import React from 'react';
import {mount, shallow} from '../../build/enzyme';

import {DismissibleAlert} from './DismissibleAlert';

describe('DismissibleAlert', () => {
    const opts = {
        message: {
            text: 'warning text'
        },
        delayInterval: 1000
    };

    it('check the state after mounting', done => {
        const wrapper = mount(<DismissibleAlert {...opts} />);
        expect(wrapper.state('show')).toBe(true);
        setTimeout(() => {
            expect(wrapper.state('show')).toBe(false);
            done();
        }, opts.delayInterval + 100);
    });

    it('check the state after clicking close button', done => {
        let wrapper = null;
        const _opts = {
            ...opts,
            onHide() {
                expect(wrapper.state('show')).toBe(false);
                done();
            }
        };
        wrapper = mount(<DismissibleAlert {..._opts} />);
        expect(wrapper.state('show')).toBe(true);
        wrapper
            .find('.close')
            .hostNodes()
            .simulate('click');
    });

    it('check the state onHide', done => {
        const _opts = {
            ...opts,
            onHide() {
                expect(wrapper.state('show')).toBe(false);
                done();
            }
        };
        const wrapper = shallow(<DismissibleAlert {..._opts} />);
        setTimeout(() => {
            wrapper.setProps({
                message: {text: ''}
            });
        }, 100);
    });

    it('check the state onShow', done => {
        const _opts = {
            ...opts,
            onShow() {
                expect(wrapper.state('show')).toBe(true);
                done();
            }
        };
        const wrapper = shallow(<DismissibleAlert {..._opts} />);
        setTimeout(() => {
            wrapper.setProps({
                message: {text: 'another text'}
            });
        }, 100);
    });
});
