"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-0-p-datepicker';
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-p-datepicker', () => {
    // ─── Tag rename ──────────────────────────────────────────────────────────
    it('deve renomear a tag p-datepicker para s-datepicker', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [(ngModel)]="date" />`,
        });
        expect(result.readText('app.component.html')).toContain('<s-datepicker');
        expect(result.readText('app.component.html')).not.toContain('p-datepicker');
    });
    it('deve renomear a tag de fechamento </p-datepicker>', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [(ngModel)]="date"></p-datepicker>`,
        });
        expect(result.readText('app.component.html')).toContain('</s-datepicker>');
        expect(result.readText('app.component.html')).not.toContain('</p-datepicker>');
    });
    // ─── Atributo view → mode ────────────────────────────────────────────────
    it('deve converter view="month" para mode="month"', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker view="month" />`,
        });
        expect(result.readText('app.component.html')).toContain('mode="month"');
        expect(result.readText('app.component.html')).not.toContain('view=');
    });
    it('deve converter view="year" para mode="year"', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker view="year" />`,
        });
        expect(result.readText('app.component.html')).toContain('mode="year"');
        expect(result.readText('app.component.html')).not.toContain('view=');
    });
    it('deve remover view="date" (é o default do s-datepicker)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker view="date" />`,
        });
        expect(result.readText('app.component.html')).not.toContain('view=');
        expect(result.readText('app.component.html')).not.toContain('mode="date"');
    });
    // ─── showTime / timeOnly → mode ──────────────────────────────────────────
    it('deve converter [showTime]="true" para mode="datetime"', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [showTime]="true" />`,
        });
        expect(result.readText('app.component.html')).toContain('mode="datetime"');
        expect(result.readText('app.component.html')).not.toContain('showTime');
    });
    it('deve converter [timeOnly]="true" para mode="time"', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [timeOnly]="true" />`,
        });
        expect(result.readText('app.component.html')).toContain('mode="time"');
        expect(result.readText('app.component.html')).not.toContain('timeOnly');
    });
    // ─── selectionMode ───────────────────────────────────────────────────────
    it('deve converter selectionMode="range" para mode="range"', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker selectionMode="range" />`,
        });
        expect(result.readText('app.component.html')).toContain('mode="range"');
        expect(result.readText('app.component.html')).not.toContain('selectionMode="range"');
    });
    it('deve converter [selectionMode]="\'range\'" para mode="range"', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [selectionMode]="'range'" />`,
        });
        expect(result.readText('app.component.html')).toContain('mode="range"');
    });
    it('deve manter selectionMode="multiple" (agora suportado nativamente)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker selectionMode="multiple" />`,
        });
        expect(result.readText('app.component.html')).toContain('selectionMode="multiple"');
    });
    it('deve converter [selectionMode]="\'multiple\'" para selectionMode="multiple"', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [selectionMode]="'multiple'" />`,
        });
        expect(result.readText('app.component.html')).toContain('selectionMode="multiple"');
    });
    // ─── minDate / maxDate ───────────────────────────────────────────────────
    it('deve renomear [minDate] para [min]', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [minDate]="minDate" />`,
        });
        expect(result.readText('app.component.html')).toContain('[min]="minDate"');
        expect(result.readText('app.component.html')).not.toContain('[minDate]');
    });
    it('deve renomear [maxDate] para [max]', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [maxDate]="maxDate" />`,
        });
        expect(result.readText('app.component.html')).toContain('[max]="maxDate"');
        expect(result.readText('app.component.html')).not.toContain('[maxDate]');
    });
    it('deve renomear minDate= (estático) para min=', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker minDate="2024-01-01" />`,
        });
        expect(result.readText('app.component.html')).toContain('min="2024-01-01"');
        expect(result.readText('app.component.html')).not.toContain('minDate=');
    });
    // ─── stepMinute → minuteStep ─────────────────────────────────────────────
    it('deve renomear [stepMinute] para [minuteStep]', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [stepMinute]="10" />`,
        });
        expect(result.readText('app.component.html')).toContain('[minuteStep]="10"');
        expect(result.readText('app.component.html')).not.toContain('stepMinute');
    });
    // ─── Eventos ─────────────────────────────────────────────────────────────
    it('deve renomear (onFocus) para (focused)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onFocus)="onFocus($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(focused)="onFocus($event)"');
    });
    it('deve renomear (onBlur) para (blurred)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onBlur)="onBlur($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(blurred)="onBlur($event)"');
    });
    it('deve renomear (onSelect) para (selected)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onSelect)="onSelect($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(selected)="onSelect($event)"');
    });
    it('deve renomear (onClose) para (closed)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onClose)="onClose($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(closed)="onClose($event)"');
    });
    it('deve renomear (onShow) para (show)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onShow)="onShow()" />`,
        });
        expect(result.readText('app.component.html')).toContain('(show)="onShow()"');
    });
    it('deve renomear (onInput) para (valueInput)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onInput)="onInput($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(valueInput)="onInput($event)"');
    });
    it('deve renomear (onTodayClick) para (todayClick)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onTodayClick)="today($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(todayClick)="today($event)"');
    });
    it('deve renomear (onClearClick) para (clearClick)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onClearClick)="clear($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(clearClick)="clear($event)"');
    });
    it('deve renomear (onMonthChange) para (monthChange)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onMonthChange)="monthChange($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(monthChange)="monthChange($event)"');
    });
    it('deve renomear (onYearChange) para (yearChange)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onYearChange)="yearChange($event)" />`,
        });
        expect(result.readText('app.component.html')).toContain('(yearChange)="yearChange($event)"');
    });
    it('deve remover (onClear) sem equivalente', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onClear)="clear()" />`,
        });
        expect(result.readText('app.component.html')).not.toContain('(onClear)');
    });
    it('deve remover (onClickOutside) sem equivalente', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker (onClickOutside)="outside()" />`,
        });
        expect(result.readText('app.component.html')).not.toContain('(onClickOutside)');
    });
    // ─── Atributos removidos ─────────────────────────────────────────────────
    it('deve remover sDatepickerNoPeriodTab (a11y nativa no s-datepicker)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker sDatepickerNoPeriodTab />`,
        });
        expect(result.readText('app.component.html')).not.toContain('sDatepickerNoPeriodTab');
    });
    it('deve remover appendTo', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [appendTo]="'body'" />`,
        });
        expect(result.readText('app.component.html')).not.toContain('appendTo');
    });
    it('deve remover dataType', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker dataType="date" />`,
        });
        expect(result.readText('app.component.html')).not.toContain('dataType');
    });
    it('deve remover atributos não suportados (inline, touchUI, showWeek, etc.)', async () => {
        const result = await runMigration({
            'app.component.html': `<p-datepicker [inline]="true" [touchUI]="true" [showWeek]="true" [numberOfMonths]="2" />`,
        });
        const html = result.readText('app.component.html');
        expect(html).not.toContain('inline');
        expect(html).not.toContain('touchUI');
        expect(html).not.toContain('showWeek');
        expect(html).not.toContain('numberOfMonths');
    });
    // ─── Migração completa ───────────────────────────────────────────────────
    it('deve migrar um template completo com múltiplos atributos', async () => {
        const result = await runMigration({
            'app.component.html': `
<p-datepicker
    [(ngModel)]="date"
    sDatepickerNoPeriodTab
    view="month"
    [minDate]="min"
    [maxDate]="max"
    [stepMinute]="10"
    (onSelect)="onSelect($event)"
    (onClose)="onClose($event)"
    (onFocus)="onFocus($event)"
    (onBlur)="onBlur($event)"
    [appendTo]="'body'"
    placeholder="Selecione"
/>`,
        });
        const html = result.readText('app.component.html');
        expect(html).toContain('<s-datepicker');
        expect(html).toContain('mode="month"');
        expect(html).toContain('[min]="min"');
        expect(html).toContain('[max]="max"');
        expect(html).toContain('[minuteStep]="10"');
        expect(html).toContain('(selected)="onSelect($event)"');
        expect(html).toContain('(closed)="onClose($event)"');
        expect(html).toContain('(focused)="onFocus($event)"');
        expect(html).toContain('(blurred)="onBlur($event)"');
        expect(html).not.toContain('p-datepicker');
        expect(html).not.toContain('sDatepickerNoPeriodTab');
        expect(html).not.toContain('appendTo');
        expect(html).not.toContain('view=');
    });
    // ─── Migração TypeScript ─────────────────────────────────────────────────
    it('deve remover import DatePickerModule do PrimeNG', async () => {
        const result = await runMigration({
            'app.component.ts': `import { DatePickerModule } from 'primeng/datepicker';\n@Component({}) export class AppComponent {}`,
        });
        expect(result.readText('app.component.ts')).not.toContain('DatePickerModule');
        expect(result.readText('app.component.ts')).not.toContain("from 'primeng/datepicker'");
    });
    it('deve adicionar import DatepickerComponent após remover PrimeNG', async () => {
        const result = await runMigration({
            'app.component.ts': `import { DatePickerModule } from 'primeng/datepicker';\n@Component({}) export class AppComponent {}`,
        });
        expect(result.readText('app.component.ts')).toContain('DatepickerComponent');
        expect(result.readText('app.component.ts')).toContain("@seniorsistemas/angular-components/datepicker");
    });
    it('deve preservar outros imports do mesmo pacote primeng ao remover DatePickerModule', async () => {
        const result = await runMigration({
            'app.component.ts': `import { DatePickerModule, ButtonModule } from 'primeng/datepicker';\n@Component({}) export class AppComponent {}`,
        });
        const ts = result.readText('app.component.ts');
        expect(ts).toContain('ButtonModule');
        expect(ts).not.toContain('DatePickerModule');
    });
    it('não deve modificar arquivo .ts sem imports do primeng', 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);
    });
    it('não deve modificar arquivo .html sem p-datepicker', 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);
    });
    // ─── Decorator imports array ─────────────────────────────────────────────
    it('deve substituir DatePickerModule por DatepickerComponent no array exports de @NgModule', async () => {
        const result = await runMigration({
            'app.module.ts': `import { DatePickerModule } from 'primeng/datepicker';\n@NgModule({ imports: [BrowserModule], exports: [DatePickerModule, DropdownModule] })\nexport class AppModule {}`,
        });
        const ts = result.readText('app.module.ts');
        expect(ts).not.toContain('DatePickerModule');
        expect(ts).toContain('DatepickerComponent');
        expect(ts).toContain('DropdownModule');
    });
    it('deve substituir DatePickerModule por DatepickerComponent no array imports de @NgModule', async () => {
        const result = await runMigration({
            'app.module.ts': `import { DatePickerModule } from 'primeng/datepicker';\n@NgModule({ imports: [CommonModule, DatePickerModule] })\nexport class AppModule {}`,
        });
        const ts = result.readText('app.module.ts');
        expect(ts).toContain('DatepickerComponent');
        expect(ts).not.toContain('DatePickerModule');
        expect(ts).toContain('CommonModule');
    });
    it('deve substituir DatePickerModule por DatepickerComponent no array imports de @Component standalone', async () => {
        const result = await runMigration({
            'app.component.ts': `import { DatePickerModule } from 'primeng/datepicker';\n@Component({ imports: [DatePickerModule], template: '' })\nexport class AppComponent {}`,
        });
        const ts = result.readText('app.component.ts');
        expect(ts).toContain('DatepickerComponent');
        expect(ts).not.toContain('DatePickerModule');
    });
    it('deve preservar outros imports no array ao substituir DatePickerModule', async () => {
        const result = await runMigration({
            'app.module.ts': `import { DatePickerModule } from 'primeng/datepicker';\n@NgModule({ imports: [CommonModule, RouterModule, DatePickerModule] })\nexport class AppModule {}`,
        });
        const ts = result.readText('app.module.ts');
        expect(ts).toContain('DatepickerComponent');
        expect(ts).toContain('CommonModule');
        expect(ts).toContain('RouterModule');
        expect(ts).not.toContain('DatePickerModule');
    });
    it('deve substituir CalendarModule (alias PrimeNG legado) no array imports', async () => {
        const result = await runMigration({
            'app.module.ts': `import { CalendarModule } from 'primeng/calendar';\n@NgModule({ imports: [CalendarModule] })\nexport class AppModule {}`,
        });
        const ts = result.readText('app.module.ts');
        expect(ts).toContain('DatepickerComponent');
        expect(ts).not.toContain('CalendarModule');
    });
    it('deve substituir DatePickerModule no decorator mesmo quando importado via re-export (sem import direto do primeng)', async () => {
        const result = await runMigration({
            'feature.module.ts': `import { NgModule } from '@angular/core';\nimport { DatePickerModule } from '../shared/primeng';\n\n@NgModule({ imports: [DatePickerModule] })\nexport class FeatureModule {}`,
        });
        const ts = result.readText('feature.module.ts');
        expect(ts).not.toContain('DatePickerModule');
        expect(ts).toContain('DatepickerComponent');
        expect(ts).toContain("@seniorsistemas/angular-components/datepicker");
    });
    // ─── angular.json styles injection ───────────────────────────────────────
    it('deve adicionar o styles.css da lib ao angular.json', async () => {
        const angularJson = {
            projects: {
                app: {
                    architect: {
                        build: {
                            builder: '@angular-devkit/build-angular:browser',
                            options: { styles: ['src/styles.css'] },
                        },
                    },
                },
            },
        };
        const result = await runMigration({
            '/angular.json': JSON.stringify(angularJson, null, 2),
            'app.component.html': `<p-datepicker [(ngModel)]="date" />`,
        });
        const json = JSON.parse(result.readText('/angular.json'));
        expect(json.projects.app.architect.build.options.styles).toContain('node_modules/@seniorsistemas/angular-components/styles.css');
    });
    it('não deve duplicar o style se angular.json já tiver a entrada', async () => {
        const style = 'node_modules/@seniorsistemas/angular-components/styles.css';
        const angularJson = {
            projects: {
                app: {
                    architect: {
                        build: {
                            builder: '@angular-devkit/build-angular:browser',
                            options: { styles: ['src/styles.css', style] },
                        },
                    },
                },
            },
        };
        const result = await runMigration({
            '/angular.json': JSON.stringify(angularJson, null, 2),
            'app.component.html': `<p-datepicker [(ngModel)]="date" />`,
        });
        const json = JSON.parse(result.readText('/angular.json'));
        const count = json.projects.app.architect.build.options.styles.filter((s) => s === style).length;
        expect(count).toBe(1);
    });
});
//# sourceMappingURL=index.test.js.map