"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const performance_predictor_1 = require("../../walls/03-knowledge/decisions/performance-predictor");
describe('PerformancePredictor', () => {
    let predictor;
    beforeEach(() => {
        predictor = new performance_predictor_1.PerformancePredictor();
    });
    test('detects N+1 query in loop', () => {
        const code = 'users.forEach(user => {\n  const posts = await Post.findAll({ where: { userId: user.id } });\n});';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'n_plus_one')).toBe(true);
    });
    test('detects memory leak via setInterval', () => {
        const code = 'setInterval(() => { fetchData(); }, 1000);';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'memory_leak')).toBe(true);
    });
    test('detects memory leak via addEventListener', () => {
        const code = 'window.addEventListener("resize", handler);';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'memory_leak')).toBe(true);
    });
    test('detects large bundle import', () => {
        const code = "import * as lodash from 'lodash';";
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'large_bundle')).toBe(true);
    });
    test('returns empty for clean code', () => {
        const code = 'const x = 1 + 2;';
        const predictions = predictor.predict(code);
        expect(predictions).toHaveLength(0);
    });
    test('AST detects wildcard import', () => {
        const code = "import * as moment from 'moment';";
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'large_bundle')).toBe(true);
    });
    test('AST detects N+1 via forEach with DB call in callback', () => {
        const code = 'items.forEach(item => { const r = db.query("SELECT *"); });';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'n_plus_one')).toBe(true);
    });
    test('AST detects setInterval memory leak', () => {
        const code = 'setInterval(() => { refreshData(); }, 5000);';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'memory_leak')).toBe(true);
    });
    test('AST detects addEventListener memory leak', () => {
        const code = 'document.addEventListener("click", onClick);';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'memory_leak')).toBe(true);
    });
    test('AST ignores named imports (not wildcard)', () => {
        const code = "import { debounce } from 'lodash';";
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'large_bundle')).toBe(false);
    });
});
//# sourceMappingURL=performance-predictor.test.js.map