File size: 2,984 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
/* eslint-env jest */
import { waitFor } from 'next-test-utils'
import path from 'path'
import { nextTestSetup } from 'e2e-utils'
describe('Client Navigation', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixture'),
env: {
TEST_STRICT_NEXT_HEAD: String(true),
},
})
describe('with <a/> tag inside the <Link />', () => {
it('should navigate the page', async () => {
const browser = await next.browser('/nav/about')
const text = await browser
.elementByCss('#home-link')
.click()
.waitForElementByCss('.nav-home')
.elementByCss('p')
.text()
expect(text).toBe('This is the home.')
await browser.close()
})
it('should not navigate if the <a/> tag has a target', async () => {
const browser = await next.browser('/nav')
await browser
.elementByCss('#increase')
.click()
.elementByCss('#target-link')
.click()
await waitFor(1000)
const counterText = await browser.elementByCss('#counter').text()
expect(counterText).toBe('Counter: 1')
await browser.close()
})
it('should not navigate if the click-event is modified', async () => {
const browser = await next.browser('/nav')
await browser.elementByCss('#increase').click()
const key = process.platform === 'darwin' ? 'Meta' : 'Control'
await browser.keydown(key)
await browser.elementByCss('#in-svg-link').click()
await browser.keyup(key)
await waitFor(1000)
const counterText = await browser.elementByCss('#counter').text()
expect(counterText).toBe('Counter: 1')
await browser.close()
})
it('should not reload when link in svg is clicked', async () => {
const browser = await next.browser('/nav')
await browser.eval('window.hello = true')
await browser
.elementByCss('#in-svg-link')
.click()
.waitForElementByCss('.nav-about')
expect(await browser.eval('window.hello')).toBe(true)
await browser.close()
})
})
describe('with unexpected <a/> nested tag', () => {
it('should not redirect if passHref prop is not defined in Link', async () => {
const browser = await next.browser('/nav/pass-href-prop')
const text = await browser
.elementByCss('#without-href')
.click()
.waitForElementByCss('.nav-pass-href-prop')
.elementByCss('p')
.text()
expect(text).toBe('This is the passHref prop page.')
await browser.close()
})
it('should redirect if passHref prop is defined in Link', async () => {
const browser = await next.browser('/nav/pass-href-prop')
const text = await browser
.elementByCss('#with-href')
.click()
.waitForElementByCss('.nav-home')
.elementByCss('p')
.text()
expect(text).toBe('This is the home.')
await browser.close()
})
})
})
|