From eadfef9e34183c7d3832bb6b00199555eb0910d5 Mon Sep 17 00:00:00 2001 From: Bobbie Goede Date: Thu, 21 Mar 2024 12:31:59 +0100 Subject: [PATCH] test: merge issue #1889 test (#2867) --- specs/fixtures/basic/nuxt.config.ts | 2 + .../pages/define-i18n-route-false.vue} | 0 specs/fixtures/basic/pages/index.vue | 3 ++ specs/fixtures/issues/1889/app.vue | 25 ---------- specs/fixtures/issues/1889/locales/en.json | 3 -- specs/fixtures/issues/1889/locales/fr.json | 3 -- specs/fixtures/issues/1889/locales/pl.json | 3 -- specs/fixtures/issues/1889/nuxt.config.ts | 33 ------------- specs/fixtures/issues/1889/package.json | 14 ------ specs/fixtures/issues/1889/pages/about.vue | 5 -- specs/fixtures/issues/1889/pages/example.vue | 5 -- specs/fixtures/issues/1889/pages/index.vue | 3 -- specs/issues/1889.spec.ts | 28 ----------- specs/routing_strategies/prefix.spec.ts | 49 ++++++++++++++++++- 14 files changed, 52 insertions(+), 124 deletions(-) rename specs/fixtures/{issues/1889/pages/disabled-localized-route.vue => basic/pages/define-i18n-route-false.vue} (100%) delete mode 100644 specs/fixtures/issues/1889/app.vue delete mode 100644 specs/fixtures/issues/1889/locales/en.json delete mode 100644 specs/fixtures/issues/1889/locales/fr.json delete mode 100644 specs/fixtures/issues/1889/locales/pl.json delete mode 100644 specs/fixtures/issues/1889/nuxt.config.ts delete mode 100644 specs/fixtures/issues/1889/package.json delete mode 100644 specs/fixtures/issues/1889/pages/about.vue delete mode 100644 specs/fixtures/issues/1889/pages/example.vue delete mode 100644 specs/fixtures/issues/1889/pages/index.vue delete mode 100644 specs/issues/1889.spec.ts diff --git a/specs/fixtures/basic/nuxt.config.ts b/specs/fixtures/basic/nuxt.config.ts index 64f17d97a..81043ad25 100644 --- a/specs/fixtures/basic/nuxt.config.ts +++ b/specs/fixtures/basic/nuxt.config.ts @@ -20,6 +20,8 @@ export default defineNuxtConfig({ } ], defaultLocale: 'en', + // TODO: remove this later, apply in test `setup` + // `false` will not be overwritten by `runtimeConfig` making this fixture less reusable detectBrowserLanguage: false, vueI18n: './config/i18n.config.ts' } diff --git a/specs/fixtures/issues/1889/pages/disabled-localized-route.vue b/specs/fixtures/basic/pages/define-i18n-route-false.vue similarity index 100% rename from specs/fixtures/issues/1889/pages/disabled-localized-route.vue rename to specs/fixtures/basic/pages/define-i18n-route-false.vue diff --git a/specs/fixtures/basic/pages/index.vue b/specs/fixtures/basic/pages/index.vue index b27171103..c6f6613ea 100644 --- a/specs/fixtures/basic/pages/index.vue +++ b/specs/fixtures/basic/pages/index.vue @@ -66,5 +66,8 @@ useHead(() => ({ go to product foo go to history + + go to defineI18nRoute(false) + diff --git a/specs/fixtures/issues/1889/app.vue b/specs/fixtures/issues/1889/app.vue deleted file mode 100644 index b275800d6..000000000 --- a/specs/fixtures/issues/1889/app.vue +++ /dev/null @@ -1,25 +0,0 @@ - - - - diff --git a/specs/fixtures/issues/1889/locales/en.json b/specs/fixtures/issues/1889/locales/en.json deleted file mode 100644 index f19b50ba9..000000000 --- a/specs/fixtures/issues/1889/locales/en.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "hello": "Hello!" -} diff --git a/specs/fixtures/issues/1889/locales/fr.json b/specs/fixtures/issues/1889/locales/fr.json deleted file mode 100644 index 8bfd8b428..000000000 --- a/specs/fixtures/issues/1889/locales/fr.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "hello": "Bonjour!" -} diff --git a/specs/fixtures/issues/1889/locales/pl.json b/specs/fixtures/issues/1889/locales/pl.json deleted file mode 100644 index 7f4d2dafe..000000000 --- a/specs/fixtures/issues/1889/locales/pl.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "hello": "Witaj!" -} diff --git a/specs/fixtures/issues/1889/nuxt.config.ts b/specs/fixtures/issues/1889/nuxt.config.ts deleted file mode 100644 index f41caaad4..000000000 --- a/specs/fixtures/issues/1889/nuxt.config.ts +++ /dev/null @@ -1,33 +0,0 @@ -// https://v3.nuxtjs.org/api/configuration/nuxt.config -export default defineNuxtConfig({ - modules: ['@nuxtjs/i18n'], - i18n: { - locales: [ - { - code: 'en', - flag: 'us', - iso: 'en-US', - file: 'en.json', - name: 'English' - }, - { code: 'pl', flag: 'pl', iso: 'pl-PL', file: 'pl.json', name: 'Polski' }, - { - code: 'fr', - flag: 'fr', - iso: 'fr-FR', - file: 'fr.json', - name: 'Français' - } - ], - defaultLocale: 'en', - strategy: 'prefix', - langDir: 'locales', - detectBrowserLanguage: { - useCookie: true, - // cookieKey: 'locale', - // fallbackLocale: 'en', - alwaysRedirect: false, - redirectOn: 'root' - } - } -}) diff --git a/specs/fixtures/issues/1889/package.json b/specs/fixtures/issues/1889/package.json deleted file mode 100644 index 9b50b539f..000000000 --- a/specs/fixtures/issues/1889/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "nuxt3-test-issues-1889", - "private": true, - "scripts": { - "build": "nuxt build", - "dev": "nuxt dev", - "generate": "nuxt generate", - "preview": "nuxt preview" - }, - "devDependencies": { - "@nuxtjs/i18n": "latest", - "nuxt": "latest" - } -} diff --git a/specs/fixtures/issues/1889/pages/about.vue b/specs/fixtures/issues/1889/pages/about.vue deleted file mode 100644 index cce183b9c..000000000 --- a/specs/fixtures/issues/1889/pages/about.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/specs/fixtures/issues/1889/pages/example.vue b/specs/fixtures/issues/1889/pages/example.vue deleted file mode 100644 index cce183b9c..000000000 --- a/specs/fixtures/issues/1889/pages/example.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/specs/fixtures/issues/1889/pages/index.vue b/specs/fixtures/issues/1889/pages/index.vue deleted file mode 100644 index 7b6d0a085..000000000 --- a/specs/fixtures/issues/1889/pages/index.vue +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/specs/issues/1889.spec.ts b/specs/issues/1889.spec.ts deleted file mode 100644 index b6b7d24b8..000000000 --- a/specs/issues/1889.spec.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { test, expect, describe } from 'vitest' -import { fileURLToPath } from 'node:url' -import { setup, createPage, url } from '../utils' -import { getText } from '../helper' - -describe('#1889', async () => { - await setup({ - rootDir: fileURLToPath(new URL(`../fixtures/issues/1889`, import.meta.url)) - }) - - test('navigate work on `defineI18nRoute(false)`', async () => { - const home = url('/') - const page = await createPage() - await page.goto(home) - - // switch 'pl' locale - await page.locator('#pl').click() - expect(await getText(page, '#hello-text')).toEqual('Witaj!') - - // navigate to disabled route - await page.locator('#disabled-route').click() - expect(await getText(page, '#disable-route-text')).toEqual('Page with disabled localized route') - - // back to home - await page.locator('#goto-home').click() - expect(await getText(page, '#hello-text')).toEqual('Witaj!') - }) -}) diff --git a/specs/routing_strategies/prefix.spec.ts b/specs/routing_strategies/prefix.spec.ts index 948b0ac36..712116c1c 100644 --- a/specs/routing_strategies/prefix.spec.ts +++ b/specs/routing_strategies/prefix.spec.ts @@ -1,7 +1,7 @@ import { describe, test, expect } from 'vitest' import { fileURLToPath } from 'node:url' import { setup, url, fetch } from '../utils' -import { getText, getData, renderPage, waitForURL } from '../helper' +import { getText, getData, renderPage, waitForURL, startServerWithRuntimeConfig } from '../helper' import type { Response } from 'playwright' @@ -12,12 +12,23 @@ await setup({ nuxtConfig: { i18n: { strategy: 'prefix', - defaultLocale: 'en' + defaultLocale: 'en', + // fixture uses `false` which cannot be overwritten using runtimeConfig + detectBrowserLanguage: {} } } }) describe('strategy: prefix', async () => { + beforeEach(async () => { + // use original fixture `detectBrowserLanguage` value as default for tests, overwrite here needed + await startServerWithRuntimeConfig({ + public: { + i18n: { detectBrowserLanguage: false } + } + }) + }) + test.each([ ['/', '/en'], ['/about', '/en/about'], @@ -107,4 +118,38 @@ describe('strategy: prefix', async () => { // current locale expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('fr') }) + + test('(#1889) navigation to page with `defineI18nRoute(false)`', async () => { + const restore = await startServerWithRuntimeConfig({ + public: { + i18n: { + detectBrowserLanguage: { + useCookie: true, + alwaysRedirect: false, + redirectOn: 'root' + } + } + } + }) + + const { page } = await renderPage('/', { locale: 'en' }) + await waitForURL(page, '/en') + + // switch 'fr' locale + await page.locator('#lang-switcher-with-set-locale a').click() + await waitForURL(page, '/fr') + expect(await getText(page, '#home-header')).toEqual('Accueil') + + // navigate to disabled route + await page.locator('#link-define-i18n-route-false').click() + await waitForURL(page, '/define-i18n-route-false') + + expect(await getText(page, '#disable-route-text')).toEqual('Page with disabled localized route') + + // back to home + await page.locator('#goto-home').click() + expect(await getText(page, '#home-header')).toEqual('Accueil') + + await restore() + }) })