"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const migrateToSections_js_1 = require("./migrateToSections.js");
(0, vitest_1.describe)('findNextWidgetNameWithSuffix', () => {
    (0, vitest_1.it)('generates a name with a default suffix or none', () => {
        // Numbers start at 1
        const result = (0, migrateToSections_js_1.findNextWidgetNameWithSuffix)('TestWidget', []);
        (0, vitest_1.expect)(result).toBe('TestWidget1');
        const result2 = (0, migrateToSections_js_1.findNextWidgetNameWithSuffix)('TestWidget', ['TestWidget1']);
        (0, vitest_1.expect)(result2).toBe('TestWidget2');
        // Suffix start with no suffix
        const result3 = (0, migrateToSections_js_1.findNextWidgetNameWithSuffix)('TestWidget', [], '_');
        (0, vitest_1.expect)(result3).toBe('TestWidget');
        const result4 = (0, migrateToSections_js_1.findNextWidgetNameWithSuffix)('TestWidget', ['TestWidget'], '_');
        (0, vitest_1.expect)(result4).toBe('TestWidget_');
    });
    (0, vitest_1.it)('generates a name with the right suffix when multiple instances of the name exist', () => {
        const existingNames = ['testwidget', 'testwidget_', 'testwidget__'];
        const result = (0, migrateToSections_js_1.findNextWidgetNameWithSuffix)('TestWidget', existingNames, '_');
        (0, vitest_1.expect)(result).toBe('TestWidget___');
    });
    (0, vitest_1.it)('generates a name with the right suffix when multiple instances of the name exist and the suffix string arg is undefined', () => {
        const existingNames = ['testwidget', 'testwidget_', 'testwidget__'];
        const result = (0, migrateToSections_js_1.findNextWidgetNameWithSuffix)('TestWidget', existingNames);
        (0, vitest_1.expect)(result).toBe('TestWidget1');
    });
    (0, vitest_1.it)('generates a name with the right suffix when a name with a numeric suffix exists and the suffix string arg is undefined', () => {
        const existingNames = ['TestWidget', 'TestWidget1'];
        const result = (0, migrateToSections_js_1.findNextWidgetNameWithSuffix)('TestWidget', existingNames);
        (0, vitest_1.expect)(result).toBe('TestWidget2');
    });
    (0, vitest_1.it)('generates a name without the suffix when one instance already exists', () => {
        const existingNames = ['testwidget'];
        const result = (0, migrateToSections_js_1.findNextWidgetNameWithSuffix)('TestWidget', existingNames, '_myfunnysuffix_');
        (0, vitest_1.expect)(result).toBe('TestWidget_myfunnysuffix_');
    });
});
(0, vitest_1.describe)('findAllInstancesOfWidgetNameWithPrefix', () => {
    (0, vitest_1.it)('should find widget names with the given prefix', () => {
        const dsl = {
            widgetName: 'prefixOne',
            children: [{ widgetName: 'prefixTwo' }, { widgetName: 'otherName' }]
        };
        const result = (0, migrateToSections_js_1.findAllInstancesOfWidgetNameWithPrefix)(dsl, 'prefix');
        (0, vitest_1.expect)(result).toEqual(['prefixOne', 'prefixTwo']);
    });
    (0, vitest_1.it)('should handle deeply nested widget structures', () => {
        const dsl = {
            widgetName: 'root',
            children: [
                {
                    widgetName: 'level1',
                    children: [
                        {
                            widgetName: 'prefixNested',
                            children: [{ widgetName: 'prefixDeeplyNested' }]
                        }
                    ]
                }
            ]
        };
        const result = (0, migrateToSections_js_1.findAllInstancesOfWidgetNameWithPrefix)(dsl, 'prefix');
        (0, vitest_1.expect)(result).toEqual(['prefixNested', 'prefixDeeplyNested']);
    });
    (0, vitest_1.it)('should return an empty array when there are no matches', () => {
        const dsl = {
            widgetName: 'rootName',
            children: [{ widgetName: 'childOne' }, { widgetName: 'childTwo' }]
        };
        const result = (0, migrateToSections_js_1.findAllInstancesOfWidgetNameWithPrefix)(dsl, 'prefix');
        (0, vitest_1.expect)(result).toEqual([]);
    });
});
//# sourceMappingURL=migrateToSections.test.js.map