"use strict";
/**
 * Test case for CheckboxFieldStyler
 *
 *  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 CheckboxFieldStyler_1 = require("../../../../src/ui/context/styler/CheckboxFieldStyler");
var chai_1 = require("chai");
before(function () {
    this.jsdom = require('jsdom-global')();
});
after(function () {
    this.jsdom();
});
describe('CheckboxFieldStyler', function () {
    [
        {
            label: 'setValue sets value true for 2nd checkbox',
            field_name: 'foo',
            value: '1',
            html_content: '<input type="checkbox" value="0" data-field-name="foo" id="q_checkbox_foo_n_0">' +
                '<input type="checkbox" value="1" data-field-name="foo" id="q_checkbox_foo_y_0">',
            expected_first_checkbox: false,
            expected_second_checkbox: true,
        },
        {
            label: 'setValue sets value true for 1st checkbox',
            field_name: 'bar',
            value: '0',
            html_content: '<input type="checkbox" value="0" data-field-name="bar" id="q_checkbox_bar_n_0">' +
                '<input type="checkbox" value="1" data-field-name="bar" id="q_checkbox_bar_y_0">',
            expected_first_checkbox: true,
            expected_second_checkbox: false,
        },
    ].forEach(function (_a) {
        var label = _a.label, field_name = _a.field_name, value = _a.value, html_content = _a.html_content, expected_first_checkbox = _a.expected_first_checkbox, expected_second_checkbox = _a.expected_second_checkbox;
        it(label, function () {
            var index = 1;
            var content = document.createElement('dd');
            content.innerHTML = html_content;
            var sut = new CheckboxFieldStyler_1.CheckboxFieldStyler(field_name, index);
            sut.setValue(content, value);
            // Now check the elements are the values were set
            var elements = content.querySelectorAll('[data-field-name="' + field_name + '"]');
            var checkbox_1 = elements[0];
            var checkbox_2 = elements[1];
            chai_1.expect(checkbox_1.checked).to.equal(expected_first_checkbox);
            chai_1.expect(checkbox_2.checked).to.equal(expected_second_checkbox);
        });
    });
    it('finds legacy radios in content parent element', function () {
        var index = 0;
        var field_name = 'supplier';
        var value = 'Dewey';
        // Simulate the td content has a parent row
        // where the inputs we are searching for
        // are found in the content and a sibling in its parent
        var parentContent = document.createElement('tr');
        var content = document.createElement('td');
        content.innerHTML =
            '<input type="radio" value="Huey" id="q_supplier_bar_0" data-field-name="supplier">';
        var content2 = document.createElement('td');
        content2.innerHTML =
            '<input type="radio" value="Dewey" id="q_supplier_foo_0" data-field-name="supplier">';
        parentContent.appendChild(content);
        parentContent.appendChild(content2);
        var sut = new CheckboxFieldStyler_1.CheckboxFieldStyler(field_name, index);
        sut.setValue(content, value);
        // Now check the elements are the values were set
        var elements = parentContent.querySelectorAll('[data-field-name="' + field_name + '"]');
        var radio_1 = elements[0];
        var radio_2 = elements[1];
        chai_1.expect(radio_1.checked).to.equal(false);
        chai_1.expect(radio_2.checked).to.equal(true);
    });
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2hlY2tib3hGaWVsZFN0eWxlclRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJDaGVja2JveEZpZWxkU3R5bGVyVGVzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FtQkc7O0FBRUgsNkZBQWlHO0FBR2pHLDZCQUE0QjtBQUU1QixNQUFNLENBQUM7SUFDTCxJQUFJLENBQUMsS0FBSyxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsRUFBRSxDQUFDO0FBQ3pDLENBQUMsQ0FBQyxDQUFDO0FBRUgsS0FBSyxDQUFDO0lBQ0osSUFBSSxDQUFDLEtBQU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