"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 = require("lodash");
const vitest_1 = require("vitest");
const container_js_1 = __importDefault(require("../../../utils/pageFixtures/v4/container.js"));
const v4to5_js_1 = require("../v4to5.js");
const v5to6_js_1 = require("../v5to6.js");
const migrateToDimensions_js_1 = require("./migrateToDimensions.js");
const migrateToSections_js_1 = require("./migrateToSections.js");
(0, vitest_1.describe)('version 7 to version 8', () => {
    (0, vitest_1.test)('should migrate a page with a container widget', () => {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        const v7 = (0, migrateToSections_js_1.migrateToSections)((0, v5to6_js_1.migrate5to6)((0, v4to5_js_1.migrate4to5)((0, lodash_1.cloneDeep)(container_js_1.default))));
        const v8 = (0, migrateToDimensions_js_1.migrateToDimensions)((0, lodash_1.cloneDeep)(v7));
        // What are we testing?
        // Check that each Widget that is a child has a left, top, width, height
        // Check that each CanvasWidget has a layoutType, gridColumn
        // Check that minHeight has been migrated to a Dimension object of type 'gridUnit'
        // Check that snapColumns, snapRows have been migrated to gridColumns and don't exist anymore
        // Do this for all children recursively
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        const checkWidget = (parent, old) => {
            if (parent.children) {
                parent.children.forEach((child) => {
                    const children = child.children;
                    const oldChild = old.children.find((c) => c.widgetId === child.widgetId);
                    // Use the following to debug to see what is being compared
                    // console.log(child, oldChild);
                    if (child.type === 'CANVAS_WIDGET') {
                        (0, vitest_1.expect)(child).toHaveProperty('layout');
                        (0, vitest_1.expect)(child).toHaveProperty('gridColumns');
                    }
                    if (parent.type === 'CANVAS_WIDGET' && parent.layout === 'FIXED_GRID') {
                        (0, vitest_1.expect)(child).toHaveProperty('left');
                        (0, vitest_1.expect)(child).toHaveProperty('top');
                        (0, vitest_1.expect)(child).toHaveProperty('width');
                        (0, vitest_1.expect)(child).toHaveProperty('height');
                        // Assert minHeight has been migrated to a Dimension object of type 'gridUnit'
                        if (child.minHeight) {
                            (0, vitest_1.expect)(child.minHeight).toHaveProperty('mode');
                            (0, vitest_1.expect)(child.minHeight.mode).toEqual('gridUnit');
                        }
                        // assert CONTAINERS
                        if (parent.type === 'CONTAINER_WIDGET' || parent.type === 'FORM_WIDGET' || parent.type === 'TABS_WIDGET') {
                            (0, vitest_1.expect)(child).toHaveProperty('padding');
                            (0, vitest_1.expect)(child.padding?.left?.value).toEqual(16);
                            (0, vitest_1.expect)(child.padding?.top?.value).toEqual(12);
                            (0, vitest_1.expect)(child.padding?.right?.value).toEqual(16);
                            (0, vitest_1.expect)(child.padding?.bottom?.value).toEqual(12);
                        }
                        else {
                            // there should be no padding
                            (0, vitest_1.expect)(child).not.toHaveProperty('padding');
                        }
                        // Assert left, top, width, height === old values
                        (0, vitest_1.expect)(child.left.value).toEqual(oldChild.leftColumn);
                        (0, vitest_1.expect)(child.left.value + child.width.value).toEqual(oldChild.rightColumn);
                        (0, vitest_1.expect)(child.top.value).toEqual(oldChild.topRow);
                        (0, vitest_1.expect)(child.top.value + child.height.value).toEqual(oldChild.bottomRow);
                    }
                    (0, vitest_1.expect)(child).not.toHaveProperty('snapColumns');
                    (0, vitest_1.expect)(child).not.toHaveProperty('snapRows');
                    (0, vitest_1.expect)(child).not.toHaveProperty('leftColumn');
                    (0, vitest_1.expect)(child).not.toHaveProperty('rightColumn');
                    (0, vitest_1.expect)(child).not.toHaveProperty('topRow');
                    (0, vitest_1.expect)(child).not.toHaveProperty('bottomRow');
                    (0, vitest_1.expect)(child).not.toHaveProperty('widgetLastChange');
                    checkWidget({ ...child, children }, old.children.find((c) => c.widgetId === child.widgetId));
                });
            }
        };
        checkWidget({ children: [v8] }, { children: [v7] });
    });
});
//# sourceMappingURL=migrateToDimensions.test.js.map