Skip to content

Commit 926f9dc

Browse files
tests: add mantine tests (native Enum), update select to use label (value of enum key)
1 parent fa3632f commit 926f9dc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

apps/web/cypress/component/autoform/mantine-zod/basic.cy.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ import { ZodProvider, fieldConfig } from "@autoform/zod";
44
import { z } from "zod/v3";
55
import { TestWrapper } from "./utils";
66

7+
enum Sports {
8+
Football = "Football/Soccer",
9+
Basketball = "Basketballs",
10+
Baseball = "Baseballs",
11+
Hockey = "Hockey (Ice)",
12+
None = "I don't like sports",
13+
}
14+
715
describe("AutoForm Basic Tests (MANTINE-ZOD)", () => {
816
const basicSchema = z.object({
917
name: z.string().min(2, "Name must be at least 2 characters"),
1018
age: z.coerce.number().min(18, "Must be at least 18 years old"),
1119
email: z.string().email("Invalid email address"),
1220
website: z.string().url("Invalid URL").optional(),
21+
sports: z.nativeEnum(Sports),
1322
birthdate: z.coerce.date(),
1423
isStudent: z.boolean(),
1524
});
@@ -31,6 +40,7 @@ describe("AutoForm Basic Tests (MANTINE-ZOD)", () => {
3140
cy.get('input[name="age"]').should("have.attr", "type", "number");
3241
cy.get('input[name="email"]').should("exist");
3342
cy.get('input[name="website"]').should("exist");
43+
cy.get('input[name="sports"]').should("exist");
3444
cy.get('[data-dates-input="true"]').should("exist");
3545
cy.get('input[name="isStudent"]').should("have.attr", "type", "checkbox");
3646
});
@@ -47,9 +57,13 @@ describe("AutoForm Basic Tests (MANTINE-ZOD)", () => {
4757
cy.get('input[name="age"]').type("25");
4858
cy.get('input[name="email"]').type("[email protected]");
4959
cy.get('input[name="website"]').type("https://example.com");
50-
cy.get('[data-dates-input="true"]').type("1990-01-01");
5160
cy.get('input[name="isStudent"]').check();
52-
61+
cy.get(".mantine-Select-input").eq(0).click();
62+
cy.get('.mantine-Select-option[value="Hockey (Ice)"]')
63+
.should("exist")
64+
.and("be.visible")
65+
.click();
66+
cy.get('[data-dates-input="true"]').type("1990-01-01");
5367
cy.get('button[type="submit"]').click();
5468

5569
cy.get("@onSubmit").should("have.been.calledOnce");
@@ -58,6 +72,7 @@ describe("AutoForm Basic Tests (MANTINE-ZOD)", () => {
5872
age: 25,
5973
6074
website: "https://example.com",
75+
sports: "Hockey (Ice)",
6176
birthdate: new Date("1990-01-01"),
6277
isStudent: true,
6378
});

packages/mantine/src/components/SelectField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const SelectField: React.FC<AutoFormFieldProps> = ({
3030
defaultValue={value}
3131
description={field.fieldConfig?.description}
3232
data={(field.options || []).map(([key, label]) => ({
33-
value: key,
33+
value: label,
3434
label,
3535
}))}
3636
/>

0 commit comments

Comments
 (0)