/* global
 xdescribe, describe, it, beforeEach, assert, expect, PreviewHelper,
 Currency, CmsTestUtility, TestUtility, SampleData
*/

xdescribe('Currency / DropdownsWordPressTest', function() { //DR-6576
    'use strict';
    var control, themeController;

    var activeData = SampleData.getBox();
    var passiveData = $.extend({"display": "inline-block"}, SampleData.getBox());
    var hoveredData = SampleData.getBox();

    CmsTestUtility.controlSetUp();

    beforeEach(function () {

    });

    it('html test', function() {
        themeController = window.editor.themeController;
        control = new Currency();
        themeController.addToControls("/controls/Currency", control);
        window.editor.templatesController.currentTemplate.BaseTemplate.body.items.push("/controls/Currency");

        CmsTestUtility.getPreviewAfterFullExport(function(error, previewDocument) {
            var dom = $(PreviewHelper.getDataIdSelector(control.dropdowns.dataId), previewDocument);
            assert(dom.length > 0, 'control not found');

            assert.equal(1, dom.parent().find(PreviewHelper.getDataIdSelector(control.dropdowns.dataId)).length, 'dropdowns dataId not found');
            assert.equal(2, dom.find(PreviewHelper.getDataIdSelector(control.dropdowns.menu.dataId)).length, 'menu dataId not found');
            assert.equal(2, dom.find(PreviewHelper.getDataIdSelector(control.dropdowns.menu.item.dataId)).length, 'menu items dataId not found');
            assert.equal(1, dom.find(PreviewHelper.getDataIdSelector(control.dropdowns.subMenu.Menu.dataId)).length, 'submenu not dataId found');
            assert.equal(31, dom.find(PreviewHelper.getDataIdSelector(control.dropdowns.subMenu.Menu.item.dataId)).length, 'submenu items dataId not found');
            assert.equal(1, dom.parent().find('script').length, 'script tag not found');
            assert.equal(true, dom.parent().find('script').html().indexOf('function set_currency_cookies(currency)') > -1, 'function set_currency_cookies not found');

            var item = dom.find('div > ul > li.'+ control.dropdowns.menu.item.classNames);
            assert.equal(true, item.length > 0, 'invalid structure');
            assert.equal(true, item.find('a.dropdown-toggle').length > 0, 'a.dropdown-toggle  not found');
            assert.equal(true, item.find(control.dropdowns.subMenu.Menu.selector + "-popup").length > 0, 'popup not found');

        });

    });

    describe('css test', function() {
        var cssConfig = function () {
            themeController = window.editor.themeController;
            control = new Currency();

            TestUtility.applyCss(control.dropdowns.menu.item.active, activeData);
            TestUtility.applyCss(control.dropdowns.menu.item.passive, passiveData);
            TestUtility.applyCss(control.dropdowns.menu.item.hovered, hoveredData);

            themeController.addToControls("/controls/Currency", control);
            window.editor.templatesController.currentTemplate.BaseTemplate.body.items.push("/controls/Currency");
            CmsTestUtility.fixPseudoClasses(control.dropdowns.menu.item);
        };



        it('check menu prop', function () {
            cssConfig.call();
            CmsTestUtility.getPreviewAfterFullExport(function(error, previewDocument) {
                var dom = $(PreviewHelper.getDataIdSelector(control.dropdowns.dataId), previewDocument);
                assert(dom.length > 0, 'control not found');

                var elem = dom.find(control.dropdowns.menu.item.selector + ' > a.dropdown-toggle');
                TestUtility.assertCssTrue(elem, passiveData);
                elem.addClass('test-hovered');
                TestUtility.assertCssTrue(elem, hoveredData);
                elem.addClass('active');
                TestUtility.assertCssTrue(elem, activeData);
            });
        });


        var cssConfig2 = function () {
            themeController = window.editor.themeController;
            control = new Currency();

            TestUtility.applyCss(control.dropdowns.subMenu.Menu.item.active, activeData);
            TestUtility.applyCss(control.dropdowns.subMenu.Menu.item.passive, passiveData);
            TestUtility.applyCss(control.dropdowns.subMenu.Menu.item.hovered, hoveredData);

            themeController.addToControls("/controls/Currency", control);
            window.editor.templatesController.currentTemplate.BaseTemplate.body.items.push("/controls/Currency");
            CmsTestUtility.fixPseudoClasses(control.dropdowns.subMenu.Menu.item);
        };

        it('check submenu prop', function () {
            cssConfig2.call();
            CmsTestUtility.getPreviewAfterFullExport(function(error, previewDocument) {
                var dom = $(PreviewHelper.getDataIdSelector(control.dropdowns.dataId), previewDocument);
                assert(dom.length > 0, 'control not found');

                var elem = dom.find(control.dropdowns.subMenu.Menu.item.selector + ' > a');
                TestUtility.assertCssTrue(elem, passiveData);
                elem.addClass('test-hovered');
                TestUtility.assertCssTrue(elem, hoveredData);
                elem.addClass('active');
                TestUtility.assertCssTrue(elem, activeData);
            });
        });

        it('media width equal 1000px', function () {
            cssConfig.call();
            CmsTestUtility.getPreviewAfterFullExport(function(error, previewDocument) {
                var dom = $(PreviewHelper.getDataIdSelector(control.dropdowns.dataId), previewDocument);
                assert(dom.length > 0, 'control not found');
                $('iframe').width(1000);

                expect("block").toEqual(dom.css("display"));
                TestUtility.assertCssTrue(dom.find(control.dropdowns.subMenu.Menu.selector + "-popup"), TestUtility.toObject("top: 100%; left: 0px;"));
            });
        });

        it('media width equal 400px', function () {
            cssConfig.call();
            CmsTestUtility.getPreviewAfterFullExport(function(error, previewDocument) {
                var dom = $(PreviewHelper.getDataIdSelector(control.dropdowns.dataId), previewDocument);
                assert(dom.length > 0, 'control not found');
                $('iframe').width(400);

                expect("block").toEqual(dom.css("display"));
            });
        });

    });
});
