Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Map and Label Copy Tests #3695

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 102 additions & 12 deletions editor.planx.uk/src/@planx/components/MapAndLabel/Public/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,108 @@ describe("basic interactions - happy path", () => {
});

describe("copy feature select", () => {
it.todo("is disabled if only a single feature is present");
// no copy select if only one feature
it.todo("is enabled once multiple features are present");
// copy select enabled once you add more features
it.todo(
"lists all other features as options (the current feature is not listed)"
);
// current tree is not an option in the copy select
it.todo("copies all data from one feature to another");
// all data fields are populated from one field to another
it.todo("should not have any accessibility violations");
// axe checks
it("is disabled if only a single feature is present", async () => {
const { getByTestId, getByTitle } = setup(<MapAndLabel {...props} />);
const map = getByTestId("map-and-label-map");

addFeaturesToMap(map, [point1]);

const copyTitle = getByTitle("Copy from");

const copyInput = within(copyTitle).getByRole("combobox");

expect(copyInput).toHaveAttribute("aria-disabled", "true");
});

it("is enabled once multiple features are present", async () => {
const { getByTitle } = setup(<MapAndLabel {...props} />);

addMultipleFeatures([point1, point2]);

const copyTitle = getByTitle("Copy from");

const copyInput = within(copyTitle).getByRole("combobox");

expect(copyInput).not.toHaveAttribute("aria-disabled", "true");
RODO94 marked this conversation as resolved.
Show resolved Hide resolved
});

it("lists all other features as options (the current feature is not listed)", async () => {
const { getByTitle, user, queryByRole } = setup(<MapAndLabel {...props} />);
addMultipleFeatures([point1, point2]);

const copyTitle = getByTitle("Copy from");

const copyInput = within(copyTitle).getByRole("combobox");

expect(copyInput).not.toHaveAttribute("aria-disabled", "true");

await user.click(copyInput);

// Current item would be Tree 2 since we added two points
const listItemTwo = queryByRole("option", { name: "Tree 2" });

expect(listItemTwo).not.toBeInTheDocument();
});

it("copies all data from one feature to another", async () => {
RODO94 marked this conversation as resolved.
Show resolved Hide resolved
const { getByTitle, user, getByLabelText, getByRole } = setup(
<MapAndLabel {...props} />
);
addMultipleFeatures([point1, point2]);
const tabOne = getByRole("tab", { name: /Tree 1/ });

await fillOutForm(user);

const speciesInputTwo = getByLabelText("Species");
const workInputTwo = getByLabelText("Proposed work");
const justificationInputTwo = getByLabelText("Justification");
const urgencyDivTwo = getByTitle("Urgency");
const urgencySelectTwo = within(urgencyDivTwo).getByRole("combobox");

expect(speciesInputTwo).toHaveDisplayValue("Larch");
expect(workInputTwo).toHaveDisplayValue("Chopping it down");
expect(justificationInputTwo).toHaveDisplayValue("Cause I can");
expect(urgencySelectTwo).toHaveTextContent("Low");
RODO94 marked this conversation as resolved.
Show resolved Hide resolved

await user.click(tabOne);

const copyTitle = getByTitle("Copy from");

const copyInput = within(copyTitle).getByRole("combobox", {
name: "Copy from",
});
await user.click(copyInput);
const listItemTwo = getByRole("option", { name: "Tree 2" });

await user.click(listItemTwo);

const speciesInputOne = getByLabelText("Species");
const workInputOne = getByLabelText("Proposed work");
const justificationInputOne = getByLabelText("Justification");
const urgencyDivOne = getByTitle("Urgency");
const urgencySelectOne = within(urgencyDivOne).getByRole("combobox");

expect(speciesInputOne).toHaveDisplayValue("Larch");
expect(workInputOne).toHaveDisplayValue("Chopping it down");
expect(justificationInputOne).toHaveDisplayValue("Cause I can");
expect(urgencySelectOne).toHaveTextContent("Low");
});

it("should not have any accessibility violations", async () => {
const { getByTitle, user, container } = setup(<MapAndLabel {...props} />);
addMultipleFeatures([point1, point2]);

const copyTitle = getByTitle("Copy from");

const copyInput = within(copyTitle).getByRole("combobox");

expect(copyInput).not.toHaveAttribute("aria-disabled", "true");
RODO94 marked this conversation as resolved.
Show resolved Hide resolved

await user.click(copyInput);

const results = await axe(container);
expect(results).toHaveNoViolations();
});
});

describe("remove feature button", () => {
Expand Down
Loading