From a88f613da7e5567dbfdebd7df94f94507c47c6b5 Mon Sep 17 00:00:00 2001 From: Michael Hunteman Date: Fri, 27 Sep 2024 08:43:02 -0700 Subject: Add vitests --- client/src/components/RsvpForm.test.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 client/src/components/RsvpForm.test.tsx (limited to 'client/src/components/RsvpForm.test.tsx') diff --git a/client/src/components/RsvpForm.test.tsx b/client/src/components/RsvpForm.test.tsx new file mode 100644 index 0000000..a871268 --- /dev/null +++ b/client/src/components/RsvpForm.test.tsx @@ -0,0 +1,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( + , + { 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(); + }); +}); -- cgit v1.2.3