Skip to content

Commit

Permalink
tests: added test case
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed May 27, 2024
1 parent f2358b2 commit 6b456d7
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ module.exports = {

return [
`prettier --with-node-modules --ignore-path .prettierignore --write ${escapedFileNames}`,
`eslint --no-ignore --max-warnings=0 --fix ${escape(eslintFileNames.filter((filename) => filename !== null)).join(' ')}`,
`eslint --no-ignore --max-warnings=0 --fix ${eslintFileNames
.filter((filename) => filename !== null)
.map((filename) => {
return `"${filename}"`
})
.join(' ')}`,
`git add ${escapedFileNames}`,
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TestPage } from '../../../components/page'

export default function Page({ params: { locale } }) {
return <TestPage pathname={`/${locale}/about`} />
}
13 changes: 13 additions & 0 deletions test/e2e/app-dir/ppr-navigations/simple/app/[locale]/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { locales } from '../../components/page'

export async function generateStaticParams() {
return locales.map((locale) => ({ locale }))
}

export default function Layout({ children, params: { locale } }) {
return (
<html lang={locale}>
<body>{children}</body>
</html>
)
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/ppr-navigations/simple/app/[locale]/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TestPage } from '../../components/page'

export default function Page({ params: { locale } }) {
return <TestPage pathname={`/${locale}`} />
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/ppr-navigations/simple/app/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default ({ children }) => {
return children
}
7 changes: 7 additions & 0 deletions test/e2e/app-dir/ppr-navigations/simple/app/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { redirect } from 'next/navigation'
import { locales } from '../components/page'

export default () => {
// Redirect to the default locale
return redirect(`/${locales[0]}`)
}
40 changes: 40 additions & 0 deletions test/e2e/app-dir/ppr-navigations/simple/components/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { unstable_noStore } from 'next/cache'
import Link from 'next/link'
import { Suspense } from 'react'

export const locales = ['en', 'fr']

export const links = [
{ href: '/', text: 'Home' },
...locales
.map((locale) => {
return [
{ href: `/${locale}`, text: locale },
{ href: `/${locale}/about`, text: `${locale} - About` },
]
})
.flat(),
]

function Dynamic() {
unstable_noStore()
return <div id="dynamic">Dynamic</div>
}

export function TestPage({ pathname }) {
return (
<div>
<ul>
{links.map(({ href, text }) => (
<li key={href}>
<Link href={href}>{text}</Link>
</li>
))}
</ul>
<code data-value={pathname}>{pathname}</code>
<Suspense fallback={<div>Loading...</div>}>
<Dynamic />
</Suspense>
</div>
)
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/ppr-navigations/simple/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
ppr: true,
},
}
31 changes: 31 additions & 0 deletions test/e2e/app-dir/ppr-navigations/simple/simple.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { nextTestSetup } from 'e2e-utils'
import { links, locales } from './components/page'

describe('ppr-navigations simple', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('can navigate between all the links and back', async () => {
const browser = await next.browser('/')

try {
for (const { href } of links) {
// Find the link element for the href and click it.
await browser.elementByCss(`a[href="${href}"]`).click()

// Wait for that page to load.
if (href === '/') {
// The root page redirects to the first locale.
await browser.waitForElementByCss(`[data-value="/${locales[0]}"]`)
} else {
await browser.waitForElementByCss(`[data-value="${href}"]`)
}

await browser.elementByCss('#dynamic')
}
} finally {
await browser.close()
}
})
})

0 comments on commit 6b456d7

Please sign in to comment.