Skip to content

Commit

Permalink
Add test for i18n + developments page
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jan 19, 2021
1 parent cb48d65 commit 74c18d9
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
@@ -0,0 +1,33 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function Page(props) {
const router = useRouter()

return (
<>
<p id="developments">developments page</p>
<p id="props">{JSON.stringify(props)}</p>
<p id="router-locale">{router.locale}</p>
<p id="router-default-locale">{router.defaultLocale}</p>
<p id="router-locales">{JSON.stringify(router.locales)}</p>
<p id="router-query">{JSON.stringify(router.query)}</p>
<p id="router-pathname">{router.pathname}</p>
<p id="router-as-path">{router.asPath}</p>
<Link href="/">
<a id="to-index">to /</a>
</Link>
<br />
</>
)
}

export const getServerSideProps = ({ locale, locales, defaultLocale }) => {
return {
props: {
locale,
locales,
defaultLocale,
},
}
}
33 changes: 33 additions & 0 deletions test/integration/i18n-support/pages/developments/index.js
@@ -0,0 +1,33 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function Page(props) {
const router = useRouter()

return (
<>
<p id="developments">developments page</p>
<p id="props">{JSON.stringify(props)}</p>
<p id="router-locale">{router.locale}</p>
<p id="router-default-locale">{router.defaultLocale}</p>
<p id="router-locales">{JSON.stringify(router.locales)}</p>
<p id="router-query">{JSON.stringify(router.query)}</p>
<p id="router-pathname">{router.pathname}</p>
<p id="router-as-path">{router.asPath}</p>
<Link href="/">
<a id="to-index">to /</a>
</Link>
<br />
</>
)
}

export const getServerSideProps = ({ locale, locales, defaultLocale }) => {
return {
props: {
locale,
locales,
defaultLocale,
},
}
}
30 changes: 30 additions & 0 deletions test/integration/i18n-support/test/shared.js
Expand Up @@ -37,6 +37,36 @@ async function addDefaultLocaleCookie(browser) {
}

export function runTests(ctx) {
it('should navigate to page with same name as development buildId', async () => {
const browser = await webdriver(ctx.appPort, `${ctx.basePath || '/'}`)

await browser.eval(`(function() {
window.beforeNav = 1
window.next.router.push('/developments')
})()`)

await browser.waitForElementByCss('#developments')
expect(await browser.eval('window.beforeNav')).toBe(1)
expect(await browser.elementByCss('#router-locale').text()).toBe('en-US')
expect(await browser.elementByCss('#router-default-locale').text()).toBe(
'en-US'
)
expect(await browser.elementByCss('#router-pathname').text()).toBe(
'/developments'
)
expect(await browser.elementByCss('#router-as-path').text()).toBe(
'/developments'
)
expect(
JSON.parse(await browser.elementByCss('#router-query').text())
).toEqual({})
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
locales,
locale: 'en-US',
defaultLocale: 'en-US',
})
})

it('should redirect to locale domain correctly client-side', async () => {
const browser = await webdriver(ctx.appPort, `${ctx.basePath || '/'}`)

Expand Down

0 comments on commit 74c18d9

Please sign in to comment.