"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const testing_1 = require("@angular-devkit/schematics/testing");
const schematics_1 = require("@angular-devkit/schematics");
const path = require("path");
const migrationsPath = path.join(__dirname, '../../migrations.json');
const runner = new testing_1.SchematicTestRunner('migrations', migrationsPath);
const MIGRATION = 'migration-v19-6-2-s-chips-outputs';
async function runMigration(files) {
    const tree = new testing_1.UnitTestTree(schematics_1.Tree.empty());
    for (const [filePath, content] of Object.entries(files)) {
        tree.create(filePath, content);
    }
    return runner.runSchematic(MIGRATION, {}, tree);
}
describe('migrate-s-chips-outputs', () => {
    // ─── Renames individuais ─────────────────────────────────────────────────
    it('deve renomear (onAdd) para (added)', async () => {
        const result = await runMigration({
            'app.component.html': `<s-chips (onAdd)="onAdd($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(added)="onAdd($event)"');
        expect(result.readText('app.component.html')).not.toContain('(onAdd)');
    });
    it('deve renomear (onRemove) para (removed)', async () => {
        const result = await runMigration({
            'app.component.html': `<s-chips (onRemove)="onRemove($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(removed)="onRemove($event)"');
        expect(result.readText('app.component.html')).not.toContain('(onRemove)');
    });
    it('deve renomear (onChipClick) para (chipClicked)', async () => {
        const result = await runMigration({
            'app.component.html': `<s-chips (onChipClick)="onChipClick($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(chipClicked)="onChipClick($event)"');
        expect(result.readText('app.component.html')).not.toContain('(onChipClick)');
    });
    it('deve renomear (onFocus) para (focused) dentro de s-chips', async () => {
        const result = await runMigration({
            'app.component.html': `<s-chips (onFocus)="onFocus($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(focused)="onFocus($event)"');
        expect(result.readText('app.component.html')).not.toContain('(onFocus)');
    });
    it('deve renomear (onBlur) para (focusLost) dentro de s-chips', async () => {
        const result = await runMigration({
            'app.component.html': `<s-chips (onBlur)="onBlur($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(focusLost)="onBlur($event)"');
        expect(result.readText('app.component.html')).not.toContain('(onBlur)');
    });
    // ─── Escopo dos eventos genéricos ────────────────────────────────────────
    it('não deve alterar (onFocus) em elementos que não são s-chips', async () => {
        const result = await runMigration({
            'app.component.html': `<s-chips [value]="tags" />\n<input (onFocus)="focus()" />`,
        });
        expect(result.readText('app.component.html')).toContain('(onFocus)="focus()"');
    });
    it('não deve alterar (onBlur) em elementos que não são s-chips', async () => {
        const result = await runMigration({
            'app.component.html': `<s-chips [value]="tags" />\n<input (onBlur)="blur()" />`,
        });
        expect(result.readText('app.component.html')).toContain('(onBlur)="blur()"');
    });
    // ─── Tag multi-linha ─────────────────────────────────────────────────────
    it('deve renomear outputs em tag s-chips multi-linha', async () => {
        const result = await runMigration({
            'app.component.html': `
<s-chips
    [value]="chips"
    (onAdd)="onAdd($event)"
    (onFocus)="onFocus($event)"
    (onBlur)="onBlur($event)"
/>`,
        });
        const html = result.readText('app.component.html');
        expect(html).toContain('(added)="onAdd($event)"');
        expect(html).toContain('(focused)="onFocus($event)"');
        expect(html).toContain('(focusLost)="onBlur($event)"');
        expect(html).not.toContain('(onAdd)');
        expect(html).not.toContain('(onFocus)');
        expect(html).not.toContain('(onBlur)');
    });
    // ─── Template completo ───────────────────────────────────────────────────
    it('deve migrar um template completo com todos os outputs legados', async () => {
        const result = await runMigration({
            'app.component.html': `
<s-chips
    [value]="chips"
    [allowDuplicated]="false"
    [addOnTab]="true"
    [addOnBlur]="true"
    (onAdd)="onAdd($event)"
    (onRemove)="onRemove($event)"
    (onChipClick)="onChipClick($event)"
    (onFocus)="onFocus($event)"
    (onBlur)="onBlur($event)"
/>`,
        });
        const html = result.readText('app.component.html');
        expect(html).toContain('(added)="onAdd($event)"');
        expect(html).toContain('(removed)="onRemove($event)"');
        expect(html).toContain('(chipClicked)="onChipClick($event)"');
        expect(html).toContain('(focused)="onFocus($event)"');
        expect(html).toContain('(focusLost)="onBlur($event)"');
        expect(html).not.toContain('(onAdd)');
        expect(html).not.toContain('(onRemove)');
        expect(html).not.toContain('(onChipClick)');
        expect(html).not.toContain('(onFocus)');
        expect(html).not.toContain('(onBlur)');
    });
    // ─── Sem s-chips ─────────────────────────────────────────────────────────
    it('não deve modificar arquivo sem s-chips', async () => {
        const content = `<div class="container"><p>Olá</p></div>`;
        const result = await runMigration({ 'app.component.html': content });
        expect(result.readText('app.component.html')).toBe(content);
    });
    it('não deve modificar arquivo .ts', async () => {
        const content = `import { Component } from '@angular/core';\n@Component({}) export class AppComponent {}`;
        const result = await runMigration({ 'app.component.ts': content });
        expect(result.readText('app.component.ts')).toBe(content);
    });
});
//# sourceMappingURL=index.test.js.map