test setup lackin
This commit is contained in:
19
src/app/_components/Test/TestingTest.client.test.tsx
Normal file
19
src/app/_components/Test/TestingTest.client.test.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import TestingTest from "./TestingTest";
|
||||
import { test } from 'vitest'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import { userEvent } from '@testing-library/user-event'
|
||||
import { FormMutationContextProvider } from "../Form/Components/MutationProvider";
|
||||
|
||||
test('TestingTest', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<TestingTest/>
|
||||
)
|
||||
const submitButton = screen.getByTestId('form-submit')
|
||||
screen.debug()
|
||||
user.click(submitButton)
|
||||
await waitFor(() => {
|
||||
screen.getByTestId('submitted')
|
||||
})
|
||||
screen.debug()
|
||||
})
|
||||
33
src/app/_components/Test/TestingTest.tsx
Normal file
33
src/app/_components/Test/TestingTest.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useForm } from "react-hook-form";
|
||||
import { FormScaffold } from "../Form/Components";
|
||||
import z from "zod";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useState } from "react";
|
||||
import { FormMutationContextProvider } from "../Form/Components/MutationProvider";
|
||||
|
||||
export default function TestingTest() {
|
||||
const schema = z.object({ text: z.string() })
|
||||
const [submitted, setSubmitted] = useState(false)
|
||||
const fakeMutation = {
|
||||
error: {message: "test"},
|
||||
status: "idle" as const,
|
||||
mutate: (_:{id:string}) => {}
|
||||
}
|
||||
const form = useForm<z.infer<typeof schema>>({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
text: ""
|
||||
}
|
||||
})
|
||||
const onSubmit = (_: z.infer<typeof schema>) => {
|
||||
setSubmitted(true)
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<div data-testid={submitted ? "submitted" : "unsubmitted"} />
|
||||
<FormMutationContextProvider value={{ createMutation: fakeMutation, updateMutation: fakeMutation, deleteMutation: fakeMutation }}>
|
||||
<FormScaffold form={form} onSubmit={onSubmit} title="Testing Test" />
|
||||
</FormMutationContextProvider>
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user