import { describe, it, expect, beforeAll } from 'vitest';
import i18n from '@/i18n';

describe('i18n', () => {
  beforeAll(async () => {
    await i18n.changeLanguage('de');
  });

  it('loads German locale by default', () => {
    expect(i18n.language).toBe('de');
  });

  it('translates key in German', () => {
    expect(i18n.t('nav.dashboard')).toBe('Dashboard');
    expect(i18n.t('nav.companies')).toBe('Firmen');
    expect(i18n.t('auth.login')).toBe('Anmelden');
  });

  it('can switch to English', async () => {
    await i18n.changeLanguage('en');
    expect(i18n.language).toBe('en');
    expect(i18n.t('auth.login')).toBe('Sign In');
    expect(i18n.t('nav.companies')).toBe('Companies');
  });

  it('falls back to German for missing English keys', async () => {
    await i18n.changeLanguage('en');
    expect(i18n.t('app.name')).toBe('leocrm');
  });

  it('switches back to German', async () => {
    await i18n.changeLanguage('de');
    expect(i18n.t('auth.login')).toBe('Anmelden');
  });
});
