diff --git a/package-lock.json b/package-lock.json index 232a843..edbe659 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "granda-front", - "version": "0.3.17", + "version": "0.3.18", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "granda-front", - "version": "0.3.17", + "version": "0.3.18", "dependencies": { "@radix-ui/react-dropdown-menu": "^2.1.6", "@radix-ui/react-select": "^2.2.6", diff --git a/package.json b/package.json index c767d80..1d49dc1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "granda-front", - "version": "0.3.17", + "version": "0.3.18", "private": true, "scripts": { "dev": "next dev --turbopack", diff --git a/src/components/tournament/dashboard/DashSide.tsx b/src/components/tournament/dashboard/DashSide.tsx index c20dd65..6538539 100644 --- a/src/components/tournament/dashboard/DashSide.tsx +++ b/src/components/tournament/dashboard/DashSide.tsx @@ -1,3 +1,5 @@ +"use client"; + import { LucideBetweenHorizontalStart, LucideCastle, @@ -16,6 +18,7 @@ import { import { ComponentType } from "react"; import { Link } from "@/i18n/navigation"; import "@/i18n/language-utils"; +import { usePathname } from "next/navigation"; import { useTranslations } from "next-intl"; import { DebatecoreLogo } from "@/components/debatecore/DebatecoreLogo"; import { GrandaLogo } from "@/components/debatecore/GrandaLogo"; @@ -41,14 +44,22 @@ type DashSidebarLinks = { links: DashSideLink[]; }[]; -const DashSide = ({ - tournament_path, - path_highlight, -}: { - tournament_path: string; - path_highlight?: string; -}) => { +const DashSide = ({ tournament_path }: { tournament_path: string }) => { const t = useTranslations("dash"); + const currentPathname = usePathname() ?? ""; + + const matchPaths = (str: string, target: string) => { + const getParam = (p: string) => { + const parts = p.split( + /\/t\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/, + ); + if (parts.length < 2) return undefined; + return parts[1].replace(/^\/|\/$/g, "").split("/")[0]; + }; + + const s = getParam(str); + return s !== undefined && s === getParam(target); + }; const links: DashSidebarLinks = [ { @@ -175,13 +186,15 @@ const DashSide = ({ {category.links.map((link) => { const Icon = link.icon; - const isHighlighted = link.name === path_highlight; + const isHighlighted = matchPaths(currentPathname, link.href); return ( { + // GIVEN + const overviewSidebarItem = page.getByRole("link", { name: "Overview" }); + const tournamentSidebarItem = page.getByRole("link", { + name: "Tournament Ladder", + }); + const debatesSidebarItem = page.getByRole("link", { name: "Debates" }); + + await expect(overviewSidebarItem).toHaveClass(/border-stone-600/); + await expect(tournamentSidebarItem).not.toHaveClass(/border-stone-600/); + await expect(debatesSidebarItem).not.toHaveClass(/border-stone-600/); + + // WHEN + await tournamentSidebarItem.click(); + + // THEN + await page.waitForURL(/\/en\/t\/[^/]+\/ladder$/); + await expect(overviewSidebarItem).not.toHaveClass(/border-stone-600/); + await expect(tournamentSidebarItem).toHaveClass(/border-stone-600/); + await expect(debatesSidebarItem).not.toHaveClass(/border-stone-600/); + }, +);