"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = __importDefault(require("lodash"));
const react_1 = __importDefault(require("react"));
const react_i18next_1 = require("react-i18next");
const react_test_renderer_1 = __importDefault(require("react-test-renderer"));
const AnsweringInstructions_1 = __importDefault(require("../src/components/AnsweringInstructions"));
const i18n_1 = require("../src/i18n");
describe('<AnsweringInstructions />', () => {
    let i18n;
    beforeAll(() => {
        i18n = (0, i18n_1.initI18n)('fi-FI');
    });
    describe('question', () => {
        it('numerals', () => {
            expectRendering({
                maxAnswers: 1,
                elementType: 'question',
                childQuestions: mkQuestions(range(1, 10, '1.'))
            });
            expectRendering({
                maxAnswers: 5,
                elementType: 'question',
                childQuestions: mkQuestions(range(1, 10, '1.'))
            });
        });
        it('2 child questions and maxAnswers = 1', () => {
            expectRendering({
                maxAnswers: 1,
                elementType: 'question',
                childQuestions: mkQuestions(range(1, 2, '1.'))
            });
        });
        it('fallback', () => {
            expectRendering({
                maxAnswers: 11,
                elementType: 'question',
                childQuestions: mkQuestions(range(1, 12, '1.'))
            });
        });
    });
    describe('section', () => {
        it('numerals', () => {
            expectRendering({
                maxAnswers: 1,
                elementType: 'section',
                childQuestions: mkQuestions(range(1, 10))
            });
            expectRendering({
                maxAnswers: 5,
                elementType: 'section',
                childQuestions: mkQuestions(range(1, 10))
            });
        });
        it('2 child questions and maxAnswers = 1', () => {
            expectRendering({
                maxAnswers: 1,
                elementType: 'section',
                childQuestions: mkQuestions(range(1, 2))
            });
        });
        it('fallback', () => {
            expectRendering({
                minAnswers: 2,
                maxAnswers: 5,
                elementType: 'section',
                childQuestions: mkQuestions(range(1, 12))
            });
            expectRendering({
                maxAnswers: 11,
                elementType: 'section',
                childQuestions: mkQuestions(range(1, 12))
            });
        });
    });
    function range(start, end, prefix = '') {
        return lodash_1.default.range(start, end + 1).map(n => `${prefix}${n}`);
    }
    function expectRendering(props) {
        const container = react_test_renderer_1.default.create(react_1.default.createElement(react_i18next_1.I18nextProvider, { i18n: i18n },
            react_1.default.createElement(AnsweringInstructions_1.default, { ...props })));
        expect(container.toJSON()).toMatchSnapshot();
    }
    function mkQuestions(displayNumbers) {
        return displayNumbers.map(displayNumber => {
            const question = document.createElement('question');
            question.setAttribute('display-number', displayNumber);
            return question;
        });
    }
});
//# sourceMappingURL=AnsweringInstructions.test.js.map