import { ActionGroup, Button, Form, FormGroup, Page, PageSection, } from "@patternfly/react-core"; import { mount } from "cypress/react"; import { useEffect } from "react"; import { FormProvider, useForm } from "react-hook-form"; import { MultiLineInput, MultiLineInputProps, } from "../../src/components/multi-line-input/MultiLineInput"; type MultiLineInputTestProps = Omit & { submit: (values: any) => void; defaultValues?: string | string[]; }; describe("MultiLineInput", () => { const MultiLineInputTest = ({ submit, defaultValues, ...rest }: MultiLineInputTestProps) => { const form = useForm(); useEffect(() => { form.setValue("name", defaultValues || ""); }, [form.setValue]); return (
); }; it("basic interaction", () => { const submit = cy.spy().as("onSubmit"); mount(); cy.get("input").should("exist"); cy.findByTestId("name0").type("value"); cy.findAllByTestId("save").click(); cy.get("@onSubmit").should("have.been.calledWith", { name: ["value"] }); }); it("add values", () => { const submit = cy.spy().as("onSubmit"); mount(); cy.findByTestId("name0").type("value"); cy.findByTestId("addValue").click(); cy.findByTestId("name1").type("value1"); cy.findByTestId("addValue").click(); cy.findByTestId("name2").type("value2"); cy.findAllByTestId("save").click(); cy.get("@onSubmit").should("have.been.calledWith", { name: ["value", "value1", "value2"], }); }); it("from existing values as string", () => { const submit = cy.spy().as("onSubmit"); mount( ); cy.findByTestId("name0").should("have.value", "one"); cy.findByTestId("name1").should("have.value", "two"); cy.findByTestId("name2").should("have.value", "three"); cy.findByTestId("addValue").click(); cy.findByTestId("name3").type("four"); cy.findAllByTestId("save").click(); cy.get("@onSubmit").should("have.been.calledWith", { name: "one##two##three##four", }); }); it("from existing values as string[]", () => { const submit = cy.spy().as("onSubmit"); mount( ); cy.findByTestId("name0").should("have.value", "one"); cy.findByTestId("name1").should("have.value", "two"); cy.findByTestId("name2").should("have.value", "three"); cy.findByTestId("remove0").click(); cy.findAllByTestId("save").click(); cy.get("@onSubmit").should("have.been.calledWith", { name: ["two", "three"], }); }); it("remove test", () => { const submit = cy.spy().as("onSubmit"); mount( ); cy.findByTestId("remove0").click(); cy.findByTestId("remove2").click(); cy.findByTestId("remove2").click(); cy.findAllByTestId("save").click(); cy.get("@onSubmit").should("have.been.calledWith", { name: ["two", "three", "six"], }); }); it("add / update test", () => { const submit = cy.spy().as("onSubmit"); mount(); cy.findByTestId("name0").type("-one"); cy.findByTestId("addValue").click(); cy.findByTestId("name1").type("twos"); cy.findAllByTestId("save").click(); cy.get("@onSubmit").should("have.been.calledWith", { name: ["one-one", "twos"], }); }); });