Skip to content

Commit

Permalink
test: added some test cases for new client side router
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Jul 6, 2022
1 parent f113141 commit fcf95d6
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 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 (
<Link href="/with-date">
<a id="link">With Date</a>
</Link>
)
}
9 changes: 9 additions & 0 deletions 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 (
<Link href="/with-date" replace>
<a id="link">With Date</a>
</Link>
)
}
9 changes: 9 additions & 0 deletions 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 (
<Link href="/with-date" soft>
<a id="link">With Date</a>
</Link>
)
}
9 changes: 9 additions & 0 deletions 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 (
<Link href="/with-date" replace soft>
<a id="link">With Date</a>
</Link>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app/app/navigation/page.server.js
@@ -0,0 +1,3 @@
export default function Page() {
return <h1 id="date">{new Date().toString()}</h1>
}
12 changes: 12 additions & 0 deletions 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 (
<>
<h1 id="date">{new Date().toString()}</h1>
<Link href="/navigation">
<a id="link">To Navigation</a>
</Link>
</>
)
}
169 changes: 169 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -193,6 +193,175 @@ describe('app dir', () => {
expect(html).toContain('hello from app/partial-match-[id]. ID is: 123')
})

describe('<Link />', () => {
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
Expand Down

0 comments on commit fcf95d6

Please sign in to comment.