"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 canvases_js_1 = __importDefault(require("../../utils/pageFixtures/v7/canvases.js"));
const grids_and_forms_js_1 = __importDefault(require("../../utils/pageFixtures/v7/grids_and_forms.js"));
const images_js_1 = __importDefault(require("../../utils/pageFixtures/v7/images.js"));
const initial_app_js_1 = __importDefault(require("../../utils/pageFixtures/v7/initial_app.js"));
const nested_containers_js_1 = __importDefault(require("../../utils/pageFixtures/v7/nested_containers.js"));
const v7to8_js_1 = require("./v7to8.js");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const getWidgetNameToProperty = (widget, widgetTypes, propertyNames, obj) => {
    if (widgetTypes.includes(widget.type)) {
        propertyNames.forEach((propertyName) => {
            obj[widget.widgetName] = {
                ...obj[widget.widgetName],
                [propertyName]: widget[propertyName]
            };
        });
    }
    if (widget.children) {
        widget.children.forEach((child) => getWidgetNameToProperty(child, widgetTypes, propertyNames, obj));
    }
};
const defaultPadding = {
    bottom: {
        mode: 'px',
        value: 12
    },
    left: {
        mode: 'px',
        value: 16
    },
    right: {
        mode: 'px',
        value: 16
    },
    top: {
        mode: 'px',
        value: 12
    }
};
(0, vitest_1.describe)('version 7 to version 8', () => {
    (0, vitest_1.it)(`returns a new object`, () => {
        const originalInput = (0, lodash_1.cloneDeep)(initial_app_js_1.default);
        const migrated = (0, v7to8_js_1.migrate7to8)(originalInput);
        (0, vitest_1.expect)(migrated).not.toStrictEqual(originalInput);
    });
    (0, vitest_1.it)('should migrate an initial app DSL', () => {
        const migrated = (0, v7to8_js_1.migrate7to8)((0, lodash_1.cloneDeep)(initial_app_js_1.default));
        // app will be the mosty same, apart from the root containers padding + the version
        const migratedVersion = (0, lodash_1.get)(migrated, 'version');
        const initialVersion = (0, lodash_1.get)(initial_app_js_1.default, 'version');
        (0, vitest_1.expect)(migratedVersion).toEqual(8);
        (0, vitest_1.expect)(initialVersion).toEqual(7);
        const migratedPadding = (0, lodash_1.get)(migrated, 'children[0].children[0].padding');
        const initialPadding = (0, lodash_1.get)(initial_app_js_1.default, 'children[0].children[0].padding');
        (0, vitest_1.expect)(migratedPadding).toBeUndefined();
        (0, vitest_1.expect)(initialPadding).toEqual(defaultPadding);
        const restOfMigratedDsl = (0, lodash_1.omit)(migrated, ['version', 'children[0].children[0].padding']);
        const restOfInitialDsl = (0, lodash_1.omit)(initial_app_js_1.default, ['version', 'children[0].children[0].padding']);
        (0, vitest_1.expect)(restOfMigratedDsl).toEqual(restOfInitialDsl);
    });
    (0, vitest_1.it)('should migrate container widgets background color styles', () => {
        const initialBackgrounds = {};
        const migratedBackgrounds = {};
        getWidgetNameToProperty(nested_containers_js_1.default, ['CONTAINER_WIDGET', 'CANVAS_WIDGET'], ['backgroundColor'], initialBackgrounds);
        const migrated = (0, v7to8_js_1.migrate7to8)((0, lodash_1.cloneDeep)(nested_containers_js_1.default));
        getWidgetNameToProperty(migrated, ['CONTAINER_WIDGET', 'CANVAS_WIDGET'], ['backgroundColor'], migratedBackgrounds);
        (0, vitest_1.expect)(initialBackgrounds).toEqual({
            Canvas1: { backgroundColor: 'none' },
            Container1: { backgroundColor: '#FFFFFF' },
            Canvas2: {},
            Container2: { backgroundColor: 'white' },
            Canvas3: {},
            Container3: { backgroundColor: '' },
            Canvas4: {},
            Container4: { backgroundColor: 'red' },
            Canvas5: {}
        });
        (0, vitest_1.expect)(migratedBackgrounds).toEqual({
            Canvas1: { backgroundColor: 'none' },
            Container1: { backgroundColor: undefined },
            Canvas2: { backgroundColor: 'none' },
            Container2: { backgroundColor: undefined },
            Canvas3: { backgroundColor: 'none' },
            Container3: { backgroundColor: 'none' },
            Canvas4: { backgroundColor: 'none' },
            Container4: { backgroundColor: 'red' },
            Canvas5: { backgroundColor: 'none' }
        });
    });
    (0, vitest_1.it)('should migrate grid and form widgets background color styles', () => {
        const initialBackgrounds = {};
        const migratedBackgrounds = {};
        getWidgetNameToProperty(grids_and_forms_js_1.default, ['CONTAINER_WIDGET', 'CANVAS_WIDGET', 'FORM_WIDGET', 'IMAGE_WIDGET'], ['backgroundColor'], initialBackgrounds);
        const migrated = (0, v7to8_js_1.migrate7to8)((0, lodash_1.cloneDeep)(grids_and_forms_js_1.default));
        getWidgetNameToProperty(migrated, ['CONTAINER_WIDGET', 'CANVAS_WIDGET', 'FORM_WIDGET', 'IMAGE_WIDGET'], ['backgroundColor'], migratedBackgrounds);
        (0, vitest_1.expect)(initialBackgrounds).toEqual({
            Canvas1: { backgroundColor: 'none' },
            Form3: { backgroundColor: '' },
            Canvas6: {},
            Canvas2: {},
            Container1: { backgroundColor: 'white' },
            Canvas3: {},
            Image1: {},
            Form1: { backgroundColor: 'white' },
            Canvas4: {},
            Form2: { backgroundColor: 'black' },
            Canvas5: {}
        });
        (0, vitest_1.expect)(migratedBackgrounds).toEqual({
            Canvas1: { backgroundColor: 'none' },
            Form3: { backgroundColor: 'none' },
            Canvas6: { backgroundColor: 'none' },
            Canvas2: { backgroundColor: 'none' },
            Container1: { backgroundColor: undefined },
            Canvas3: { backgroundColor: 'none' },
            Image1: {},
            Form1: { backgroundColor: undefined },
            Canvas4: { backgroundColor: 'none' },
            Form2: { backgroundColor: 'black' },
            Canvas5: { backgroundColor: 'none' }
        });
    });
    (0, vitest_1.it)('should migrate image border radii', () => {
        const initialBorderRadii = {};
        const migratedBorderRadii = {};
        getWidgetNameToProperty(images_js_1.default, ['IMAGE_WIDGET'], ['borderRadius'], initialBorderRadii);
        const migrated = (0, v7to8_js_1.migrate7to8)((0, lodash_1.cloneDeep)(images_js_1.default));
        getWidgetNameToProperty(migrated, ['IMAGE_WIDGET'], ['borderRadius'], migratedBorderRadii);
        (0, vitest_1.expect)(initialBorderRadii).toEqual({ Image3: { borderRadius: '' }, Image2: { borderRadius: '0px' }, Image1: { borderRadius: '4px' } });
        (0, vitest_1.expect)(migratedBorderRadii).toEqual({
            Image3: { borderRadius: '0px' },
            Image2: { borderRadius: '0px' },
            Image1: { borderRadius: undefined }
        });
    });
    (0, vitest_1.it)('should migrate padding property', () => {
        const initialPaddings = {};
        const migratedPaddings = {};
        getWidgetNameToProperty(canvases_js_1.default, ['CANVAS_WIDGET'], ['padding'], initialPaddings);
        const migrated = (0, v7to8_js_1.migrate7to8)((0, lodash_1.cloneDeep)(canvases_js_1.default));
        getWidgetNameToProperty(migrated, ['CANVAS_WIDGET'], ['padding'], migratedPaddings);
        (0, vitest_1.expect)(initialPaddings).toEqual({
            Canvas1: {
                padding: defaultPadding
            },
            Canvas10: {
                padding: undefined
            },
            Canvas2: {
                padding: defaultPadding
            },
            Canvas3: {
                padding: defaultPadding
            },
            Canvas4: {
                padding: defaultPadding
            },
            Canvas8: {
                padding: defaultPadding
            },
            Canvas9: {
                padding: {
                    top: {
                        value: 24,
                        mode: 'px'
                    },
                    bottom: {
                        value: 12,
                        mode: 'px'
                    },
                    left: {
                        value: 16,
                        mode: 'px'
                    },
                    right: {
                        value: 16,
                        mode: 'px'
                    }
                }
            }
        });
        (0, vitest_1.expect)(migratedPaddings).toEqual({
            Canvas1: {
                padding: undefined
            },
            Canvas10: {
                padding: {
                    bottom: {
                        mode: 'px',
                        value: 0
                    },
                    left: {
                        mode: 'px',
                        value: 0
                    },
                    right: {
                        mode: 'px',
                        value: 0
                    },
                    top: {
                        mode: 'px',
                        value: 0
                    }
                }
            },
            Canvas2: {
                padding: undefined
            },
            Canvas3: {
                padding: undefined
            },
            Canvas4: {
                padding: undefined
            },
            Canvas8: {
                padding: undefined
            },
            Canvas9: {
                padding: {
                    top: {
                        value: 24,
                        mode: 'px'
                    },
                    bottom: {
                        value: 12,
                        mode: 'px'
                    },
                    left: {
                        value: 16,
                        mode: 'px'
                    },
                    right: {
                        value: 16,
                        mode: 'px'
                    }
                }
            }
        });
    });
});
//# sourceMappingURL=v7to8.test.js.map