-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
tests: e2e test for active links with special char encoding #5681
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { createFileRoute, Link } from '@tanstack/react-router' | ||
| import z from 'zod' | ||
|
|
||
| export const Route = createFileRoute('/encoding/link-active/$target')({ | ||
| validateSearch: z.object({ foo: z.string().optional() }), | ||
|
|
||
| component: RouteComponent, | ||
| }) | ||
|
|
||
| function RouteComponent() { | ||
| return ( | ||
| <Link | ||
| data-testid="self-link" | ||
| activeProps={{ className: 'font-bold' }} | ||
| activeOptions={{ includeSearch: true }} | ||
| to="/encoding/link-active/$target" | ||
| params={{ target: Route.useParams().target }} | ||
| search={Route.useSearch()} | ||
| > | ||
| link to self with $target={Route.useParams().target}, search.foo= | ||
| {Route.useSearch().foo} | ||
| </Link> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
|
|
||
| export const Route = createFileRoute('/encoding/link-active/')({ | ||
| component: RouteComponent, | ||
| }) | ||
|
|
||
| function RouteComponent() { | ||
| return ( | ||
| <div> | ||
| <Route.Link to="$target" params={{ target: 'ê' }}> | ||
| link to $target=ê | ||
| </Route.Link> | ||
| <br /> | ||
| <Route.Link to="$target" params={{ target: 'hello' }}> | ||
| link to $target=hello | ||
| </Route.Link> | ||
| </div> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||||
| import { expect } from '@playwright/test' | ||||||||
|
|
||||||||
| import { test } from '@tanstack/router-e2e-utils' | ||||||||
| import combinateImport from 'combinate' | ||||||||
|
|
||||||||
| // somehow playwright does not correctly import default exports | ||||||||
| const combinate = (combinateImport as any).default as typeof combinateImport | ||||||||
|
|
||||||||
| test.beforeEach(async ({ page }) => { | ||||||||
| await page.goto('/') | ||||||||
| }) | ||||||||
|
|
||||||||
| test.use({ | ||||||||
| whitelistErrors: [ | ||||||||
| /Failed to load resource: the server responded with a status of 404/, | ||||||||
| ], | ||||||||
| }) | ||||||||
|
|
||||||||
| combinate | ||||||||
| test.describe('link active', () => { | ||||||||
|
Comment on lines
+19
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the stray Line 19 contains a standalone Apply this diff to remove it: -combinate
test.describe('link active', () => {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| const testMatrix = combinate({ | ||||||||
| target: ['ê', 'hello'] as const, | ||||||||
| search: [undefined, { foo: 'bar' }, { foo: 'ö' }] as const, | ||||||||
| }) | ||||||||
|
|
||||||||
| testMatrix.forEach(({ target, search }) => { | ||||||||
| test(`should correctly highlight active link for $target=${target} and search=${JSON.stringify(search)}`, async ({ | ||||||||
| page, | ||||||||
| }) => { | ||||||||
| const url = new URL( | ||||||||
| `/encoding/link-active/${target}`, | ||||||||
| 'http://localhost:3000', | ||||||||
| ) | ||||||||
| if (search) { | ||||||||
| Object.entries(search).forEach(([key, value]) => { | ||||||||
| url.searchParams.set(key, value) | ||||||||
| }) | ||||||||
| } | ||||||||
| const hrefWithoutOrigin = url.href.replace(url.origin, '') | ||||||||
| await page.goto(hrefWithoutOrigin) | ||||||||
| const link = page.getByTestId('self-link') | ||||||||
| await expect(link).toBeInViewport() | ||||||||
| await expect(link).toHaveAttribute('class', 'font-bold') | ||||||||
| await expect(link).toHaveAttribute('data-status', 'active') | ||||||||
| }) | ||||||||
| }) | ||||||||
| }) | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Fix import sorting and verify zod import.
The static analysis tool flagged that
Linkshould be sorted beforecreateFileRoutealphabetically. Additionally, the zod import uses a default import pattern, but zod typically exportszas a named export.Apply this diff to fix the import sorting:
Verify the zod import pattern with a web search:
As per coding guidelines.
🌐 Web query:
💡 Result:
Zod does not use a default export. Import it as a namespace (recommended):
import * as z from "zod". [1][2]
Sources: Zod docs and repository. [1] https://zod.dev/intro (recommendation) [2] https://github.com/colinhacks/zod (README).
Fix import sorting and correct zod import pattern.
The zod import is incorrect. Zod does not use a default export and should be imported as a namespace:
import * as z from "zod". Additionally, apply the import sorting fix to align with static analysis conventions.📝 Committable suggestion
🧰 Tools
🪛 ESLint
[error] 1-1: Member 'Link' of the import declaration should be sorted alphabetically.
(sort-imports)
🤖 Prompt for AI Agents