-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: alwaysRedirect does not work with redirectOn 'all' and 'no prefi…
…x' (#1884) * fix always redirect * fix --------- Co-authored-by: khaled.borghol <khaled.borghol@abyatonline.com>
- Loading branch information
Showing
3 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
specs/browser_language_detection/always_redirect/prefix_and_default_all.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { test, expect } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, url, createPage } from '@nuxt/test-utils' | ||
import { getText } from '../../helper' | ||
|
||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../../fixtures/basic`, import.meta.url)), | ||
browser: true, | ||
// overrides | ||
nuxtConfig: { | ||
i18n: { | ||
strategy: 'prefix_and_default', | ||
detectBrowserLanguage: { | ||
alwaysRedirect: true, | ||
redirectOn: 'all' | ||
} | ||
} | ||
} | ||
}) | ||
|
||
test('alwaysRedirect: all', async () => { | ||
const blog = url('/blog/article') | ||
const page = await createPage(undefined, { locale: 'en' }) // set browser locale | ||
await page.goto(blog) | ||
|
||
// detect locale from navigator language | ||
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('en') | ||
|
||
// click `fr` lang switch link | ||
await page.locator('#set-locale-link-fr').click() | ||
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('fr') | ||
|
||
// go to `en` home page | ||
await page.goto(blog) | ||
expect(page.url().endsWith('/fr/blog/article')) | ||
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('fr') | ||
}) |
41 changes: 41 additions & 0 deletions
41
specs/browser_language_detection/always_redirect/prefix_and_default_no_prefix.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { test, expect } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, url, createPage } from '@nuxt/test-utils' | ||
import { getText } from '../../helper' | ||
|
||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../../fixtures/fallback`, import.meta.url)), | ||
browser: true, | ||
// overrides | ||
nuxtConfig: { | ||
i18n: { | ||
strategy: 'prefix_and_default', | ||
detectBrowserLanguage: { | ||
alwaysRedirect: true, | ||
redirectOn: 'no prefix' | ||
} | ||
} | ||
} | ||
}) | ||
|
||
test('alwaysRedirect: no prefix', async () => { | ||
const blog = url('/about') | ||
const page = await createPage(undefined, { locale: 'en' }) // set browser locale | ||
await page.goto(blog) | ||
|
||
// detect locale from navigator language | ||
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('en') | ||
|
||
// click `fr` lang switch link | ||
await page.locator('#set-locale-link-fr').click() | ||
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('fr') | ||
|
||
// go to `en` home page | ||
await page.goto(url('/ja/about')) | ||
expect(page.url().endsWith('/ja/about')) | ||
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('ja') | ||
|
||
await page.goto(url('/about')) | ||
expect(page.url().endsWith('/ja/about')) | ||
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('ja') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters