forked from nuxt-modules/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazy_load.spec.ts
81 lines (68 loc) · 2.53 KB
/
lazy_load.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
76
77
78
79
80
81
import { test, expect } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url, createPage } from '@nuxt/test-utils'
import { getText, getData } from './helper'
await setup({
rootDir: fileURLToPath(new URL(`./fixtures/lazy`, import.meta.url)),
browser: true,
// overrides
nuxtConfig: {
i18n: {
defaultLocale: 'en',
langDir: 'lang',
lazy: true,
locales: [
{
code: 'en',
iso: 'en-US',
file: 'en.json',
name: 'English'
},
{
code: 'fr',
iso: 'fr-FR',
file: 'fr.json5',
name: 'Français'
}
]
}
}
})
test('can access to no prefix locale (en): /', async () => {
const home = url('/')
const page = await createPage()
await page.goto(home)
// `en` rendering
expect(await getText(page, '#home-header')).toEqual('Homepage')
expect(await getText(page, 'title')).toEqual('Homepage')
expect(await getText(page, '#link-about')).toEqual('About us')
// lang switcher rendering
expect(await getText(page, '#lang-switcher-with-nuxt-link a')).toEqual('Français')
expect(await getText(page, '#set-locale-link-fr')).toEqual('Français')
// page path
expect(await getData(page, '#home-use-async-data')).toMatchObject({ aboutPath: '/about' })
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a', 'href')).toEqual('/fr')
// current locale
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('en')
// html tag `lang` attriute with iso code
expect(await page.getAttribute('html', 'lang')).toEqual('en-US')
})
test('can access to prefix locale: /fr', async () => {
const home = url('/fr')
const page = await createPage()
await page.goto(home)
// `fr` rendering
expect(await getText(page, '#home-header')).toEqual('Accueil')
expect(await getText(page, 'title')).toEqual('Accueil')
expect(await getText(page, '#link-about')).toEqual('À propos')
// lang switcher rendering
expect(await getText(page, '#lang-switcher-with-nuxt-link a')).toEqual('English')
expect(await getText(page, '#set-locale-link-en')).toEqual('English')
// page path
expect(await getData(page, '#home-use-async-data')).toMatchObject({ aboutPath: '/fr/about' })
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a', 'href')).toEqual('/')
// current locale
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('fr')
// html tag `lang` attriute with iso code
expect(await page.getAttribute('html', 'lang')).toEqual('fr-FR')
})