"use strict";
/**
 * Test case for GroupUi
 *
 *  Copyright (C) 2010-2020 R-T Specialty, LLC.
 *
 *  This file is part of the Liza Data Collection Framework
 *
 *  Liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
var expect = require('chai').expect, sinon = require('sinon');
var GroupUi_1 = require("../../../src/ui/group/GroupUi");
var CommonResources_1 = require("./CommonResources");
describe('ui.group.GroupUi', function () {
    describe('#init', function () {
        [{ fields: ['foo', 'baz'] }].forEach(function (_a) {
            var fields = _a.fields;
            it('initializes Group Context with exclusive fields', function () {
                var context_called = false;
                var group = CommonResources_1.createGroup('foo', fields);
                var context = {
                    init: function () {
                        context_called = true;
                    },
                    detachStoreContent: function () { },
                };
                var feature_flag = {
                    isEnabled: function (_) {
                        return false;
                    },
                };
                var sut = CommonResources_1.createSut(GroupUi_1.GroupUi, {
                    group: group,
                    feature_flag: feature_flag,
                    context: context,
                });
                var quote = CommonResources_1.createQuote();
                sut.init(quote);
                expect(context_called).to.equal(true);
            });
        });
    });
    [
        {
            label: 'when feature flag is on, use new GroupContext',
            flag: true,
            show_expected: true,
            revoke_style_expected: false,
            hide_expected: true,
            apply_style_expected: false,
            styler_options_expected: false,
            context_options_expected: true,
            detach_store_content_expected: true,
            context_set_value_expected: true,
            styler_set_value_expected: false,
        },
        {
            label: 'when feature flag is off, use the old styler',
            flag: false,
            show_expected: false,
            revoke_style_expected: true,
            hide_expected: false,
            apply_style_expected: true,
            styler_options_expected: true,
            context_options_expected: false,
            detach_store_content_expected: false,
            context_set_value_expected: false,
            styler_set_value_expected: true,
        },
    ].forEach(function (_a) {
        var label = _a.label, flag = _a.flag, show_expected = _a.show_expected, revoke_style_expected = _a.revoke_style_expected, hide_expected = _a.hide_expected, apply_style_expected = _a.apply_style_expected, styler_options_expected = _a.styler_options_expected, context_options_expected = _a.context_options_expected, detach_store_content_expected = _a.detach_store_content_expected, context_set_value_expected = _a.context_set_value_expected, styler_set_value_expected = _a.styler_set_value_expected;
        it(label, function () {
            flag;
            var fields = ['bar', 'foo', 'baz'];
            var cmatch_fields = ['baz', 'bar'];
            var field_name = 'bar';
            var field_index = 0;
            var group = CommonResources_1.createGroup('foo', fields, cmatch_fields);
            var show_is_called = false;
            var revoke_style_is_called = false;
            var apply_style_is_called = false;
            var hide_is_called = false;
            var styler_set_options_called = false;
            var context_set_options_called = false;
            var detach_store_content_called = false;
            var context_set_value_called = false;
            var styler_set_value_called = false;
            var styler = {
                setOptions: function () {
                    styler_set_options_called = true;
                    return;
                },
                setValueByName: function () {
                    styler_set_value_called = true;
                    return;
                },
            };
            var feature_flag = {
                isEnabled: function (_) {
                    return flag;
                },
            };
            var context = CommonResources_1.createContext();
            context.show = function () {
                show_is_called = true;
            };
            context.hide = function () {
                hide_is_called = true;
            };
            context.setOptions = function () {
                context_set_options_called = true;
            };
            context.detachStoreContent = function () {
                detach_store_content_called = true;
            };
            context.setValueByName = function () {
                context_set_value_called = true;
            };
            var rcontext = {
                getFieldByName: function () {
                    return {
                        revokeStyle: function () {
                            revoke_style_is_called = true;
                        },
                        applyStyle: function () {
                            apply_style_is_called = true;
                        },
                    };
                },
            };
            var sut = CommonResources_1.createSut(GroupUi_1.GroupUi, {
                field: fields,
                group: group,
                styler: styler,
                context: context,
                rcontext: rcontext,
                feature_flag: feature_flag,
            });
            var quote = CommonResources_1.createQuote();
            sut.init(quote);
            sut.getCurrentIndex = sinon.stub().returns(10);
            expect(detach_store_content_called).to.equal(detach_store_content_expected);
            sut.showField(field_name, field_index);
            expect(revoke_style_is_called).to.equal(revoke_style_expected);
            expect(show_is_called).to.equal(show_expected);
            sut.hideField(field_name, field_index);
            expect(apply_style_is_called).to.equal(apply_style_expected);
            expect(hide_is_called).to.equal(hide_expected);
            sut.setOptions(field_name, field_index, {}, '');
            expect(styler_set_options_called).to.equal(styler_options_expected);
            expect(context_set_options_called).to.equal(context_options_expected);
            sut.setValueByName(field_name, field_index, 'foo');
            expect(styler_set_value_called).to.equal(styler_set_value_expected);
            expect(context_set_value_called).to.equal(context_set_value_expected);
        });
    });
    [
        {
            label: 'if "when" classification is true, show the group',
            when_name: 'foo',
            classes: {
                foo: { is: true },
            },
            shown: true,
        },
        {
            label: 'if "when" classification is false, do not show the group',
            when_name: 'foo',
            classes: {
                foo: { is: false },
            },
            shown: false,
        },
        {
            label: 'if "when" classification does not exist, do not show the group',
            when_name: 'foo',
            classes: {
                bar: { is: false },
            },
            shown: false,
        },
    ].forEach(function (_a) {
        var label = _a.label, when_name = _a.when_name, classes = _a.classes, shown = _a.shown;
        it(label, function () {
            var shown_actual = null;
            var group = CommonResources_1.createGroup('foo', [], [], false, when_name);
            var content = CommonResources_1.createJqueryContent();
            var quote = CommonResources_1.createQuote();
            var sut = CommonResources_1.createSut(GroupUi_1.GroupUi, {
                $content: content,
                group: group,
            });
            content.show = function () {
                shown_actual = true;
            };
            content.hide = function () {
                shown_actual = false;
            };
            var classify_cb = function (_) { };
            quote.onClassifyAndNow = function (cb) {
                classify_cb = cb;
            };
            sut.init(quote);
            classify_cb(classes);
            expect(shown_actual).to.equal(shown);
        });
    });
});
//# sourceMappingURL=data:application/json;base64, 