"use strict";
// This file was moved from the `server` package to here and `server` has `strictNullChecks` disabled.
// This code was originally written with the assumption that `widget.children` is never undefined, despite the type saying otherwise.
// So we are using `!` to assert that `widget.children` is never undefined.
// Note that `!` does not change the runtime behavior of the code so the code will work the same way as before.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const vitest_1 = require("vitest");
const container_js_1 = __importDefault(require("../../utils/pageFixtures/v4/container.js"));
const empty_js_1 = __importDefault(require("../../utils/pageFixtures/v4/empty.js"));
const form_js_1 = __importDefault(require("../../utils/pageFixtures/v4/form.js"));
const grid_js_1 = __importDefault(require("../../utils/pageFixtures/v4/grid.js"));
const slideout_js_1 = __importDefault(require("../../utils/pageFixtures/v4/slideout.js"));
const tabs_js_1 = __importDefault(require("../../utils/pageFixtures/v4/tabs.js"));
const v4to5_js_1 = require("./v4to5.js");
const positionProps = [
    'leftColumn',
    'rightColumn',
    'topRow',
    'bottomRow',
    'minHeight',
    'parentColumnSpace',
    'parentRowSpace',
    'snapColumns',
    'snapRows'
];
function getStaticProps(widget) {
    const output = {};
    positionProps.forEach((key) => {
        output[key] = widget[key];
    });
    return output;
}
(0, vitest_1.describe)('version 4 to version 5', () => {
    (0, vitest_1.it)('should migrate the top-level app', () => {
        const migrated = (0, v4to5_js_1.migrate4to5)((0, lodash_1.cloneDeep)(empty_js_1.default));
        (0, vitest_1.expect)(getStaticProps(migrated)).toEqual({
            topRow: 0,
            bottomRow: 104,
            minHeight: 1292,
            snapColumns: 96,
            snapRows: 104
        });
    });
    (0, vitest_1.it)('should migrate a grid component and its children', () => {
        const migrated = (0, v4to5_js_1.migrate4to5)((0, lodash_1.cloneDeep)(grid_js_1.default));
        const grid = migrated.children[0];
        (0, vitest_1.expect)(getStaticProps(grid)).toEqual({
            snapColumns: 11 * 6,
            leftColumn: 1 * 6,
            rightColumn: 12 * 6,
            topRow: 4 * 3,
            bottomRow: 21 * 3
        });
        const gridCanvas = grid.children[0];
        (0, vitest_1.expect)(getStaticProps(gridCanvas)).toEqual({
            minHeight: 680,
            topRow: 0,
            snapColumns: 22,
            bottomRow: 51,
            snapRows: 51
        });
        const gridContainer = gridCanvas.children[0];
        (0, vitest_1.expect)(getStaticProps(gridContainer)).toEqual({
            leftColumn: 0,
            rightColumn: 22,
            topRow: 0,
            bottomRow: 7 * 3,
            snapColumns: 22,
            snapRows: undefined
        });
        const gridCanvas2 = gridContainer.children[0];
        (0, vitest_1.expect)(getStaticProps(gridCanvas2)).toEqual({
            topRow: 0,
            leftColumn: undefined,
            minHeight: undefined,
            parentColumnSpace: undefined,
            parentRowSpace: undefined,
            rightColumn: undefined,
            snapColumns: 22,
            bottomRow: 21,
            snapRows: 21
        });
        const gridImage = gridCanvas2.children[0];
        (0, vitest_1.expect)(getStaticProps(gridImage)).toEqual({
            leftColumn: 0,
            rightColumn: 22,
            snapColumns: 22,
            topRow: 0,
            bottomRow: 4 * 3
        });
    });
    (0, vitest_1.it)('should migrate a slideout component and its children', () => {
        const migrated = (0, v4to5_js_1.migrate4to5)((0, lodash_1.cloneDeep)(slideout_js_1.default));
        const slideout = migrated.children[0];
        (0, vitest_1.expect)(getStaticProps(slideout)).toEqual({
            snapColumns: 6,
            snapRows: undefined,
            leftColumn: 3 * 6,
            rightColumn: 4 * 6,
            topRow: 0,
            bottomRow: 1 * 3
        });
        const slideoutCanvas = slideout.children[0];
        (0, vitest_1.expect)(getStaticProps(slideoutCanvas)).toEqual({
            snapColumns: 80,
            topRow: 0,
            snapRows: 69,
            bottomRow: 67,
            minHeight: 800
        });
        const slideoutTitle = slideoutCanvas.children[0];
        (0, vitest_1.expect)(getStaticProps(slideoutTitle)).toEqual({
            snapColumns: 50,
            leftColumn: 0,
            rightColumn: 50, // Scaled up from before
            topRow: 0,
            bottomRow: 3
        });
    });
    (0, vitest_1.it)('should migrate a tabs component and its children', () => {
        const migrated = (0, v4to5_js_1.migrate4to5)((0, lodash_1.cloneDeep)(tabs_js_1.default));
        const tabs = migrated.children[0];
        (0, vitest_1.expect)(getStaticProps(tabs)).toEqual({
            snapColumns: 8 * 6,
            leftColumn: 1 * 6,
            rightColumn: 9 * 6,
            topRow: 2 * 3,
            bottomRow: 9 * 3
        });
        const firstTab = tabs.children[0];
        (0, vitest_1.expect)(getStaticProps(firstTab)).toEqual({
            snapColumns: 48,
            topRow: 0,
            bottomRow: 18,
            snapRows: 18
        });
        const elementInTab = firstTab.children[0];
        (0, vitest_1.expect)(getStaticProps(elementInTab)).toEqual({
            snapColumns: 72 - 18,
            leftColumn: 18,
            rightColumn: 72,
            topRow: 0,
            bottomRow: 45,
            snapRows: undefined
        });
    });
    (0, vitest_1.it)('should migrate a form component and its children', () => {
        const migrated = (0, v4to5_js_1.migrate4to5)((0, lodash_1.cloneDeep)(form_js_1.default));
        const form = migrated.children[0];
        (0, vitest_1.expect)(getStaticProps(form)).toEqual({
            snapColumns: 7 * 6,
            snapRows: undefined,
            leftColumn: 3 * 6,
            rightColumn: 10 * 6,
            topRow: 8 * 3,
            bottomRow: 21 * 3
        });
        const formCanvas = form.children[0];
        (0, vitest_1.expect)(getStaticProps(formCanvas)).toEqual({
            snapColumns: 42,
            topRow: 0,
            bottomRow: 39,
            snapRows: 39,
            minHeight: 520
        });
        const formTitle = formCanvas.children[0];
        (0, vitest_1.expect)(getStaticProps(formTitle)).toEqual({
            leftColumn: 0,
            rightColumn: 31,
            snapColumns: 31,
            topRow: 0,
            bottomRow: 3
        });
        const formInput = formCanvas.children[3];
        (0, vitest_1.expect)(getStaticProps(formInput)).toEqual({
            leftColumn: 0,
            rightColumn: 7,
            snapColumns: 7,
            // Normally would be topRow: 3, but there is an adjustment for inputs
            topRow: 4,
            bottomRow: 9
        });
        const formInputNoLabel = formCanvas.children[4];
        (0, vitest_1.expect)(getStaticProps(formInputNoLabel)).toEqual({
            leftColumn: 0,
            rightColumn: 7,
            snapColumns: 7,
            // This input has a missing label so it gets migrated at full height
            topRow: 3,
            bottomRow: 9
        });
    });
    (0, vitest_1.it)('should migrate a complex app using containers', () => {
        const migrated = (0, v4to5_js_1.migrate4to5)((0, lodash_1.cloneDeep)(container_js_1.default));
        (0, vitest_1.expect)(getStaticProps(migrated)).toEqual({
            topRow: 0,
            bottomRow: 140,
            minHeight: 1292,
            snapColumns: 96,
            snapRows: 140
        });
        const containerElement = migrated.children[0];
        (0, vitest_1.expect)(getStaticProps(containerElement)).toEqual({
            topRow: 6,
            bottomRow: 120,
            leftColumn: 0,
            rightColumn: 96,
            snapColumns: 96
        });
        const containerCanvas = containerElement.children[0];
        (0, vitest_1.expect)(getStaticProps(containerCanvas)).toEqual({
            topRow: 0,
            bottomRow: 114,
            snapRows: 114,
            minHeight: 400,
            snapColumns: 96
        });
        const tabComponent = containerCanvas.children[0];
        (0, vitest_1.expect)(getStaticProps(tabComponent)).toEqual({
            topRow: 0,
            leftColumn: 0,
            bottomRow: 108,
            rightColumn: 96,
            snapColumns: 96
        });
        const tabCanvas = tabComponent.children[1];
        (0, vitest_1.expect)(getStaticProps(tabCanvas)).toEqual({
            bottomRow: 105,
            snapRows: 105,
            snapColumns: 96,
            topRow: 0
        });
        const tabTitle = tabCanvas.children[0];
        (0, vitest_1.expect)(getStaticProps(tabTitle)).toEqual({
            topRow: 0,
            bottomRow: 3,
            leftColumn: 30,
            rightColumn: 60,
            snapColumns: 30
        });
    });
});
//# sourceMappingURL=v4to5.test.js.map