Skip to content

Commit

Permalink
test: Outstanding test.todo() in Search component
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 23, 2024
1 parent c377521 commit 6c2fb89
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as planxCore from "@opensystemslab/planx-core";
import { waitFor } from "@testing-library/react";
import { waitFor, within } from "@testing-library/react";
import { FullStore, useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import { act } from "react-dom/test-utils";
import { setup } from "testUtils";
import { vi } from "vitest";
import { axe } from "vitest-axe";

const mockNavigate = vi.fn();

vi.mock("react-navi", () => ({
useNavigation: () => ({
navigate: vi.fn(),
navigate: mockNavigate,
}),
}));

Expand Down Expand Up @@ -64,7 +66,7 @@ test("entering a search term displays a series of cards", async () => {
await waitFor(() => expect(getAllByRole("listitem")).toHaveLength(2));
});

test.todo("cards link to their associated nodes", async () => {
test("cards link to their associated nodes", async () => {
const { user, getAllByRole, getByLabelText } = setup(
<VirtuosoWrapper>
<Search />
Expand All @@ -77,9 +79,19 @@ test.todo("cards link to their associated nodes", async () => {
await waitFor(() => expect(getAllByRole("listitem")).toHaveLength(2));

const [first, second] = getAllByRole("listitem");
// TODO!
expect(first).toHaveAttribute("href", "link to tR9tdaWOvF (India)");
expect(second).toHaveAttribute("href", "link to tvUxd2IoPo (Indonesia)");
const urlToParentQuestion = "nodes/_root/nodes/Ej0xpn4l8u/edit";

const firstItemButton = within(first).getByRole("button");
await user.click(firstItemButton);
expect(mockNavigate).toHaveBeenCalledWith(
expect.stringContaining(urlToParentQuestion),
);

const secondItemButton = within(second).getByRole("button");
await user.click(secondItemButton);
expect(mockNavigate).toHaveBeenCalledWith(
expect.stringContaining(urlToParentQuestion),
);
});

it("orderedFlow is set in the store on render of Search", async () => {
Expand Down

0 comments on commit 6c2fb89

Please sign in to comment.