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
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
fillOutForm,
fillOutSecondHalfOfForm,
} from "../test/utils";
import { mockTreeData } from "../test/mocks/GenericValues";

beforeAll(() => {
if (!window.customElements.get("my-map")) {
Expand Down Expand Up @@ -332,18 +333,97 @@ 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);

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 urgencyDiv = getByTitle("Urgency");
const urgencySelect = within(urgencyDiv).getByRole("combobox");

expect(getByLabelText("Species")).toHaveDisplayValue(mockTreeData.species);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DafyddLlyr is this the sort of thing you meant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

expect(getByLabelText("Proposed work")).toHaveDisplayValue(
mockTreeData.work
);
expect(getByLabelText("Justification")).toHaveDisplayValue(
mockTreeData.justification
);
expect(urgencySelect).toHaveTextContent(mockTreeData.urgency);
});

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");

await user.click(copyInput);

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

describe("remove feature button", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ export const mockTreeData = {
species: "Larch",
work: "Chopping it down",
justification: "Cause I can",
urgency: "High",
completionDate: { day: "", month: "", year: "" },
urgency: "Low",
};
Loading