"use strict";
/**
 * Test case for FieldContext
 *
 *  Copyright (C) 2010-2019 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 FieldContextFactory_1 = require("../../../src/ui/context/FieldContextFactory");
var FieldContext_1 = require("../../../src/ui/context/FieldContext");
var FieldContextStore_1 = require("../../../src/ui/context/FieldContextStore");
var SubFieldContext_1 = require("../../../src/ui/context/SubFieldContext");
var TableCellFieldContext_1 = require("../../../src/ui/context/TableCellFieldContext");
var chai_1 = require("chai");
describe('FieldContextFactory', function () {
    [
        {
            label: 'creates new FieldContext',
            is_subfield: false,
            field_name: 'baz',
            expected: FieldContext_1.FieldContext,
        },
        {
            label: 'creates new SubFieldContext',
            is_subfield: true,
            field_name: 'baz',
            expected: SubFieldContext_1.SubFieldContext,
        },
    ].forEach(function (_a) {
        var label = _a.label, is_subfield = _a.is_subfield, field_name = _a.field_name, expected = _a.expected;
        it(label, function () {
            var styler_stub = getFieldStylerStub();
            var styler_factory = getFieldStylerFactory();
            var create_styler_is_called = false;
            styler_factory.create = function (_, __) {
                create_styler_is_called = true;
                return styler_stub;
            };
            var sut = new FieldContextFactory_1.FieldContextFactory(document, styler_factory);
            var content = document.createElement('div');
            var given = sut.create(field_name, 0, content, is_subfield);
            chai_1.expect(create_styler_is_called).to.be.true;
            chai_1.expect(given).to.be.instanceOf(expected);
        });
    });
    it('creates new TableCellFieldContext', function () {
        var styler_factory = getFieldStylerFactory();
        var sut = new FieldContextFactory_1.FieldContextFactory(document, styler_factory);
        var table = document.createElement('table');
        table.innerHTML =
            '<tr>' +
                '<td>' +
                '<input type="text" id="q_field_0">' +
                '</td>' +
                '</tr>';
        var content = table.querySelector('td');
        var given = sut.create('q_field_0', 0, content, false);
        chai_1.expect(given).to.be.instanceOf(TableCellFieldContext_1.TableCellFieldContext);
    });
    it('creates new FieldContextStore', function () {
        var styler_factory = getFieldStylerFactory();
        var is_internal = true;
        var sut = new FieldContextFactory_1.FieldContextFactory(document, styler_factory);
        var parent = document.createElement('div');
        parent.innerHTML =
            '<dl class="">' +
                '<dt id="qlabel_checkbox_foo" >Foo</dt>' +
                '<dd id="qcontainer_checkbox_foo">' +
                '<input type="checkbox" id="q_checkbox_foo_n_0">' +
                '</dd>' +
                '</dl>';
        var content = parent.querySelector('#qcontainer_checkbox_foo');
        var sibling = parent.querySelector('#qlabel_checkbox_foo');
        var given = sut.createStore('foo', content, sibling, is_internal);
        chai_1.expect(given).to.be.instanceOf(FieldContextStore_1.FieldContextStore);
    });
});
function getFieldStylerFactory() {
    return {
        create: function (_, __) {
            return;
        },
    };
}
function getFieldStylerStub() {
    return {
        setValue: function (_, __) { },
    };
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRmllbGRDb250ZXh0RmFjdG9yeVRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJGaWVsZENvbnRleHRGYWN0b3J5VGVzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FtQkc7O0FBSUgsbUZBQXVGO0FBQ3ZGLHFFQUk4QztBQUM5QywrRUFBNEU7QUFFNUUsMkVBQXdFO0FBQ3hFLHVGQUFvRjtBQUVwRiw2QkFBNEI7QUFFNUIsUUFBUSxDQUFDLHFCQUFxQixFQUFFO0lBQzlCO1FBQ0U7WUFDRSxLQUFLLEVBQUUsMEJBQTBCO1lB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