"use strict";
/**
 * Test case for DisplayFieldStyler
 *
 *  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 DisplayFieldStyler_1 = require("../../../../src/ui/context/styler/DisplayFieldStyler");
var chai_1 = require("chai");
before(function () {
    this.jsdom = require('jsdom-global')();
});
after(function () {
    this.jsdom();
});
describe('DisplayFieldStyler', function () {
    [
        {
            label: 'setValue calls ElementStyler to style one answer',
            field_name: 'foo',
            answer_ref: 'bar',
            value: '1',
            display_value: 'New York',
            html_content: '<span data-field-name="foo" id="foo_dca320"' +
                'data-answer-ref="bar"></span>',
            expected_calls: 1,
        },
        {
            label: 'setValue calls ElementStyler to style two answers',
            field_name: 'foo',
            answer_ref: 'bar',
            value: '1',
            display_value: 'Detroit',
            html_content: '<span data-field-name="foo" id="foo_dca320"' +
                'data-answer-ref="bar"></span>' +
                '<span data-field-name="foo" id="foobar_dca320"' +
                'data-answer-ref="bar"></span>',
            expected_calls: 2,
        },
    ].forEach(function (_a) {
        var label = _a.label, field_name = _a.field_name, answer_ref = _a.answer_ref, value = _a.value, display_value = _a.display_value, html_content = _a.html_content, expected_calls = _a.expected_calls;
        it(label, function () {
            var index = 1;
            var style_answer_call_count = 0;
            var element_styler = getElementStylerStub();
            var sut = new DisplayFieldStyler_1.DisplayFieldStyler(element_styler, field_name, index);
            element_styler.styleAnswer = function (ref_id, value_to_set) {
                style_answer_call_count++;
                chai_1.expect(ref_id).to.equal(answer_ref);
                chai_1.expect(value_to_set).to.equal(value);
                return display_value;
            };
            var content = document.createElement('dd');
            content.innerHTML = html_content;
            sut.setValue(content, value);
            chai_1.expect(style_answer_call_count).to.equal(expected_calls);
        });
    });
    [
        {
            label: 'setValue styles answer as HTML',
            field_name: 'foo',
            value: '1',
            display_value: 'New York',
            html_content: '<span data-field-name="foo" id="foo_dca320"' +
                ' data-answer-ref="bar" data-field-allow-html="true"></span>',
            expected_html: '<dd><span data-field-name="foo" id="foo_dca320"' +
                ' data-answer-ref="bar" data-field-allow-html="true">New York</span></dd>',
            expected_textcontent: 'New York',
        },
        {
            label: 'setValue styles answer as text',
            field_name: 'foo',
            value: '1',
            display_value: 'Detroit',
            html_content: '<span data-field-name="foo" id="foo_dca320"' +
                ' data-answer-ref="bar"></span>',
            expected_html: '<dd><span data-field-name="foo" id="foo_dca320"' +
                ' data-answer-ref="bar">Detroit</span></dd>',
            expected_textcontent: 'Detroit',
        },
    ].forEach(function (_a) {
        var label = _a.label, field_name = _a.field_name, value = _a.value, display_value = _a.display_value, html_content = _a.html_content, expected_html = _a.expected_html, expected_textcontent = _a.expected_textcontent;
        it(label, function () {
            var index = 1;
            var element_styler = getElementStylerStub();
            var sut = new DisplayFieldStyler_1.DisplayFieldStyler(element_styler, field_name, index);
            element_styler.styleAnswer = function (_, __) {
                return display_value;
            };
            var content = document.createElement('dd');
            content.innerHTML = html_content;
            sut.setValue(content, value);
            var element = content.querySelector('[data-field-name="' + field_name + '"]');
            chai_1.expect(element === null || element === void 0 ? void 0 : element.textContent).to.equal(expected_textcontent);
            chai_1.expect(content === null || content === void 0 ? void 0 : content.outerHTML).to.equal(expected_html);
        });
    });
});
function getElementStylerStub() {
    return {
        getDefault: function (_) { },
        styleAnswer: function (_, __) { },
    };
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGlzcGxheUZpZWxkU3R5bGVyVGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLC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