"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
// Test the counting logic that was implemented in OperatorsSelect
function calculateSelectedOperators(values, bundles, opSpecs) {
    // Calculate all selected operators (direct selections + bundle selections)
    const bundleOperators = values.selectedBundles.flatMap((bundleId) => { var _a; return ((_a = bundles.find((b) => b.id === bundleId)) === null || _a === void 0 ? void 0 : _a.operators) || []; });
    const allSelectedOperators = values.selectedOperators
        .concat(bundleOperators)
        .filter((op, index, array) => array.indexOf(op) === index); // Remove duplicates
    return allSelectedOperators.filter((opKey) => !!opSpecs[opKey]);
}
(0, vitest_1.describe)('OperatorsSelect counting logic', () => {
    const mockBundles = [
        {
            id: 'virtualization',
            title: 'Virtualization',
            description: 'Virtualization bundle',
            operators: ['cnv', 'nmstate', 'mtv'],
        },
        {
            id: 'openshift-ai',
            title: 'OpenShift AI',
            description: 'AI bundle',
            operators: ['nvidia-gpu', 'authorino', 'odf'],
        },
    ];
    const mockOpSpecs = {
        lvm: { title: 'LVM' },
        odf: { title: 'ODF' },
        cnv: { title: 'CNV' },
        nmstate: { title: 'NMState' },
        mtv: { title: 'MTV' },
        'nvidia-gpu': { title: 'NVIDIA GPU' },
        authorino: { title: 'Authorino' },
    };
    (0, vitest_1.it)('should count only manually selected operators when no bundles are selected', () => {
        const values = {
            selectedOperators: ['lvm', 'odf'],
            selectedBundles: [],
        };
        const result = calculateSelectedOperators(values, mockBundles, mockOpSpecs);
        (0, vitest_1.expect)(result).toHaveLength(2);
        (0, vitest_1.expect)(result).toContain('lvm');
        (0, vitest_1.expect)(result).toContain('odf');
    });
    (0, vitest_1.it)('should count bundle operators when a bundle is selected', () => {
        const values = {
            selectedOperators: ['lvm'], // 1 manually selected
            selectedBundles: ['virtualization'], // bundle with 3 operators: cnv, nmstate, mtv
        };
        const result = calculateSelectedOperators(values, mockBundles, mockOpSpecs);
        (0, vitest_1.expect)(result).toHaveLength(4);
        (0, vitest_1.expect)(result).toContain('lvm');
        (0, vitest_1.expect)(result).toContain('cnv');
        (0, vitest_1.expect)(result).toContain('nmstate');
        (0, vitest_1.expect)(result).toContain('mtv');
    });
    (0, vitest_1.it)('should not double-count operators that are both manually selected and in a bundle', () => {
        const values = {
            selectedOperators: ['lvm', 'cnv'], // cnv is also in the bundle
            selectedBundles: ['virtualization'], // bundle with: cnv, nmstate, mtv
        };
        const result = calculateSelectedOperators(values, mockBundles, mockOpSpecs);
        (0, vitest_1.expect)(result).toHaveLength(4);
        (0, vitest_1.expect)(result).toContain('lvm');
        (0, vitest_1.expect)(result).toContain('cnv');
        (0, vitest_1.expect)(result).toContain('nmstate');
        (0, vitest_1.expect)(result).toContain('mtv');
        // cnv should only appear once in the result
        (0, vitest_1.expect)(result.filter((op) => op === 'cnv')).toHaveLength(1);
    });
    (0, vitest_1.it)('should only count operators that have valid specs', () => {
        const values = {
            selectedOperators: ['lvm', 'invalid-operator'], // invalid-operator not in opSpecs
            selectedBundles: [],
        };
        const result = calculateSelectedOperators(values, mockBundles, mockOpSpecs);
        (0, vitest_1.expect)(result).toHaveLength(1);
        (0, vitest_1.expect)(result).toContain('lvm');
        (0, vitest_1.expect)(result).not.toContain('invalid-operator');
    });
    (0, vitest_1.it)('should handle multiple bundles correctly', () => {
        const values = {
            selectedOperators: ['lvm'],
            selectedBundles: ['virtualization', 'openshift-ai'], // Two bundles
        };
        const result = calculateSelectedOperators(values, mockBundles, mockOpSpecs);
        (0, vitest_1.expect)(result).toHaveLength(7); // lvm + 3 from virtualization + 3 from openshift-ai
        (0, vitest_1.expect)(result).toContain('lvm');
        (0, vitest_1.expect)(result).toContain('cnv');
        (0, vitest_1.expect)(result).toContain('nmstate');
        (0, vitest_1.expect)(result).toContain('mtv');
        (0, vitest_1.expect)(result).toContain('nvidia-gpu');
        (0, vitest_1.expect)(result).toContain('authorino');
        (0, vitest_1.expect)(result).toContain('odf');
    });
    (0, vitest_1.it)('should handle overlapping operators in multiple bundles', () => {
        const values = {
            selectedOperators: [],
            selectedBundles: ['virtualization', 'openshift-ai'], // Both bundles have 'odf' (but only virtualization has it in our mock)
        };
        // Let's modify the virtualization bundle to include odf to test overlap
        const bundlesWithOverlap = [
            {
                id: 'virtualization',
                title: 'Virtualization',
                description: 'Virtualization bundle',
                operators: ['cnv', 'nmstate', 'mtv', 'odf'], // Added odf
            },
            {
                id: 'openshift-ai',
                title: 'OpenShift AI',
                description: 'AI bundle',
                operators: ['nvidia-gpu', 'authorino', 'odf'], // odf is in both bundles
            },
        ];
        const result = calculateSelectedOperators(values, bundlesWithOverlap, mockOpSpecs);
        (0, vitest_1.expect)(result).toHaveLength(6); // cnv, nmstate, mtv, odf, nvidia-gpu, authorino (odf not double-counted)
        (0, vitest_1.expect)(result.filter((op) => op === 'odf')).toHaveLength(1); // odf should only appear once
    });
    (0, vitest_1.it)('should handle empty selections correctly', () => {
        const values = {
            selectedOperators: [],
            selectedBundles: [],
        };
        const result = calculateSelectedOperators(values, mockBundles, mockOpSpecs);
        (0, vitest_1.expect)(result).toHaveLength(0);
    });
});
//# sourceMappingURL=OperatorsSelect.test.js.map