forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

breadcrumbs.test.tsx25 lines, 1.1 KiBHistoryRawDownload
1import { cleanup, render, screen } from "@solidjs/testing-library";
2import type { JSX } from "solid-js";
3import { afterEach, expect, test, vi } from "vitest";
4import { Breadcrumbs } from "@/components/layout/breadcrumbs";
5import { PreferencesProvider } from "@/stores/preferences-context";
6
7vi.mock("@tanstack/solid-router", () => ({
8 Link: (props: { to: string; children: JSX.Element; class?: string }) => <a href={props.to} class={props.class}>{props.children}</a>,
9}));
10
11afterEach(cleanup);
12
13test("links every ancestor and marks the last crumb as the current page", () => {
14 render(() => (
15 <PreferencesProvider>
16 <Breadcrumbs items={[{ label: "Courses", to: "/courses" }, { label: "Algebra", to: "/courses/$id" }, { label: "9-A" }]} />
17 </PreferencesProvider>
18 ));
19
20 const nav = screen.getByRole("navigation");
21 expect(nav.getAttribute("aria-label")).toBeTruthy();
22 expect(screen.getAllByRole("link").map((link) => link.getAttribute("href"))).toEqual(["/courses", "/courses/$id"]);
23 expect(screen.getByText("9-A").getAttribute("aria-current")).toBe("page");
24 expect(screen.getByText("Algebra").getAttribute("aria-current")).toBeNull();
25});