"use strict";
/**
 * Test case for StackedGroupUi
 *
 *  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 StackedGroupUi_1 = require("../../../src/ui/group/StackedGroupUi");
var CommonResources_1 = require("./CommonResources");
describe('ui.group.StackedGroupUi', function () {
    describe('#showField', function () {
        [
            {
                field: 'foo_bar',
                index: 0,
            },
            {
                field: 'bar_foo',
                index: 1,
            },
        ].forEach(function (_a) {
            var field = _a.field, index = _a.index;
            it("it shows the header for " + field + " when group fields are visible", function () {
                var container = CommonResources_1.createContainer();
                var content = CommonResources_1.createContent();
                content.querySelector
                    .withArgs('div.stacked-container')
                    .returns(container);
                var sut = CommonResources_1.createSut(StackedGroupUi_1.StackedGroupUi, {
                    field: field,
                    content: content,
                });
                var removeClass = sinon.stub();
                var header = {
                    classList: {
                        remove: removeClass,
                    },
                };
                sut.getCurrentIndex = sinon.stub().returns(10);
                sut.hasVisibleField = sinon.stub().withArgs(index).returns(true);
                container.querySelectorAll.withArgs('dl').returns([header, header]);
                var quote = CommonResources_1.createQuote();
                content.querySelectorAll.withArgs('dl').returns([header, header]);
                sut.init(quote);
                sut.showField(field, index);
                expect(removeClass.calledOnce).to.be.true;
            });
        });
    });
    describe('#hideField', function () {
        [
            {
                field: 'foo_baz',
                index: 0,
            },
            {
                field: 'baz_foo',
                index: 1,
            },
        ].forEach(function (_a) {
            var field = _a.field, index = _a.index;
            it("it hides the header for " + field + " when no group fields are visible", function () {
                var container = CommonResources_1.createContainer();
                var content = CommonResources_1.createContent();
                content.querySelector
                    .withArgs('div.stacked-container')
                    .returns(container);
                var sut = CommonResources_1.createSut(StackedGroupUi_1.StackedGroupUi, {
                    field: field,
                    content: content,
                });
                var addClass = sinon.stub();
                var header = {
                    classList: {
                        add: addClass,
                    },
                };
                sut.getCurrentIndex = sinon.stub().returns(10);
                sut.hasVisibleField = sinon.stub().withArgs(index).returns(false);
                container.querySelectorAll.withArgs('dl').returns([header, header]);
                var quote = CommonResources_1.createQuote();
                content.querySelectorAll.withArgs('dl').returns([header, header]);
                sut.init(quote);
                sut.hideField(field, index);
                expect(addClass.calledOnce).to.be.true;
            });
        });
    });
    describe('removeIndex', function () {
        it('calls GroupContext and ElementStyler remove methods', function () {
            var container = CommonResources_1.createContainer();
            var content = CommonResources_1.createContent();
            var index = 1;
            content.querySelector
                .withArgs('div.stacked-container')
                .returns(container);
            var styler_remove_called = false;
            var context_remove_index_is_called = false;
            var group_get_fields_is_called = false;
            var styler = {
                remove: function () {
                    styler_remove_called = true;
                    return;
                },
            };
            var context = CommonResources_1.createContext();
            context.removeIndex = function () {
                context_remove_index_is_called = true;
            };
            var group = CommonResources_1.createGroup('foo');
            group.getExclusiveFieldNames = function () {
                group_get_fields_is_called = true;
            };
            var sut = CommonResources_1.createSut(StackedGroupUi_1.StackedGroupUi, {
                context: context,
                content: content,
                group: group,
                styler: styler,
            });
            sut.getCurrentIndex = sinon.stub().returns(10);
            sut.hasVisibleField = sinon.stub().withArgs(index).returns(false);
            var quote = CommonResources_1.createQuote();
            sut.init(quote);
            sut.removeIndex(index);
            expect(styler_remove_called).to.be.true;
            expect(context_remove_index_is_called).to.be.true;
            expect(group_get_fields_is_called).to.be.true;
        });
    });
});
//# sourceMappingURL=data:application/json;base64, 