-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate app router playground, add base path test
- Loading branch information
Showing
11 changed files
with
70 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
examples/example-app-router-playground/src/components/ClientLink.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
'use client'; | ||
|
||
import {ComponentProps} from 'react'; | ||
import {Link, Pathnames} from '@/i18n/routing'; | ||
import {Link} from '@/i18n/routing'; | ||
|
||
export default function NavigationLink<Pathname extends Pathnames>( | ||
props: ComponentProps<typeof Link<Pathname>> | ||
) { | ||
export default function NavigationLink(props: ComponentProps<typeof Link>) { | ||
return <Link {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
examples/example-app-router-playground/tests/base-path.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {test as it, expect} from '@playwright/test'; | ||
import {assertLocaleCookieValue} from './utils'; | ||
|
||
it('can use the router', async ({page}) => { | ||
await page.goto('/base/path'); | ||
await assertLocaleCookieValue(page, 'en', {path: '/base/path'}); | ||
|
||
await page.getByRole('button', {name: 'Go to nested page'}).click(); | ||
await expect(page).toHaveURL('/base/path/nested'); | ||
await page.getByRole('link', {name: 'Home'}).click(); | ||
await page.getByRole('link', {name: 'Switch to German'}).click(); | ||
|
||
await expect(page).toHaveURL('/base/path/de'); | ||
assertLocaleCookieValue(page, 'de', {path: '/base/path'}); | ||
await page.getByRole('button', {name: 'Go to nested page'}).click(); | ||
await expect(page).toHaveURL('/base/path/de/verschachtelt'); | ||
await page.getByRole('link', {name: 'Start'}).click(); | ||
await page.getByRole('link', {name: 'Zu Englisch wechseln'}).click(); | ||
|
||
await expect(page).toHaveURL('/base/path'); | ||
assertLocaleCookieValue(page, 'en', {path: '/base/path'}); | ||
}); |
13 changes: 0 additions & 13 deletions
13
examples/example-app-router-playground/tests/getAlternateLinks.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/example-app-router-playground/tests/trailing-slash.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {APIResponse, expect, Page} from '@playwright/test'; | ||
|
||
export async function getAlternateLinks(response: APIResponse) { | ||
return ( | ||
response | ||
.headers() | ||
.link.split(', ') | ||
// On CI, Playwright uses a different host somehow | ||
.map((cur) => cur.replace(/0\.0\.0\.0/g, 'localhost')) | ||
// Normalize ports | ||
.map((cur) => cur.replace(/localhost:\d{4}/g, 'localhost:3000')) | ||
); | ||
} | ||
|
||
export async function assertLocaleCookieValue( | ||
page: Page, | ||
value: string, | ||
otherProps?: Record<string, unknown> | ||
) { | ||
const cookie = (await page.context().cookies()).find( | ||
(cur) => cur.name === 'NEXT_LOCALE' | ||
); | ||
expect(cookie).toMatchObject({ | ||
name: 'NEXT_LOCALE', | ||
value, | ||
...otherProps | ||
}); | ||
} |