1 import { screen, waitFor } from '@testing-library/react';
2 import userEvent from '@testing-library/user-event';
4 import { render } from '../../helpers/test/render';
5 import Participant from './Participant';
7 describe('Participant', () => {
8 const onCreateOrEditContactCallback = jest.fn();
10 icon: <span>{'Icon'}</span>,
15 email: 'email@provider.com',
18 onCreateOrEditContact: onCreateOrEditContactCallback,
22 onCreateOrEditContactCallback.mockClear();
25 it('should render correctly', () => {
26 const { rerender } = render(<Participant {...props} />);
28 expect(screen.getByText(props.name)).toBeInTheDocument();
29 expect(screen.getByText(props.email)).toBeInTheDocument();
30 expect(screen.getByText(props.initials)).toBeInTheDocument();
31 expect(screen.getByText('Icon')).toBeInTheDocument();
33 rerender(<Participant {...props} extraText="extraText" />);
34 expect(screen.getByText('extraText')).toBeInTheDocument();
37 it('should render email only one time', () => {
38 render(<Participant {...props} name={props.email} />);
39 expect(screen.getByText(props.email)).toBeInTheDocument();
40 expect(screen.queryAllByText(props.email)).toHaveLength(1);
43 it('should not render email if isCurrentUser', () => {
44 render(<Participant {...props} isCurrentUser />);
45 expect(screen.queryByText(props.email)).not.toBeInTheDocument();
48 it('should render dropdown on user click', async () => {
49 render(<Participant {...props} />);
51 await userEvent.click(screen.getByTitle('More options'));
54 expect(screen.getByText('Copy email address')).toBeInTheDocument();
56 expect(screen.getByText('View contact details')).toBeInTheDocument();
59 describe('Contact modals callbacks', () => {
60 it('should call contact details modal callback', async () => {
61 render(<Participant {...props} isContact />);
63 await userEvent.click(screen.getByTitle('More options'));
66 expect(screen.getByText('View contact details')).toBeInTheDocument();
69 await userEvent.click(screen.getByText('View contact details'));
71 expect(onCreateOrEditContactCallback).toHaveBeenCalledTimes(1);
74 it('should call add contact modal callback', async () => {
75 render(<Participant {...props} isContact={false} />);
77 await userEvent.click(screen.getByTitle('More options'));
80 expect(screen.getByText('Create new contact')).toBeInTheDocument();
83 await userEvent.click(screen.getByText('Create new contact'));
85 expect(onCreateOrEditContactCallback).toHaveBeenCalledTimes(1);