import { render, screen, fireEvent } from '@testing-library/react';
import { ActionBar } from '../ActionBar';

describe('ActionBar', () => {
  it('renders both buttons with correct text', () => {
    const onAddVehicle = jest.fn();
    const onLogFuel = jest.fn();

    render(<ActionBar onAddVehicle={onAddVehicle} onLogFuel={onLogFuel} />);

    expect(screen.getByText('Add Vehicle')).toBeInTheDocument();
    expect(screen.getByText('Log Fuel')).toBeInTheDocument();
  });

  it('calls onAddVehicle when Add Vehicle button clicked', () => {
    const onAddVehicle = jest.fn();
    const onLogFuel = jest.fn();

    render(<ActionBar onAddVehicle={onAddVehicle} onLogFuel={onLogFuel} />);

    const addVehicleButton = screen.getByText('Add Vehicle');
    fireEvent.click(addVehicleButton);

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

  it('calls onLogFuel when Log Fuel button clicked', () => {
    const onAddVehicle = jest.fn();
    const onLogFuel = jest.fn();

    render(<ActionBar onAddVehicle={onAddVehicle} onLogFuel={onLogFuel} />);

    const logFuelButton = screen.getByText('Log Fuel');
    fireEvent.click(logFuelButton);

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