import { describe, expect, test } from "bun:test"; import twuiLinkMatchesPath from "./link-matches-path"; describe("twuiLinkMatchesPath", () => { test("matches the exact path", () => { expect(twuiLinkMatchesPath({ href: "/blog", pathname: "/blog" })).toBe( true, ); }); test("matches sub-paths when not strict", () => { expect( twuiLinkMatchesPath({ href: "/blog", pathname: "/blog/post-1" }), ).toBe(true); }); test("does not match sub-paths when strict", () => { expect( twuiLinkMatchesPath({ href: "/blog", pathname: "/blog/post-1", strict: true, }), ).toBe(false); }); test("does not match a path that only shares a prefix", () => { expect( twuiLinkMatchesPath({ href: "/blog", pathname: "/blogging" }), ).toBe(false); }); test("root link only matches the root path", () => { expect(twuiLinkMatchesPath({ href: "/", pathname: "/" })).toBe(true); expect(twuiLinkMatchesPath({ href: "/", pathname: "/about" })).toBe( false, ); }); test("ignores trailing slashes, query strings and hashes", () => { expect( twuiLinkMatchesPath({ href: "/docs/?tab=1#top", pathname: "/docs" }), ).toBe(true); expect(twuiLinkMatchesPath({ href: "/docs", pathname: "/docs/" })).toBe( true, ); }); test("never matches links to other origins", () => { expect( twuiLinkMatchesPath({ href: "https://example.com/blog", pathname: "/blog", }), ).toBe(false); }); test("does not match hash-only links", () => { expect( twuiLinkMatchesPath({ href: "#section", pathname: "/blog" }), ).toBe(false); }); });