import { fireEvent, render, screen } from '@testing-library/react';
import { PrimaryButton, SecondaryButton, DisabledButton } from './Button.stories';

it('should call the onClick function when Primary button is clicked', () => {
  const spyHandleOnClick = jest.fn();
  render(<PrimaryButton variant='contained' color='primary' label='Primary Button' onClick={spyHandleOnClick} />);
  const button = screen.getByText('Primary Button');

  fireEvent.click(button);

  expect(button).toBeInTheDocument();
  expect(spyHandleOnClick).toHaveBeenCalledTimes(1);
});

it('should call the onClick function when Secondary button is clicked', () => {
  const spyHandleOnClick = jest.fn();
  render(<SecondaryButton variant='outlined' color='primary' label='Secondary Button' onClick={spyHandleOnClick} />);
  const button = screen.getByText('Secondary Button');

  fireEvent.click(button);

  expect(button).toBeInTheDocument();
  expect(spyHandleOnClick).toHaveBeenCalledTimes(1);
});

it('should not call the onClick function when Disabled button is clicked', () => {
  render(<DisabledButton disabled variant='contained' color='primary' label='Disabled Button' onClick={jest.fn()} />);
  const button = screen.getByText('Disabled Button');

  expect(button).toBeInTheDocument();
  expect(button).toHaveAttribute('disabled');
});
