"use strict";
/**
 * Tests for Enhanced i18n Generator
 */
Object.defineProperty(exports, "__esModule", { value: true });
const enhanced_i18n_generator_1 = require("./enhanced-i18n-generator");
describe('EnhancedI18nGenerator', () => {
    let generator;
    beforeEach(() => {
        generator = new enhanced_i18n_generator_1.EnhancedI18nGenerator();
    });
    it('should have correct metadata', () => {
        expect(generator.id).toBe('enhanced-i18n');
        expect(generator.name).toBe('Enhanced i18n Generator');
        expect(generator.description).toContain('internationalization');
    });
    it('should return empty result when no i18n config', () => {
        const workflow = {
            workflow: {
                id: 'test',
                version: '1.0.0',
                name: 'Test',
                description: 'Test workflow',
            },
            stack: {
                web: {
                    type: 'frontend',
                    technology: 'react',
                },
            },
            stages: {
                local: {
                    infrastructure: {
                        databases: {},
                        services: {},
                    },
                },
            },
        };
        const context = {
            workflow,
            outputDirectory: '/tmp/test',
        };
        const result = generator.generate(context);
        expect(result.files).toHaveLength(0);
    });
    describe('Frontend i18n', () => {
        it('should generate frontend i18n configuration', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es', 'fr'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const configFile = result.files.find(f => f.path.includes('src/config/i18n.ts'));
            expect(configFile).toBeDefined();
            expect(configFile.content).toContain('i18next');
            expect(configFile.content).toContain("defaultLocale = 'en'");
            expect(configFile.content).toContain('supportedLocales');
        });
        it('should generate translation hook', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const hookFile = result.files.find(f => f.path.includes('hooks/useTranslation.ts'));
            expect(hookFile).toBeDefined();
            expect(hookFile.content).toContain('useTranslation');
            expect(hookFile.content).toContain('useFormattedDate');
            expect(hookFile.content).toContain('useFormattedNumber');
        });
        it('should generate locale switcher component', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es', 'fr'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const switcherFile = result.files.find(f => f.path.includes('LocaleSwitcher.tsx'));
            expect(switcherFile).toBeDefined();
            expect(switcherFile.content).toContain('LocaleSwitcher');
            expect(switcherFile.content).toContain('localeNames');
            expect(switcherFile.content).toContain('changeLocale');
        });
        it('should generate formatting utilities', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const utilsFile = result.files.find(f => f.path.includes('utils/formatting.ts'));
            expect(utilsFile).toBeDefined();
            expect(utilsFile.content).toContain('formatDate');
            expect(utilsFile.content).toContain('formatNumber');
            expect(utilsFile.content).toContain('formatCurrency');
            expect(utilsFile.content).toContain('formatFileSize');
        });
        it('should generate translation types', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const typesFile = result.files.find(f => f.path.includes('types/translations.ts'));
            expect(typesFile).toBeDefined();
            expect(typesFile.content).toContain('CommonTranslationKeys');
            expect(typesFile.content).toContain('ErrorTranslationKeys');
            expect(typesFile.content).toContain('ValidationTranslationKeys');
        });
    });
    describe('Backend i18n', () => {
        it('should generate backend i18n configuration', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'fr'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const configFile = result.files.find(f => f.path.includes('api/src/config/i18n.ts'));
            expect(configFile).toBeDefined();
            expect(configFile.content).toContain('i18next');
            expect(configFile.content).toContain('i18next-fs-backend');
            expect(configFile.content).toContain("defaultLocale = 'en'");
        });
        it('should generate locale detection middleware', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const middlewareFile = result.files.find(f => f.path.includes('middleware/locale-detection.ts'));
            expect(middlewareFile).toBeDefined();
            expect(middlewareFile.content).toContain('localeDetection');
            expect(middlewareFile.content).toContain('accept-language');
            expect(middlewareFile.content).toContain('.locale =');
        });
        it('should generate backend translation utilities', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'de'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const utilsFile = result.files.find(f => f.path.includes('api/src/utils/translations.ts'));
            expect(utilsFile).toBeDefined();
            expect(utilsFile.content).toContain('translate');
            expect(utilsFile.content).toContain('translateError');
            expect(utilsFile.content).toContain('translateValidation');
            expect(utilsFile.content).toContain('translateEmail');
        });
    });
    describe('Translation Files', () => {
        it('should generate translation files for all locales', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es', 'fr'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            // Should generate 3 files per locale (common, errors, validation) * 3 locales
            const translationFiles = result.files.filter(f => f.path.includes('locales/'));
            expect(translationFiles.length).toBe(9); // 3 locales * 3 files each
        });
        it('should generate common translations', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const commonFile = result.files.find(f => f.path.includes('locales/en/common.json'));
            expect(commonFile).toBeDefined();
            const content = JSON.parse(commonFile.content);
            expect(content.welcome).toBe('Welcome');
            expect(content.loading).toBe('Loading...');
            expect(content.save).toBe('Save');
        });
        it('should generate error translations', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const errorsFile = result.files.find(f => f.path.includes('locales/en/errors.json'));
            expect(errorsFile).toBeDefined();
            const content = JSON.parse(errorsFile.content);
            expect(content.general_error).toContain('error occurred');
            expect(content.network_error).toContain('Network error');
            expect(content.not_found).toContain('not found');
        });
        it('should generate validation translations', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const validationFile = result.files.find(f => f.path.includes('locales/en/validation.json'));
            expect(validationFile).toBeDefined();
            const content = JSON.parse(validationFile.content);
            expect(content.required).toContain('required');
            expect(content.invalid_email).toContain('email');
            expect(content.min_length).toContain('{{min}}');
        });
    });
    describe('Fallback Strategies', () => {
        it('should use default fallback strategy', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es'],
                    fallback_strategy: 'default',
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const configFile = result.files.find(f => f.path.includes('web/src/config/i18n.ts'));
            expect(configFile).toBeDefined();
            expect(configFile.content).toContain("fallbackLng: 'en'");
        });
        it('should use cascade fallback strategy', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es', 'fr'],
                    fallback_strategy: 'cascade',
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const configFile = result.files.find(f => f.path.includes('web/src/config/i18n.ts'));
            expect(configFile).toBeDefined();
            expect(configFile.content).toContain('fallbackLng: supportedLocales');
        });
    });
    describe('Formatting', () => {
        it('should use locale-specific date formatting by default', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en'],
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const hookFile = result.files.find(f => f.path.includes('hooks/useTranslation.ts'));
            expect(hookFile).toBeDefined();
            expect(hookFile.content).toContain('Intl.DateTimeFormat');
        });
        it('should use ISO date formatting when specified', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en'],
                    formatting: {
                        dates: 'iso',
                    },
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const hookFile = result.files.find(f => f.path.includes('hooks/useTranslation.ts'));
            expect(hookFile).toBeDefined();
            expect(hookFile.content).toContain('toISOString');
        });
        it('should use standard number formatting when specified', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en'],
                    formatting: {
                        numbers: 'standard',
                    },
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const hookFile = result.files.find(f => f.path.includes('hooks/useTranslation.ts'));
            expect(hookFile).toBeDefined();
            expect(hookFile.content).toContain('toString()');
        });
        it('should use USD currency formatting when specified', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en'],
                    formatting: {
                        currency: 'usd',
                    },
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const hookFile = result.files.find(f => f.path.includes('hooks/useTranslation.ts'));
            expect(hookFile).toBeDefined();
            expect(hookFile.content).toContain("'en-US'");
            expect(hookFile.content).toContain("'USD'");
        });
    });
    describe('Translation Management', () => {
        it('should generate Lokalise sync script', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es'],
                    translation_management: {
                        provider: 'lokalise',
                        auto_sync: true,
                    },
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const syncFile = result.files.find(f => f.path.includes('sync-translations.ts'));
            expect(syncFile).toBeDefined();
            expect(syncFile.content).toContain('LokaliseApi');
            expect(syncFile.content).toContain('LOKALISE_PROJECT_ID');
            expect(syncFile.content).toContain('LOKALISE_API_KEY');
        });
        it('should generate Crowdin sync script', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'fr'],
                    translation_management: {
                        provider: 'crowdin',
                    },
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const syncFile = result.files.find(f => f.path.includes('sync-translations.ts'));
            expect(syncFile).toBeDefined();
            expect(syncFile.content).toContain('crowdin');
            expect(syncFile.content).toContain('CROWDIN_PROJECT_ID');
            expect(syncFile.content).toContain('CROWDIN_API_KEY');
        });
        it('should generate Phrase sync script', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'de'],
                    translation_management: {
                        provider: 'phrase',
                    },
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            const syncFile = result.files.find(f => f.path.includes('sync-translations.ts'));
            expect(syncFile).toBeDefined();
            expect(syncFile.content).toContain('phrase');
            expect(syncFile.content).toContain('PHRASE_PROJECT_ID');
            expect(syncFile.content).toContain('PHRASE_API_KEY');
        });
    });
    describe('Complete i18n Schema', () => {
        it('should generate all files for complete i18n configuration', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    version: '1.0.0',
                    name: 'Test',
                    description: 'Test',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                i18n: {
                    default_locale: 'en',
                    supported_locales: ['en', 'es', 'fr', 'de'],
                    fallback_strategy: 'cascade',
                    formatting: {
                        dates: 'locale_specific',
                        numbers: 'locale_specific',
                        currency: 'locale_specific',
                    },
                    translation_management: {
                        provider: 'lokalise',
                        auto_sync: true,
                    },
                },
                stages: {
                    local: {
                        infrastructure: {
                            databases: {},
                            services: {},
                        },
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
            };
            const result = generator.generate(context);
            // Frontend files
            expect(result.files.find(f => f.path.includes('web/src/config/i18n.ts'))).toBeDefined();
            expect(result.files.find(f => f.path.includes('web/src/hooks/useTranslation.ts'))).toBeDefined();
            expect(result.files.find(f => f.path.includes('web/src/components/LocaleSwitcher.tsx'))).toBeDefined();
            expect(result.files.find(f => f.path.includes('web/src/utils/formatting.ts'))).toBeDefined();
            expect(result.files.find(f => f.path.includes('web/src/types/translations.ts'))).toBeDefined();
            // Backend files
            expect(result.files.find(f => f.path.includes('api/src/config/i18n.ts'))).toBeDefined();
            expect(result.files.find(f => f.path.includes('api/src/middleware/locale-detection.ts'))).toBeDefined();
            expect(result.files.find(f => f.path.includes('api/src/utils/translations.ts'))).toBeDefined();
            // Translation files (4 locales * 3 files each)
            const translationFiles = result.files.filter(f => f.path.includes('locales/'));
            expect(translationFiles.length).toBe(12);
            // Sync script
            expect(result.files.find(f => f.path.includes('sync-translations.ts'))).toBeDefined();
        });
    });
});
//# sourceMappingURL=enhanced-i18n-generator.test.js.map