From 74c18d9fa0802165a06b0f32560e12012991f18c Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 19 Jan 2021 12:08:07 -0600 Subject: [PATCH] Add test for i18n + developments page --- .../pages/developments/index.js | 33 +++++++++++++++++++ .../i18n-support/pages/developments/index.js | 33 +++++++++++++++++++ test/integration/i18n-support/test/shared.js | 30 +++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 test/integration/i18n-support-base-path/pages/developments/index.js create mode 100644 test/integration/i18n-support/pages/developments/index.js diff --git a/test/integration/i18n-support-base-path/pages/developments/index.js b/test/integration/i18n-support-base-path/pages/developments/index.js new file mode 100644 index 000000000000..cbd5858aec7e --- /dev/null +++ b/test/integration/i18n-support-base-path/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 ( + <> +

developments page

+

{JSON.stringify(props)}

+

{router.locale}

+

{router.defaultLocale}

+

{JSON.stringify(router.locales)}

+

{JSON.stringify(router.query)}

+

{router.pathname}

+

{router.asPath}

+ + to / + +
+ + ) +} + +export const getServerSideProps = ({ locale, locales, defaultLocale }) => { + return { + props: { + locale, + locales, + defaultLocale, + }, + } +} diff --git a/test/integration/i18n-support/pages/developments/index.js b/test/integration/i18n-support/pages/developments/index.js new file mode 100644 index 000000000000..cbd5858aec7e --- /dev/null +++ b/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 ( + <> +

developments page

+

{JSON.stringify(props)}

+

{router.locale}

+

{router.defaultLocale}

+

{JSON.stringify(router.locales)}

+

{JSON.stringify(router.query)}

+

{router.pathname}

+

{router.asPath}

+ + to / + +
+ + ) +} + +export const getServerSideProps = ({ locale, locales, defaultLocale }) => { + return { + props: { + locale, + locales, + defaultLocale, + }, + } +} diff --git a/test/integration/i18n-support/test/shared.js b/test/integration/i18n-support/test/shared.js index fcb6dba01873..47ff03d86776 100644 --- a/test/integration/i18n-support/test/shared.js +++ b/test/integration/i18n-support/test/shared.js @@ -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 || '/'}`)