Skip to content

Commit 8156633

Browse files
tests: add mui tests (native Enum)
1 parent 6849e21 commit 8156633

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

apps/web/cypress/component/autoform/mui-yup/basics.cy.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ import { AutoForm } from "@autoform/mui";
33
import { YupProvider, fieldConfig } from "@autoform/yup";
44
import * as Yup from "yup";
55

6+
enum Sports {
7+
Football = "Football/Soccer",
8+
Basketball = "Basketballs",
9+
Baseball = "Baseballs",
10+
Hockey = "Hockey (Ice)",
11+
None = "I don't like sports",
12+
}
13+
614
describe("AutoForm Basic Tests (MUI-YUP)", () => {
715
const basicSchema = Yup.object({
816
name: Yup.string().min(2, "Name must be at least 2 characters"),
917
age: Yup.number().min(18, "Must be at least 18 years old"),
1018
email: Yup.string().email("Invalid email address"),
1119
website: Yup.string().url("Invalid URL").optional(),
20+
sports: Yup.mixed().oneOf(Object.values(Sports)),
1221
birthdate: Yup.date(),
1322
isStudent: Yup.boolean(),
1423
});
@@ -28,6 +37,7 @@ describe("AutoForm Basic Tests (MUI-YUP)", () => {
2837
cy.get('input[name="age"]').should("have.attr", "type", "number");
2938
cy.get('input[name="email"]').should("exist");
3039
cy.get('input[name="website"]').should("exist");
40+
cy.get('input[name="sports"]').should("exist");
3141
cy.get('input[name="birthdate"]').should("have.attr", "type", "date");
3242
cy.get('input[name="isStudent"]').should("have.attr", "type", "checkbox");
3343
});
@@ -42,6 +52,8 @@ describe("AutoForm Basic Tests (MUI-YUP)", () => {
4252
cy.get('input[name="age"]').type("25");
4353
cy.get('input[name="email"]').type("[email protected]");
4454
cy.get('input[name="website"]').type("https://example.com");
55+
cy.get("#mui-component-select-sports").click();
56+
cy.get('.MuiMenuItem-root[data-value="Hockey (Ice)"]').click();
4557
cy.get('input[name="birthdate"]').type("1990-01-01");
4658
cy.get('input[name="isStudent"]').check();
4759

@@ -53,6 +65,7 @@ describe("AutoForm Basic Tests (MUI-YUP)", () => {
5365
age: 25,
5466
5567
website: "https://example.com",
68+
sports: "Hockey (Ice)",
5669
birthdate: new Date("1990-01-01"),
5770
isStudent: true,
5871
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ import { AutoForm } from "@autoform/mui";
33
import { ZodProvider, fieldConfig } from "@autoform/zod";
44
import { z } from "zod/v3";
55

6+
enum Sports {
7+
Football = "Football/Soccer",
8+
Basketball = "Basketballs",
9+
Baseball = "Baseballs",
10+
Hockey = "Hockey (Ice)",
11+
None = "I don't like sports",
12+
}
13+
614
describe("AutoForm Basic Tests (MUI-ZOD)", () => {
715
const basicSchema = z.object({
816
name: z.string().min(2, "Name must be at least 2 characters"),
917
age: z.coerce.number().min(18, "Must be at least 18 years old"),
1018
email: z.string().email("Invalid email address"),
1119
website: z.string().url("Invalid URL").optional(),
20+
sports: z.nativeEnum(Sports),
1221
birthdate: z.coerce.date(),
1322
isStudent: z.boolean(),
1423
});
@@ -28,6 +37,7 @@ describe("AutoForm Basic Tests (MUI-ZOD)", () => {
2837
cy.get('input[name="age"]').should("have.attr", "type", "number");
2938
cy.get('input[name="email"]').should("exist");
3039
cy.get('input[name="website"]').should("exist");
40+
cy.get('input[name="sports"]').should("exist");
3141
cy.get('input[name="birthdate"]').should("have.attr", "type", "date");
3242
cy.get('input[name="isStudent"]').should("have.attr", "type", "checkbox");
3343
});
@@ -42,6 +52,8 @@ describe("AutoForm Basic Tests (MUI-ZOD)", () => {
4252
cy.get('input[name="age"]').type("25");
4353
cy.get('input[name="email"]').type("[email protected]");
4454
cy.get('input[name="website"]').type("https://example.com");
55+
cy.get("#mui-component-select-sports").click();
56+
cy.get('.MuiMenuItem-root[data-value="Hockey (Ice)"]').click();
4557
cy.get('input[name="birthdate"]').type("1990-01-01");
4658
cy.get('input[name="isStudent"]').check();
4759

@@ -53,6 +65,7 @@ describe("AutoForm Basic Tests (MUI-ZOD)", () => {
5365
age: 25,
5466
5567
website: "https://example.com",
68+
sports: "Hockey (Ice)",
5669
birthdate: new Date("1990-01-01"),
5770
isStudent: true,
5871
});

0 commit comments

Comments
 (0)