import React from 'react';

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { GrafanaTeam } from 'models/grafana_team/grafana_team.types';

import { TeamResponder } from './TeamResponder';

describe('TeamResponder', () => {
  const team = {
    avatar_url: 'https://example.com',
    name: 'my test team',
  } as GrafanaTeam;

  test('it calls the delete callback', async () => {
    const handleDelete = jest.fn();

    render(<TeamResponder team={team} handleDelete={handleDelete} />);

    const deleteIcon = await screen.findByTestId('team-responder-delete-icon');
    await userEvent.click(deleteIcon);

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