"use strict";
/**
 * Test case for SubFieldContext
 *
 *  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 SubFieldContext_1 = require("../../../src/ui/context/SubFieldContext");
var chai_1 = require("chai");
before(function () {
    this.jsdom = require('jsdom-global')();
});
after(function () {
    this.jsdom();
});
describe('SubFieldContext', function () {
    [
        {
            label: 'attaches a subfield to its parent',
            content_element_id: 'qcontainer_subfield_single',
            element_id: 'q_subfield_single_0',
            expected: '<dd id="qcontainer_subfield_single">' +
                '<select id="q_subfield_single_type_0" class="foo widget">' +
                '<option id="q_subfield_single_0" value="Foo">Foo</option>' +
                '</select>' +
                '</dd>',
        },
        {
            label: 'attaches a subfield to its parent after its sibling subfields',
            content_element_id: 'qcontainer_subfield',
            element_id: 'q_baz_subfield_0',
            expected: '<dd id="qcontainer_subfield">' +
                '<select id="q_subfield_0" class="foo widget">' +
                '<option id="q_bar_subfield_0" value="Bar">Bar</option>' +
                '<option id="q_qux_subfield_0" value="Qux">Qux</option>' +
                '<option id="q_baz_subfield_0" value="Baz">Baz</option>' +
                '</select>' +
                '</dd>',
        },
    ].forEach(function (_a) {
        var label = _a.label, content_element_id = _a.content_element_id, element_id = _a.element_id, expected = _a.expected;
        it(label, function () {
            var group_content = getGroupContent();
            var content = group_content.querySelector('#' + content_element_id);
            var sut = new SubFieldContext_1.SubFieldContext(document, getStylerStub(), element_id, content);
            // First detach it
            sut.hide();
            chai_1.expect(sut.isAttached()).to.be.false;
            var to_content = document.createElement('dl');
            sut.show(to_content, null);
            var final_content = sut.getFirstOfContentSet();
            chai_1.expect(final_content.outerHTML).to.equal(expected);
            // Ensure isAttached is true for subfield being attached
            chai_1.expect(sut.isAttached()).to.be.true;
        });
    });
    [
        {
            label: 'detaches a subfield from its parent',
            content_element_id: 'qcontainer_subfield_single',
            element_id: 'q_subfield_single_0',
            expected: '<dd id="qcontainer_subfield_single">' +
                '<select id="q_subfield_single_type_0" class="foo widget">' +
                '</select>' +
                '</dd>',
        },
        {
            label: 'detaches a subfield that has sibling subfields from its parent ',
            content_element_id: 'qcontainer_subfield',
            element_id: 'q_baz_subfield_0',
            expected: '<dd id="qcontainer_subfield">' +
                '<select id="q_subfield_0" class="foo widget">' +
                '<option id="q_bar_subfield_0" value="Bar">Bar</option>' +
                '<option id="q_qux_subfield_0" value="Qux">Qux</option>' +
                '</select>' +
                '</dd>',
        },
    ].forEach(function (_a) {
        var label = _a.label, content_element_id = _a.content_element_id, element_id = _a.element_id, expected = _a.expected;
        it(label, function () {
            var group_content = getGroupContent();
            var content = group_content.querySelector('#' + content_element_id);
            var sut = new SubFieldContext_1.SubFieldContext(document, getStylerStub(), element_id, content);
            sut.hide();
            var final_content = sut.getFirstOfContentSet();
            chai_1.expect(final_content.outerHTML).to.equal(expected);
            // Ensure isAttached is false when subfield is removed
            chai_1.expect(sut.isAttached()).to.be.false;
        });
    });
});
function getStylerStub() {
    return {
        setValue: function (_, __) { },
    };
}
function getGroupContent() {
    // Mock group content
    var group = document.createElement('dl');
    group.innerHTML =
        '<dd id="qcontainer_subfield">' +
            '<select id="q_subfield_0" class="foo widget">' +
            '<option id="q_bar_subfield_0" value="Bar">Bar</option>' +
            '<option id="q_baz_subfield_0" value="Baz">Baz</option>' +
            '<option id="q_qux_subfield_0" value="Qux">Qux</option>' +
            '</select>' +
            '</dd>' +
            '<dd id="qcontainer_subfield_single">' +
            '<select id="q_subfield_single_type_0" class="foo widget">' +
            '<option id="q_subfield_single_0" value="Foo">Foo</option>' +
            '</select>' +
            '</dd>';
    return group;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU3ViRmllbGRDb250ZXh0VGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIlN1YkZpZWxkQ29udGV4dFRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBbUJHOztBQUVILDJFQUErRTtBQUkvRSw2QkFBNEI7QUFFNUIsTUFBTSxDQUFDO0lBQ0wsSUFBSSxDQUFDLEtBQUssR0FBRyxPQUFPLENBQUMsY0FBYyxDQUFDLEVBQUUsQ0FBQztBQUN6QyxDQUFDLENBQUMsQ0FBQztBQUVILEtBQUssQ0FBQztJQUNKLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQztBQUNmLENBQUMsQ0FBQyxDQUFDO0FBRUgsUUFBUSxDQUFDLGlCQUFpQixFQUFFO0lBQzFCO1FBQ0U7WUFDRSxLQUFLLEVBQUUsbUNBQW1DO1lBQzFDLGtCQUFrQixFQUFFLDRCQUE0QjtZQUNoRCxVQUFVLEVBQUUscUJBQXFCO1lBQ2pDLFFBQVEsRUFDTixzQ0FBc0M7Z0JBQ3RDLDJEQUEyRDtnQkFDM0QsMkRBQTJEO2dCQUMzRCxXQUFXO2dCQUNYLE9BQU87U0FDVjtRQUNEO1lBQ0UsS0FBSyxFQUFFLCtEQUErRDtZQUN0RSxrQkFBa0IsRUFBRSxxQkFBcUI7WUFDekMsVUFBVSxFQUFFLGtCQUFrQjtZQUM5QixRQUFRLEVBQ04sK0JBQStCO2dCQUMvQiwrQ0FBK0M7Z0JBQy9DLHdEQUF3RDtnQkFDeEQsd0RBQXdEO2dCQUN4RCx3REFBd0Q7Z0JBQ3hELFdBQVc7Z0JBQ1gsT0FBTztTQUNWO0tBQ0YsQ0FBQyxPQUFPLENB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