Skip to content

Commit

Permalink
test: merge issue 1889 test
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Mar 21, 2024
1 parent 21ddfb2 commit d2354d5
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 124 deletions.
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()
})
})

0 comments on commit d2354d5

Please sign in to comment.