Skip to content

Commit

Permalink
alter testing for new format
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Dec 19, 2024
1 parent 93a08c2 commit 007aa96
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
import React from "react";
import { setup } from "testUtils";
import { vi } from "vitest";
Expand All @@ -9,7 +9,7 @@ import ExternalPortalForm from "./Editor";
test("adding an external portal", async () => {
const handleSubmit = vi.fn();

setup(
const { user } = setup(
<ExternalPortalForm
flows={[
{ id: "a", name: "flow a", slug: "flow-a", team: "team" },
Expand All @@ -18,13 +18,22 @@ test("adding an external portal", async () => {
handleSubmit={handleSubmit}
/>,
);
const autocompleteComp = screen.getByTestId("flowId");
const autocompleteInput = within(autocompleteComp).getByRole("combobox");

expect(screen.getByTestId("flowId")).toHaveValue("");
screen.debug(autocompleteInput);

await fireEvent.change(screen.getByTestId("flowId"), {
target: { value: "b" },
});
await fireEvent.submit(screen.getByTestId("form"));
expect(autocompleteInput).toHaveValue("");

await user.click(autocompleteInput);

await user.click(screen.getByTestId("flow-b"));

expect(autocompleteInput).toHaveValue("flow b");

const extPortalForm = screen.getByTestId("form");

fireEvent.submit(extPortalForm);

await waitFor(() =>
expect(handleSubmit).toHaveBeenCalledWith({
Expand All @@ -41,9 +50,8 @@ test("adding an external portal", async () => {
test("changing an external portal", async () => {
const handleSubmit = vi.fn();

setup(
const { user } = setup(
<ExternalPortalForm
id="test"
flowId="b"
flows={[
{ id: "a", name: "flow a", slug: "flow-a", team: "team" },
Expand All @@ -53,12 +61,20 @@ test("changing an external portal", async () => {
/>,
);

expect(screen.getByTestId("flowId")).toHaveValue("b");
const autocompleteComp = screen.getByTestId("flowId");
const autocompleteInput = within(autocompleteComp).getByRole("combobox");

expect(autocompleteInput).toHaveValue("flow b");

await user.click(autocompleteInput);

await user.click(screen.getByTestId("flow-a"));

expect(autocompleteInput).toHaveValue("flow a");

const extPortalForm = screen.getByTestId("form");

await fireEvent.change(screen.getByTestId("flowId"), {
target: { value: "a" },
});
await fireEvent.submit(screen.getByTestId("form"));
fireEvent.submit(extPortalForm);

await waitFor(() =>
expect(handleSubmit).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const renderOption: FlowAutocompleteListProps["renderOption"] = (
<MenuItem
{...props}
key={option.id}
data-testid={`flow-${option.id}`}
sx={(theme) => ({ paddingY: `${theme.spacing(1.25)}` })}
>
{option.name}
Expand Down Expand Up @@ -149,6 +150,8 @@ const ExternalPortalForm: React.FC<{
</ModalSectionContent>
<ModalSectionContent title="Pick a flow">
<Autocomplete
data-testid="flowId"
id="flowId"
role="status"
aria-atomic={true}
aria-live="polite"
Expand Down

0 comments on commit 007aa96

Please sign in to comment.