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

describe('Coupon Component', () => {
  it('renders with provided props', () => {
    const code = 'TESTCODE';

    const { container, getByText } = render(
      <Coupon code={code} status="active" templateOne showprefix />
    );

    const couponButton = getByText(code);
    expect(couponButton).toBeInTheDocument();
    expect(getByText('Code:')).toBeInTheDocument();
    expect(container.querySelectorAll('span')).toHaveLength(1);
    expect(container.querySelectorAll('button')).toHaveLength(1);
    expect(container.querySelector('button')).toHaveAttribute('type', 'button');
    expect(container.querySelector('button')).not.toHaveAttribute('disabled', '');
  });

  it('renders with provided props button Click', () => {
    const code = 'TESTCODE';

    const { container } = render(<Coupon code={code} status="active" templateOne showprefix />);

    const button = container.querySelector('button');

    fireEvent.click(button);
  });

  it('renders with provided props status incactive', () => {
    const code = 'TESTCODE';

    const { container } = render(<Coupon code={code} status="inactive" templateTwo showprefix />);

    expect(container.querySelector('button')).toHaveAttribute('disabled', '');
  });
});
