-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
122 additions
and
1 deletion.
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
43 changes: 43 additions & 0 deletions
43
test/e2e/i18n-navigations-middleware/i18n-data-route.test.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,43 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('i18n-navigations-middleware', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should respect selected locale when navigating to a dynamic route', async () => { | ||
const browser = await next.browser('/') | ||
// change to "de" locale | ||
await browser.elementByCss("[href='/de']").click() | ||
const dynamicLink = await browser.waitForElementByCss( | ||
"[href='/de/dynamic/1']" | ||
) | ||
expect(await browser.elementById('current-locale').text()).toBe( | ||
'Current locale: de' | ||
) | ||
|
||
// navigate to dynamic route | ||
await dynamicLink.click() | ||
|
||
// the locale should still be "de" | ||
expect(await browser.elementById('dynamic-locale').text()).toBe( | ||
'Locale: de' | ||
) | ||
}) | ||
|
||
it('should respect selected locale when navigating to a static route', async () => { | ||
const browser = await next.browser('/') | ||
// change to "de" locale | ||
await browser.elementByCss("[href='/de']").click() | ||
const staticLink = await browser.waitForElementByCss("[href='/de/static']") | ||
expect(await browser.elementById('current-locale').text()).toBe( | ||
'Current locale: de' | ||
) | ||
|
||
// navigate to static route | ||
await staticLink.click() | ||
|
||
// the locale should still be "de" | ||
expect(await browser.elementById('static-locale').text()).toBe('Locale: de') | ||
}) | ||
}) |
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,6 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
export const config = { matcher: ['/foo'] } | ||
export async function middleware(req) { | ||
return NextResponse.next() | ||
} |
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,9 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
module.exports = { | ||
i18n: { | ||
defaultLocale: 'default', | ||
locales: ['default', 'en', 'de'], | ||
}, | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/i18n-navigations-middleware/pages/dynamic/[id].js
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,11 @@ | ||
export const getServerSideProps = async ({ locale }) => { | ||
return { | ||
props: { | ||
locale, | ||
}, | ||
} | ||
} | ||
|
||
export default function Dynamic({ locale }) { | ||
return <div id="dynamic-locale">Locale: {locale}</div> | ||
} |
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,37 @@ | ||
import Link from 'next/link' | ||
|
||
export const getServerSideProps = async ({ locale }) => { | ||
return { | ||
props: { | ||
locale, | ||
}, | ||
} | ||
} | ||
|
||
export default function Home({ locale }) { | ||
return ( | ||
<main | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '20px', | ||
}} | ||
> | ||
<p id="current-locale">Current locale: {locale}</p> | ||
Locale switch: | ||
<Link href="/" locale="default"> | ||
Default | ||
</Link> | ||
<Link href="/" locale="en"> | ||
English | ||
</Link> | ||
<Link href="/" locale="de"> | ||
German | ||
</Link> | ||
<br /> | ||
Test links: | ||
<Link href="/dynamic/1">Dynamic 1</Link> | ||
<Link href="/static">Static</Link> | ||
</main> | ||
) | ||
} |
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,11 @@ | ||
export const getServerSideProps = async ({ locale }) => { | ||
return { | ||
props: { | ||
locale, | ||
}, | ||
} | ||
} | ||
|
||
export default function Static({ locale }) { | ||
return <div id="static-locale">Locale: {locale}</div> | ||
} |