-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
249 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
apps/web/cypress/component/autoform/mantine-zod/form-props.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import { AutoForm } from "@autoform/mantine"; | ||
import { ZodProvider } from "@autoform/zod"; | ||
import { z } from "zod"; | ||
import { TestWrapper } from "./utils"; | ||
|
||
describe("AutoForm Form Props Tests (Mantine)", () => { | ||
const schema = z.object({ | ||
name: z.string(), | ||
}); | ||
|
||
const schemaProvider = new ZodProvider(schema); | ||
|
||
it("applies custom form props", () => { | ||
cy.mount( | ||
<TestWrapper> | ||
<AutoForm | ||
schema={schemaProvider} | ||
onSubmit={cy.stub().as("onSubmit")} | ||
withSubmit | ||
formProps={{ | ||
className: "custom-form-class", | ||
"data-testid": "custom-form", | ||
onKeyDown: cy.stub().as("onKeyDown"), | ||
}} | ||
/> | ||
</TestWrapper> | ||
); | ||
|
||
cy.get("form") | ||
.should("have.class", "custom-form-class") | ||
.and("have.attr", "data-testid", "custom-form"); | ||
|
||
cy.get('input[name="name"]').type("{enter}"); | ||
cy.get("@onKeyDown").should("have.been.called"); | ||
}); | ||
|
||
it("prevents form submission on enter key", () => { | ||
cy.mount( | ||
<TestWrapper> | ||
<AutoForm | ||
schema={schemaProvider} | ||
onSubmit={cy.stub().as("onSubmit")} | ||
withSubmit | ||
formProps={{ | ||
onKeyDown: (e) => { | ||
if (e.key === "Enter") e.preventDefault(); | ||
}, | ||
}} | ||
/> | ||
</TestWrapper> | ||
); | ||
|
||
cy.get('input[name="name"]').type("John Doe{enter}"); | ||
cy.get("@onSubmit").should("not.have.been.called"); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
apps/web/cypress/component/autoform/mui-zod/form-props.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from "react"; | ||
import { AutoForm } from "@autoform/mui"; | ||
import { ZodProvider } from "@autoform/zod"; | ||
import { z } from "zod"; | ||
|
||
describe("AutoForm Form Props Tests (MUI)", () => { | ||
const schema = z.object({ | ||
name: z.string(), | ||
}); | ||
|
||
const schemaProvider = new ZodProvider(schema); | ||
|
||
it("applies custom form props", () => { | ||
cy.mount( | ||
<AutoForm | ||
schema={schemaProvider} | ||
onSubmit={cy.stub().as("onSubmit")} | ||
withSubmit | ||
formProps={{ | ||
className: "custom-form-class", | ||
"data-testid": "custom-form", | ||
onKeyDown: cy.stub().as("onKeyDown"), | ||
}} | ||
/> | ||
); | ||
|
||
cy.get("form") | ||
.should("have.class", "custom-form-class") | ||
.and("have.attr", "data-testid", "custom-form"); | ||
|
||
cy.get('input[name="name"]').type("{enter}"); | ||
cy.get("@onKeyDown").should("have.been.called"); | ||
}); | ||
|
||
it("prevents form submission on enter key", () => { | ||
cy.mount( | ||
<AutoForm | ||
schema={schemaProvider} | ||
onSubmit={cy.stub().as("onSubmit")} | ||
withSubmit | ||
formProps={{ | ||
onKeyDown: (e) => { | ||
if (e.key === "Enter") e.preventDefault(); | ||
}, | ||
}} | ||
/> | ||
); | ||
|
||
cy.get('input[name="name"]').type("John Doe{enter}"); | ||
cy.get("@onSubmit").should("not.have.been.called"); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
apps/web/cypress/component/autoform/shadcn-zod/form-props.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import { AutoForm } from "@autoform/shadcn/components/ui/autoform/AutoForm"; | ||
import { ZodProvider } from "@autoform/zod"; | ||
import { z } from "zod"; | ||
import { TestWrapper } from "./utils"; | ||
|
||
describe("AutoForm Form Props Tests (shadcn)", () => { | ||
const schema = z.object({ | ||
name: z.string(), | ||
}); | ||
|
||
const schemaProvider = new ZodProvider(schema); | ||
|
||
it("applies custom form props", () => { | ||
cy.mount( | ||
<TestWrapper> | ||
<AutoForm | ||
schema={schemaProvider} | ||
onSubmit={cy.stub().as("onSubmit")} | ||
withSubmit | ||
formProps={{ | ||
className: "custom-form-class", | ||
"data-testid": "custom-form", | ||
onKeyDown: cy.stub().as("onKeyDown"), | ||
}} | ||
/> | ||
</TestWrapper> | ||
); | ||
|
||
cy.get("form") | ||
.should("have.class", "custom-form-class") | ||
.and("have.attr", "data-testid", "custom-form"); | ||
|
||
cy.get('input[name="name"]').type("{enter}"); | ||
cy.get("@onKeyDown").should("have.been.called"); | ||
}); | ||
|
||
it("prevents form submission on enter key", () => { | ||
cy.mount( | ||
<TestWrapper> | ||
<AutoForm | ||
schema={schemaProvider} | ||
onSubmit={cy.stub().as("onSubmit")} | ||
withSubmit | ||
formProps={{ | ||
onKeyDown: (e) => { | ||
if (e.key === "Enter") e.preventDefault(); | ||
}, | ||
}} | ||
/> | ||
</TestWrapper> | ||
); | ||
|
||
cy.get('input[name="name"]').type("John Doe{enter}"); | ||
cy.get("@onSubmit").should("not.have.been.called"); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
import React from "react"; | ||
import { Box } from "@mantine/core"; | ||
|
||
export const Form: React.FC<{ | ||
onSubmit: (e: React.FormEvent) => void; | ||
children: React.ReactNode; | ||
}> = ({ onSubmit, children }) => { | ||
export const Form = React.forwardRef< | ||
HTMLFormElement, | ||
React.ComponentProps<"form"> | ||
>(({ children, ...props }, ref) => { | ||
return ( | ||
<Box | ||
component="form" | ||
onSubmit={onSubmit} | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: 15, | ||
}} | ||
ref={ref} | ||
{...props} | ||
> | ||
{children} | ||
</Box> | ||
); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import React from "react"; | ||
import Box from "@mui/material/Box"; | ||
|
||
export const Form: React.FC<{ | ||
onSubmit: (e: React.FormEvent) => void; | ||
children: React.ReactNode; | ||
}> = ({ onSubmit, children }) => { | ||
export const Form = React.forwardRef< | ||
HTMLFormElement, | ||
React.ComponentProps<"form"> | ||
>(({ children, ...props }, ref) => { | ||
return ( | ||
<Box component="form" onSubmit={onSubmit} noValidate autoComplete="off"> | ||
<Box component="form" ref={ref} noValidate autoComplete="off" {...props}> | ||
{children} | ||
</Box> | ||
); | ||
}; | ||
}); |
Oops, something went wrong.