Skip to content

Commit

Permalink
tests: added some more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Jul 13, 2022
1 parent 9cc09f2 commit 1c6107c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app/app/hooks/use-headers/page.server.js
Expand Up @@ -14,6 +14,9 @@ export default function Page() {
) : (
<h2 id="does-not-have-header">Does not have x-use-headers header</h2>
)}
{'referer' in headers && headers['referer'] && (
<h3 id="has-referer">Has referer header</h3>
)}
</>
)
}
7 changes: 7 additions & 0 deletions test/e2e/app-dir/app/app/navigation/page.server.js
@@ -1,10 +1,17 @@
import { nanoid } from 'nanoid'
import Link from 'next/link'

export default function Page() {
return (
<>
<h1 id="render-id">{nanoid()}</h1>
<h2 id="from-navigation">hello from /navigation</h2>
<Link href="/hooks/use-cookies">
<a id="use-cookies">useCookies</a>
</Link>
<Link href="/hooks/use-headers">
<a id="use-headers">useHeaders</a>
</Link>
</>
)
}
44 changes: 44 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -694,6 +694,39 @@ describe('app dir', () => {
await browser.close()
}
})

it('should access cookies on <Link /> navigation', async () => {
const browser = await webdriver(next.url, '/navigation')

try {
// Click the cookies link to verify it can't see the cookie that's
// not there.
await browser.elementById('use-cookies').click()
await browser.waitForElementByCss('#does-not-have-cookie')

// Go back and add the cookies.
await browser.back()
await browser.waitForElementByCss('#from-navigation')
browser.addCookie({ name: 'use-cookies', value: 'value' })

// Click the cookies link again to see that the cookie can be picked
// up again.
await browser.elementById('use-cookies').click()
await browser.waitForElementByCss('#has-cookie')

// Go back and remove the cookies.
await browser.back()
await browser.waitForElementByCss('#from-navigation')
browser.deleteCookies()

// Verify for the last time that after clicking the cookie link
// again, there are no cookies.
await browser.elementById('use-cookies').click()
await browser.waitForElementByCss('#does-not-have-cookie')
} finally {
await browser.close()
}
})
})

describe('useHeaders', () => {
Expand All @@ -720,6 +753,17 @@ describe('app dir', () => {
expect($('#has-header').length).toBe(1)
expect($('#does-not-have-header').length).toBe(0)
})

it('should access headers on <Link /> navigation', async () => {
const browser = await webdriver(next.url, '/navigation')

try {
await browser.elementById('use-headers').click()
await browser.waitForElementByCss('#has-referer')
} finally {
await browser.close()
}
})
})

describe('usePreviewData', () => {
Expand Down

0 comments on commit 1c6107c

Please sign in to comment.