// src/components/AnonymousUserBanner.test.tsx
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { AnonymousUserBanner } from './AnonymousUserBanner';

describe('AnonymousUserBanner', () => {
  it('should render the banner with the correct text content', () => {
    const mockOnOpenProfile = vi.fn();
    render(<AnonymousUserBanner onOpenProfile={mockOnOpenProfile} />);

    expect(screen.getByText(/you're viewing as a guest/i)).toBeInTheDocument();
    expect(screen.getByText(/to save your flyers, create a watchlist, and access more features/i)).toBeInTheDocument();
    expect(screen.getByRole('button', { name: /sign up or log in/i })).toBeInTheDocument();
  });

  it('should call onOpenProfile when the "sign up or log in" button is clicked', () => {
    const mockOnOpenProfile = vi.fn();
    render(<AnonymousUserBanner onOpenProfile={mockOnOpenProfile} />);

    const loginButton = screen.getByRole('button', { name: /sign up or log in/i });
    fireEvent.click(loginButton);

    expect(mockOnOpenProfile).toHaveBeenCalledTimes(1);
  });
});