diff --git a/test/e2e/app-dir/app/app/link-hard-push/page.server.js b/test/e2e/app-dir/app/app/link-hard-push/page.server.js new file mode 100644 index 000000000000..f692aaeb9e89 --- /dev/null +++ b/test/e2e/app-dir/app/app/link-hard-push/page.server.js @@ -0,0 +1,9 @@ +import Link from 'next/link' + +export default function Page() { + return ( + + With Date + + ) +} diff --git a/test/e2e/app-dir/app/app/link-hard-replace/page.server.js b/test/e2e/app-dir/app/app/link-hard-replace/page.server.js new file mode 100644 index 000000000000..4fbb8eecc548 --- /dev/null +++ b/test/e2e/app-dir/app/app/link-hard-replace/page.server.js @@ -0,0 +1,9 @@ +import Link from 'next/link' + +export default function Page() { + return ( + + With Date + + ) +} diff --git a/test/e2e/app-dir/app/app/link-soft-push/page.server.js b/test/e2e/app-dir/app/app/link-soft-push/page.server.js new file mode 100644 index 000000000000..166a862d98df --- /dev/null +++ b/test/e2e/app-dir/app/app/link-soft-push/page.server.js @@ -0,0 +1,9 @@ +import Link from 'next/link' + +export default function Page() { + return ( + + With Date + + ) +} diff --git a/test/e2e/app-dir/app/app/link-soft-replace/page.server.js b/test/e2e/app-dir/app/app/link-soft-replace/page.server.js new file mode 100644 index 000000000000..e20dbe188527 --- /dev/null +++ b/test/e2e/app-dir/app/app/link-soft-replace/page.server.js @@ -0,0 +1,9 @@ +import Link from 'next/link' + +export default function Page() { + return ( + + With Date + + ) +} diff --git a/test/e2e/app-dir/app/app/navigation/page.server.js b/test/e2e/app-dir/app/app/navigation/page.server.js new file mode 100644 index 000000000000..72cac83794ae --- /dev/null +++ b/test/e2e/app-dir/app/app/navigation/page.server.js @@ -0,0 +1,3 @@ +export default function Page() { + return

{new Date().toString()}

+} diff --git a/test/e2e/app-dir/app/app/with-date/page.server.js b/test/e2e/app-dir/app/app/with-date/page.server.js new file mode 100644 index 000000000000..bdc5ef140dd6 --- /dev/null +++ b/test/e2e/app-dir/app/app/with-date/page.server.js @@ -0,0 +1,12 @@ +import Link from 'next/link' + +export default function Page() { + return ( + <> +

{new Date().toString()}

+ + To Navigation + + + ) +} diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index 98caaf0045c1..2ab8e8617659 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -193,6 +193,175 @@ describe('app dir', () => { expect(html).toContain('hello from app/partial-match-[id]. ID is: 123') }) + describe('', () => { + it('should hard push', async () => { + const browser = await webdriver(next.url, '/link-hard-push') + + try { + // Click the link on the page, and verify that the history entry was + // added. + await browser.elementById('link').click() + // TODO: verify that a history entry was added + + // Get the date on the rendered page. + let element = await browser.elementById('date') + const firstDate = await element.text() + + // Wait one second, + await new Promise((resolve) => setTimeout(resolve, 1000)) + + // Go back, and redo the navigation by clicking the link. + await browser.back() + await browser.elementById('link').click() + + // Get the date again, and compare, they should not be the same. + element = await browser.elementById('date') + const secondDate = await element.text() + expect(firstDate).not.toBe(secondDate) + } finally { + await browser.close() + } + }) + + it('should hard replace', async () => { + const browser = await webdriver(next.url, '/link-hard-replace') + + try { + // Click the link on the page, and verify that the history entry was NOT + // added. + await browser.elementById('link').click() + // TODO: verify that a history entry was NOT added + + // Get the date on the rendered page. + let element = await browser.elementById('date') + const firstDate = await element.text() + + // Wait one second, + await new Promise((resolve) => setTimeout(resolve, 1000)) + + // Go back, and redo the navigation by clicking the link. + await browser.back() + await browser.elementById('link').click() + + // Get the date again, and compare, they should not be the same. + element = await browser.elementById('date') + const secondDate = await element.text() + expect(firstDate).not.toBe(secondDate) + } finally { + await browser.close() + } + }) + + it('should soft push', async () => { + const browser = await webdriver(next.url, '/link-soft-push') + + try { + // Click the link on the page, and verify that the history entry was + // added. + await browser.elementById('link').click() + // TODO: verify that a history entry was added + + // Get the date on the rendered page. + let element = await browser.elementById('date') + const firstDate = await element.text() + + // Wait one second, + await new Promise((resolve) => setTimeout(resolve, 1000)) + + // Go back, and redo the navigation by clicking the link. + await browser.back() + await browser.elementById('link').click() + + // Get the date again, and compare, they should be the same. + element = await browser.elementById('date') + const secondDate = await element.text() + expect(firstDate).toBe(secondDate) + } finally { + await browser.close() + } + }) + + it('should soft replace', async () => { + const browser = await webdriver(next.url, '/link-soft-replace') + + try { + // Click the link on the page, and verify that the history entry was NOT + // added. + await browser.elementById('link').click() + // TODO: verify that a history entry was NOT added + + // Get the date on the rendered page. + let element = await browser.elementById('date') + const firstDate = await element.text() + + // Wait one second, + await new Promise((resolve) => setTimeout(resolve, 1000)) + + // Go back, and redo the navigation by clicking the link. + await browser.back() + await browser.elementById('link').click() + + // Get the date again, and compare, they should be the same. + element = await browser.elementById('date') + const secondDate = await element.text() + expect(firstDate).toBe(secondDate) + } finally { + await browser.close() + } + }) + + it('should be soft for back navigation', async () => { + const browser = await webdriver(next.url, '/with-date') + + try { + // Get the date on the rendered page. + let element = await browser.elementById('date') + const firstDate = await element.text() + + // Wait one second, + await new Promise((resolve) => setTimeout(resolve, 1000)) + + // Click the link, and go back. + await browser.elementById('link').click() + await browser.back() + + // Get the date again, and compare, they should be the same. + element = await browser.elementById('date') + const secondDate = await element.text() + expect(firstDate).toBe(secondDate) + } finally { + await browser.close() + } + }) + + it('should be soft for forward navigation', async () => { + const browser = await webdriver(next.url, '/with-date') + + try { + // Click the link. + await browser.elementById('link').click() + + // Get the date on the rendered page. + let element = await browser.elementById('date') + const firstDate = await element.text() + + // Wait one second, + await new Promise((resolve) => setTimeout(resolve, 1000)) + + // Go back, then forward. + await browser.back() + await browser.forward() + + // Get the date again, and compare, they should be the same. + element = await browser.elementById('date') + const secondDate = await element.text() + expect(firstDate).toBe(secondDate) + } finally { + await browser.close() + } + }) + }) + describe('server components', () => { // TODO: why is this not servable but /dashboard+rootonly/hello.server.js // should be? Seems like they both either should be servable or not