import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { NotFoundTemplate, type NotFoundViewData } from './NotFoundTemplate';

describe('NotFoundTemplate', () => {
  const mockViewData: NotFoundViewData = {
    errorCode: 'Error 404',
    title: 'OFF TRACK',
    message: 'The requested sector does not exist.',
    actionLabel: 'Return to Pits'
  };

  const mockOnHomeClick = vi.fn();

  it('renders the error code, title and message', () => {
    render(<NotFoundTemplate viewData={mockViewData} onHomeClick={mockOnHomeClick} />);
    
    expect(screen.getByText('Error 404')).toBeDefined();
    expect(screen.getByText('OFF TRACK')).toBeDefined();
    expect(screen.getByText('The requested sector does not exist.')).toBeDefined();
  });

  it('calls onHomeClick when the button is clicked', () => {
    render(<NotFoundTemplate viewData={mockViewData} onHomeClick={mockOnHomeClick} />);
    
    const button = screen.getByText('Return to Pits');
    fireEvent.click(button);
    
    expect(mockOnHomeClick).toHaveBeenCalledTimes(1);
  });
});
