import { beforeEach, describe, expect, it } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/react';
import LanguageSwitcher from '@/components/LanguageSwitcher';

describe('LanguageSwitcher', () => {
  beforeEach(() => {
    localStorage.clear();
  });

  it('switches language without reloading the page', () => {
    localStorage.setItem('language', 'en');

    render(<LanguageSwitcher />);

    const button = screen.getByRole('button', { name: 'Switch to Spanish' });
    fireEvent.click(button);

    expect(localStorage.getItem('language')).toBe('es');
    expect(screen.getByRole('button', { name: 'Switch to English' })).toBeInTheDocument();
  });
});
