Skip to content

Commit

Permalink
Failing test for client navigation to layout with React.Suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jan 7, 2025
1 parent 2285465 commit 9f40afe
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/e2e/app-dir/navigation-layout-suspense/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
27 changes: 27 additions & 0 deletions test/e2e/app-dir/navigation-layout-suspense/app/nested/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Suspense } from 'react'
import Link from 'next/link'

export const dynamic = 'force-dynamic'

async function LoadData() {
await fetch('https://next-data-api-endpoint.vercel.app/api/random?b').then(
(res) => res.text()
)
return <div>Got API Response </div>
}

export default async function Layout(props) {
return (
<>
<div>
<Link href={`/`} className="text-blue-500">
Home Page
</Link>
</div>
<Suspense fallback={<h1>Loading...</h1>}>
{props.children}
<LoadData>{props.children}</LoadData>
</Suspense>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function NestedPage() {
return (
<>
<h1 data-testid="nested-resolved">This is the nested Page</h1>
</>
)
}
14 changes: 14 additions & 0 deletions test/e2e/app-dir/navigation-layout-suspense/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Link from 'next/link'

export default function Home() {
return (
<>
<div>
<Link href={`/nested`} className="text-blue-500">
nested Page
</Link>
</div>
<h1>This is the Home Page</h1>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { nextTestSetup } from 'e2e-utils'

describe('app dir - navigation with Suspense in nested layout', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('resolves data after client navigation to a nested layout with Suspense', async () => {
const browser = await next.browser('/nested')

await browser.waitForElementByCss('[data-testid="nested-resolved"]')

await browser.waitForElementByCss('a[href="/"]').click()

await browser.waitForElementByCss('a[href="/nested"]').click()

await browser.waitForElementByCss('[data-testid="nested-resolved"]')
})
})
1 change: 1 addition & 0 deletions test/e2e/app-dir/navigation-layout-suspense/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}

0 comments on commit 9f40afe

Please sign in to comment.