"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 });
/* eslint-disable @typescript-eslint/no-explicit-any */
const lodash_1 = require("lodash");
const vitest_1 = require("vitest");
const container_js_1 = __importDefault(require("../../utils/pageFixtures/v4/container.js"));
const codeTrigger_js_1 = __importDefault(require("../../utils/pageFixtures/v5/codeTrigger.js"));
const complexTriggers_js_1 = __importDefault(require("../../utils/pageFixtures/v5/complexTriggers.js"));
const duplicateTriggers_js_1 = __importDefault(require("../../utils/pageFixtures/v5/duplicateTriggers.js"));
const missingTriggers_js_1 = __importDefault(require("../../utils/pageFixtures/v5/missingTriggers.js"));
const v5to6_js_1 = require("./v5to6.js");
(0, vitest_1.describe)('version 5 to version 6', () => {
    (0, vitest_1.it)('should migrate simple button code', () => {
        const migrated = (0, v5to6_js_1.migrate5to6)((0, lodash_1.cloneDeep)(container_js_1.default));
        const button = migrated.children[0].children[0].children[0].children[0].children[0];
        (0, vitest_1.expect)(button.onClick).toEqual([{ id: 'id0', type: 'controlSlideout', name: 'Slideout_Trigger_the_BOT', direction: 'open' }]);
        (0, vitest_1.expect)(button.dynamicTriggerPathList).toEqual([{ key: 'onClick' }]);
    });
    (0, vitest_1.it)('should not migrate code that uses special character', () => {
        const migrated = (0, v5to6_js_1.migrate5to6)((0, lodash_1.cloneDeep)(container_js_1.default));
        const button1 = migrated.children[0].children[0].children[0].children[1].children[1].children[0].children[0];
        const button2 = migrated.children[0].children[0].children[0].children[1].children[1].children[0].children[1];
        (0, vitest_1.expect)(button1.onSubmit).toEqual([{ id: 'id0', type: 'runJs', code: 'API_invoice_header.run()' }]);
        (0, vitest_1.expect)(button2.onSubmit).toEqual([{ id: 'id0', type: 'executeApi', apiNames: ['API_invoice_header'] }]);
        (0, vitest_1.expect)(button1.dynamicTriggerPathList).toContainEqual({ key: 'onSubmit' });
        (0, vitest_1.expect)(button2.dynamicTriggerPathList).toEqual([{ key: 'onSubmit' }]);
    });
    (0, vitest_1.it)('should migrate a table button with string', () => {
        const migrated = (0, v5to6_js_1.migrate5to6)((0, lodash_1.cloneDeep)(container_js_1.default));
        const table = migrated.children[0].children[0].children[0].children[1].children[3];
        (0, vitest_1.expect)(table.primaryColumns.customColumn3.onClick).toEqual([
            { id: 'id0', type: 'runJs', code: 'API_Icp_Payroll_Item.run(); slideout_icp_payroll_items.open()' }
        ]);
        (0, vitest_1.expect)(table.dynamicTriggerPathList).toContainEqual({ key: 'primaryColumns.customColumn3.onClick' });
    });
    (0, vitest_1.it)('should migrate a dynamic navigateTo URL', () => {
        const widget = {
            text: 'Trigger the BOT',
            type: 'BUTTON_WIDGET',
            topRow: 1,
            onClick: ['{{navigateTo("https://google.com?q=" + Input1.value)}}'],
            parentId: 'nhcpl240ad',
            widgetId: '33wah1ou3a',
            bottomRow: 2,
            isLoading: false,
            isVisible: true,
            textColor: '#000000',
            isDisabled: false,
            leftColumn: 1,
            widgetName: 'Button9',
            buttonStyle: 'PRIMARY_BUTTON',
            rightColumn: 7,
            parentRowSpace: 40,
            backgroundColor: '#FF9F35',
            parentColumnSpace: 47.625,
            dynamicBindingPathList: [
                {
                    key: 'onClick'
                }
            ],
            dynamicTriggerPathList: [
                {
                    key: 'onClick'
                }
            ],
            isDefaultClickDisabled: true
        };
        const migrated = (0, v5to6_js_1.migrate5to6)(widget);
        (0, vitest_1.expect)(migrated.onClick).toEqual([{ id: 'id0', type: 'runJs', code: 'navigateTo("https://google.com?q=" + Input1.value)' }]);
        (0, vitest_1.expect)(migrated.dynamicTriggerPathList).toEqual([{ key: 'onClick' }]);
        (0, vitest_1.expect)(migrated.dynamicBindingPathList).toEqual([]);
    });
    (0, vitest_1.it)('should correctly migrate complex triggers', () => {
        const migrated = (0, v5to6_js_1.migrate5to6)((0, lodash_1.cloneDeep)(complexTriggers_js_1.default));
        (0, vitest_1.expect)(migrated.children[0].onClick).toEqual([
            {
                id: 'id0',
                code: '\nget_tiny_filter.run(() => {\n\tdeafult_filters.run();\n})\n',
                type: 'runJs'
            },
            {
                id: 'id1',
                code: "\nresetComponent('location_dropdown') && resetComponent('sector_dropdown') && resetComponent('investor_dropdown') && resetComponent('revenue_dropdown') && \nresetComponent('founded_dropdown') && resetComponent('number_of_employee_dropdown')\n",
                type: 'runJs'
            },
            {
                id: 'id2',
                type: 'executeApi',
                apiNames: ['sleep']
            },
            {
                id: 'id3',
                code: 'apply_filters.run();map_feed.run();storeValue("sessionId", report_page_load.response)\n;',
                type: 'runJs'
            },
            {
                id: 'id4',
                code: 'valuation_line_feed.run();money_raised_bar_feed.run();investor_count_feed.run(); ',
                type: 'runJs'
            },
            {
                id: 'id5',
                code: 'revenue_bar_feed.run();sector_pie_feed.run();location_pie_feed.run(); revenue_pie_feed.run();employee_per_org.run();employee_pie_feed.run();',
                type: 'runJs'
            },
            {
                id: 'id6',
                code: 'storeValue("sessionId", report_page_load.response)\n;',
                type: 'runJs'
            },
            {
                id: 'id7',
                code: 'report_search.run();',
                type: 'runJs'
            }
        ]);
        (0, vitest_1.expect)(migrated.children[1].onClick).toEqual([
            {
                id: 'id0',
                type: 'runJs',
                code: ''
            },
            {
                id: 'id1',
                type: 'runJs',
                code: ''
            }
        ]);
    });
    (0, vitest_1.it)('should correctly migrate triggers with duplicates', () => {
        const migrated = (0, v5to6_js_1.migrate5to6)((0, lodash_1.cloneDeep)(duplicateTriggers_js_1.default));
        (0, vitest_1.expect)(migrated.children[0].onTextChanged).toEqual([
            {
                id: 'id0',
                code: '',
                type: 'runJs'
            }
        ]);
        (0, vitest_1.expect)(migrated.children[0].dynamicTriggerPathList).toEqual([{ key: 'onTextChanged' }]);
    });
    (0, vitest_1.it)('should correctly migrate triggers with code mode enabled', () => {
        const migrated = (0, v5to6_js_1.migrate5to6)((0, lodash_1.cloneDeep)(codeTrigger_js_1.default));
        (0, vitest_1.expect)(migrated.children[0].onTextChanged).toEqual([
            {
                id: 'id0',
                apiNames: ['API'],
                type: 'executeApi'
            }
        ]);
        (0, vitest_1.expect)(migrated.children[0].dynamicTriggerPathList).toEqual([{ key: 'onTextChanged' }]);
        (0, vitest_1.expect)(migrated.children[0].dynamicPropertyPathList).toEqual([]);
        (0, vitest_1.expect)(migrated.children[1].onTextChanged).toEqual([
            {
                id: 'id0',
                code: `API.run()
showAlert('hello')`,
                type: 'runJs'
            }
        ]);
        (0, vitest_1.expect)(migrated.children[1].dynamicTriggerPathList).toEqual([{ key: 'onTextChanged' }]);
        (0, vitest_1.expect)(migrated.children[1].dynamicPropertyPathList).toEqual([]);
    });
    (0, vitest_1.it)('should correctly migrate onSubmit properties that were missing a dynamicTriggerPath', () => {
        const migrated = (0, v5to6_js_1.migrate5to6)((0, lodash_1.cloneDeep)(missingTriggers_js_1.default));
        (0, vitest_1.expect)(migrated.children[0].onSubmit).toEqual([
            {
                id: 'id0',
                code: '',
                type: 'runJs'
            }
        ]);
        (0, vitest_1.expect)(migrated.children[0].dynamicTriggerPathList).toEqual([{ key: 'onSubmit' }, { key: 'onTextChanged' }]);
    });
});
//# sourceMappingURL=v5to6.test.js.map