forked from nuxt-modules/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
different_domains.spec.ts
75 lines (69 loc) · 2 KB
/
different_domains.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { test, expect } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, $fetch } from './utils'
import { getDom } from './helper'
await setup({
rootDir: fileURLToPath(new URL(`./fixtures/domain`, import.meta.url)),
// overrides
nuxtConfig: {
i18n: {
locales: [
{
code: 'en',
iso: 'en',
name: 'English',
domain: 'en.nuxt-app.localhost'
},
{
code: 'fr',
iso: 'fr-FR',
name: 'Français',
domain: 'fr.nuxt-app.localhost'
}
],
differentDomains: true,
detectBrowserLanguage: {
useCookie: true
}
}
}
})
describe('detection locale with host on server', () => {
test.each([
['en', 'en.nuxt-app.localhost', 'Homepage'],
['fr', 'fr.nuxt-app.localhost', 'Accueil']
])('%s host', async (locale, host, header) => {
const html = await $fetch('/', {
headers: {
Host: host
}
})
const dom = getDom(html)
expect(dom.querySelector('#lang-switcher-current-locale code').textContent).toEqual(locale)
expect(dom.querySelector('#home-header').textContent).toEqual(header)
})
})
test('detection locale with x-forwarded-host on server', async () => {
const html = await $fetch('/', {
headers: {
'X-Forwarded-Host': 'fr.nuxt-app.localhost'
}
})
const dom = getDom(html)
expect(dom.querySelector('#lang-switcher-current-locale code').textContent).toEqual('fr')
expect(dom.querySelector('#home-header').textContent).toEqual('Accueil')
})
test('pass `<NuxtLink> to props', async () => {
const html = await $fetch('/', {
headers: {
Host: 'fr.nuxt-app.localhost'
}
})
const dom = getDom(html)
expect(dom.querySelector('#switch-locale-path-usages .switch-to-en a').getAttribute('href')).toEqual(
`http://en.nuxt-app.localhost`
)
expect(dom.querySelector('#switch-locale-path-usages .switch-to-fr a').getAttribute('href')).toEqual(
`http://fr.nuxt-app.localhost`
)
})