Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: merge issue #1889 test #2867

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions specs/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
3 changes: 3 additions & 0 deletions specs/fixtures/basic/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ useHead(() => ({
go to product foo
</NuxtLink>
<NuxtLink id="link-history" :to="localePath({ name: 'history' })">go to history</NuxtLink>
<NuxtLink id="link-define-i18n-route-false" exact :to="localePath('/define-i18n-route-false')">
go to defineI18nRoute(false)
</NuxtLink>
</div>
</template>
25 changes: 0 additions & 25 deletions specs/fixtures/issues/1889/app.vue

This file was deleted.

3 changes: 0 additions & 3 deletions specs/fixtures/issues/1889/locales/en.json

This file was deleted.

3 changes: 0 additions & 3 deletions specs/fixtures/issues/1889/locales/fr.json

This file was deleted.

3 changes: 0 additions & 3 deletions specs/fixtures/issues/1889/locales/pl.json

This file was deleted.

33 changes: 0 additions & 33 deletions specs/fixtures/issues/1889/nuxt.config.ts

This file was deleted.

14 changes: 0 additions & 14 deletions specs/fixtures/issues/1889/package.json

This file was deleted.

5 changes: 0 additions & 5 deletions specs/fixtures/issues/1889/pages/about.vue

This file was deleted.

5 changes: 0 additions & 5 deletions specs/fixtures/issues/1889/pages/example.vue

This file was deleted.

3 changes: 0 additions & 3 deletions specs/fixtures/issues/1889/pages/index.vue

This file was deleted.

28 changes: 0 additions & 28 deletions specs/issues/1889.spec.ts

This file was deleted.

49 changes: 47 additions & 2 deletions specs/routing_strategies/prefix.spec.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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'],
Expand Down Expand Up @@ -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()
})
})