import { renderWithClient } from '../../utils/test/react-query';
import CreateIntroducerForm from './create-introducer-form';
import userEvent from '@testing-library/user-event';
import { waitFor } from '@testing-library/react';
import * as introducerAPI from '../../api/introducer';
import { MemoryRouter } from 'react-router-dom';

describe('CreateIntroducerForm component', () => {
  test('successful render component', async () => {
    const result = renderWithClient(<CreateIntroducerForm />, MemoryRouter);
    expect(await result.findByTestId('create-introducer-form')).toBeInTheDocument();
  });

  test('call create introducer function with correct arguments', async () => {
    const createIntroducerSpy = jest.spyOn(introducerAPI, 'createIntroducer');

    const result = renderWithClient(<CreateIntroducerForm />, MemoryRouter);
    const user = userEvent.setup();
    await user.click(await result.getByTestId('termsAndConditions-field'));
    await user.click(await result.getByRole('button', { name: /تایید/i }));

    await waitFor(() => expect(createIntroducerSpy).toHaveBeenCalledWith({ iban: '' }));
    createIntroducerSpy.mockRestore();
  });
});
