/*global TestUtility, describe, it, expect, assert, StyleAndScriptAppending, runs, waitsFor */
/*global UIPRTL, ProviderData, Theme */
describe('Designer\\controls\\Theme\\editor\\providers\\UIPRTL Unit Test', function () {
    'use strict';

    TestUtility.controlSetUp();
    var validValues = [['rtl',true], ['ltr',false]];

    var loaded = false;

    function loadFiles() {
        if (loaded)
            return;
        StyleAndScriptAppending.loadAndApply(
            {
                files: [
                    '../../../Designer.Site/Designer.WebUI/Content/UI/UICommons/UICommons/editor/providers/UIProvider.js',
                    '../../../Designer/controls/Components/Theme/editor/providers/UIPRTL.js'
                ],
                documents: [window.document]
            }, function () {
                loaded = true;
            }
        );
    }

    function runTest(callBack, testDescription) {
        runs(function () {
            loadFiles();
        });

        waitsFor(function () {
            return loaded;
        }, "TIMEOUT!!!" + (testDescription ? testDescription : ''), 1000);

        runs(function() {
            assert(typeof callBack === 'function', 'Test function is not defined');
            callBack();
        });
    }

    $.each(validValues, function(){
        var val = this;
        it('Get: valid value "' + val[0] + '"', function () {
            runTest(function () {
                var control = new Theme();
                control.direction = val[0];
                var data = new ProviderData(control, null);
                var provider = new UIPRTL(data);
                expect(provider.value()).toEqual(val[1]);
            }, 'Valid values');
        });
    });

    $.each(validValues, function(){
        var val = this;
        it('Set: valid value "' + val[0] + '"', function () {
            runTest(function () {
                var control = new Theme();
                var data = new ProviderData(control, null);
                var provider = new UIPRTL(data);
                provider.value(val[1]);
                expect(provider.value()).toEqual(val[1]);
                expect(control.direction).toEqual(val[0]);
            }, 'Valid values');
        });
    });

});

