"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 = require("react-test-renderer");
const QuestionContext_1 = require("../../src/components/context/QuestionContext");
const AnnotationList_1 = __importDefault(require("../../src/components/results/internal/AnnotationList"));
const ResultsContext_1 = require("../../src/components/context/ResultsContext");
const i18n_1 = require("../../src/i18n");
function mkTextAnswer(questionId, displayNumber, maxScore) {
    const textAnswer = document.createElement('text-answer');
    textAnswer.setAttribute('type', 'rich-text');
    textAnswer.setAttribute('max-score', String(maxScore));
    textAnswer.setAttribute('question-number', displayNumber);
    textAnswer.setAttribute('question-id', String(questionId));
    return textAnswer;
}
const defaultScores = {
    questionId: 1,
    answerId: 1,
    pregrading: {
        score: 1,
        annotations: [
            {
                startIndex: 0,
                length: 1,
                message: 'Test pregrading annotation'
            }
        ]
    },
    censoring: {
        scores: [
            { score: 4, shortCode: 'SE3' },
            { score: 3, shortCode: 'SE2' },
            { score: 2, shortCode: 'SE1' }
        ],
        annotations: [
            {
                startIndex: 0,
                length: 1,
                message: 'Test censoring annotation'
            }
        ]
    },
    inspection: { score: 5, shortCodes: ['IN1', 'IN2'] }
};
const defaultAnswer = mkTextAnswer(1, '5.1', 12);
describe('<AnnotationList />', () => {
    let i18n;
    describe('fi-FI', () => {
        beforeAll(() => {
            i18n = (0, i18n_1.initI18n)('fi-FI');
        });
        it('renders empty without score', () => {
            const resultsProps = {
                scores: []
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
        it('renders empty without annotations', () => {
            const resultsProps = {
                scores: [lodash_1.default.pick(defaultScores, 'answerId', 'questionId')]
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
        it('renders with only pregrading annotations', () => {
            const resultsProps = {
                scores: [lodash_1.default.pick(defaultScores, 'pregrading', 'answerId', 'questionId')]
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
        it('filters empty annotations', () => {
            const resultsProps = {
                scores: [
                    {
                        ...lodash_1.default.pick(defaultScores, 'pregrading', 'answerId', 'questionId'),
                        ...{
                            pregrading: {
                                score: 1,
                                annotations: [
                                    {
                                        startIndex: 0,
                                        length: 1,
                                        message: 'Before empty annotation'
                                    },
                                    {
                                        startIndex: 1,
                                        length: 1,
                                        message: ''
                                    },
                                    {
                                        startIndex: 2,
                                        length: 1,
                                        message: 'After empty annotation'
                                    }
                                ]
                            }
                        }
                    }
                ]
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
        it('renders with only censoring annotations', () => {
            const resultsProps = {
                scores: [lodash_1.default.pick(defaultScores, 'censoring', 'answerId', 'questionId')]
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
        it('renders with pregrading and censoring annotations', () => {
            const resultsProps = {
                scores: [defaultScores]
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
        it('renders only pregrading without header on singleGrading in ResultContext', () => {
            const resultsProps = {
                scores: [defaultScores],
                singleGrading: true
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
        it('renders null if no scores and singleGrading in ResultContext', () => {
            const resultsProps = {
                scores: [],
                singleGrading: true
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
    });
    describe('sv-FI', () => {
        it('renders with pregrading and censoring annotations', () => {
            i18n = (0, i18n_1.initI18n)('sv-FI');
            const resultsProps = {
                scores: [defaultScores]
            };
            expect(renderWithContext(resultsProps, [defaultAnswer]).toJSON()).toMatchSnapshot();
        });
    });
    const questionContextProps = {
        answers: [],
        displayNumber: '1',
        hasExternalMaterial: false,
        maxAnswers: 2,
        maxScore: 2,
        level: 2,
        childQuestions: [],
        questionLabelIds: ''
    };
    const resultsContextDefaults = {
        answersByQuestionId: {},
        gradingStructure: { questions: [] },
        scores: [],
        gradingText: '',
        totalScore: 60
    };
    function renderWithContext(results, answers) {
        return (0, react_test_renderer_1.create)(react_1.default.createElement(QuestionContext_1.QuestionContext.Provider, { value: { ...questionContextProps, ...{ answers } } },
            react_1.default.createElement(ResultsContext_1.ResultsContext.Provider, { value: { ...resultsContextDefaults, ...results } },
                react_1.default.createElement(react_i18next_1.I18nextProvider, { i18n: i18n },
                    react_1.default.createElement(AnnotationList_1.default, null)))));
    }
});
//# sourceMappingURL=AnnotationList.test.js.map