/* 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 tag inside the ', () => { 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 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 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() }) }) })