summaryrefslogtreecommitdiff
path: root/client/src/components/RsvpForm.test.tsx
blob: a871268034c03ed181e9543433d420220bc15f8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import '@testing-library/jest-dom';
import React from 'react';
import { fireEvent } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import { describe, expect, it } from 'vitest';
import { createMemoryRouter, RouterProvider } from 'react-router-dom';
import { renderWithProviders } from '../renderWithProviders';
import routes from '../routes';
import setupStore from '../store';
import { initialGuest } from '../mocks/handlers';
import { setGuest } from '../slices/auth/guestSlice';

describe('RSVP form', async () => {
  const memoryRouter = createMemoryRouter(routes, {
    initialEntries: ['/rsvp'],
  });
  it('can submit', async () => {
    const store = setupStore();
    store.dispatch(setGuest(initialGuest));
    const { getByLabelText, getByRole, findByText } = renderWithProviders(
      <RouterProvider router={memoryRouter} />,
      { store }
    );
    const user = userEvent.setup();

    fireEvent.click(getByLabelText(/accept/i), { target: { clicked: true } });
    await user.type(getByLabelText(/email/i), 'mhunteman@cox.net');
    fireEvent.click(getByRole('button', { name: 'RSVP' }));
    expect(await findByText(/RSVP updated/i)).toBeInTheDocument();
  });
});