Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c860aa7

Browse filesBrowse files
committed
Add tests
1 parent c8b7dde commit c860aa7
Copy full SHA for c860aa7

File tree

Expand file treeCollapse file tree

1 file changed

+107
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+107
-2
lines changed

‎__tests__/changeLanguage.spec.ts

Copy file name to clipboardExpand all lines: __tests__/changeLanguage.spec.ts
+107-2Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { beforeEach, describe, expect, it } from 'vitest'
22

3-
import { nextTick } from 'vue-demi'
3+
import { isVue3, nextTick } from 'vue-demi'
44
import { FluentBundle, FluentResource } from '@fluent/bundle'
55
import ftl from '@fluent/dedent'
66

77
import type { FluentVue } from '../src'
8-
import { createFluentVue } from '../src'
8+
import { createFluentVue, useFluent } from '../src'
99
import { mountWithFluent } from './utils'
1010

1111
describe('language change', () => {
@@ -104,6 +104,111 @@ describe('language change', () => {
104104
expect(mounted.html()).toEqual('<a href="/foo">link text</a>')
105105
})
106106

107+
it('updates locale even if component is unmounted github.com/orgs/fluent-vue/discussions/834', async () => {
108+
// Arrange
109+
bundleEn = new FluentBundle('en-US')
110+
bundleUk = new FluentBundle('uk-UA')
111+
112+
const fluent = createFluentVue({
113+
bundles: [bundleUk],
114+
})
115+
116+
const child = {
117+
template: '<span>{{ $t("child") }}</span>',
118+
fluent: {
119+
'en-US': new FluentResource(ftl`
120+
child = Child message
121+
`),
122+
'uk-UA': new FluentResource(ftl`
123+
child = Повідомлення
124+
`),
125+
},
126+
}
127+
128+
const component = {
129+
components: {
130+
child,
131+
},
132+
data: () => ({
133+
show: true,
134+
}),
135+
template: '<child v-if="show" />',
136+
}
137+
138+
// Act
139+
const mounted = mountWithFluent(fluent, component)
140+
141+
expect(mounted.html()).toEqual('<span>Повідомлення</span>')
142+
143+
await mounted.setData({ show: false })
144+
145+
if (isVue3)
146+
expect(mounted.html()).toEqual('<!--v-if-->')
147+
else
148+
expect(mounted.html()).toEqual('')
149+
150+
fluent.bundles = [bundleEn]
151+
152+
await mounted.setData({ show: true })
153+
154+
// Assert
155+
expect(mounted.html()).toEqual('<span>Child message</span>')
156+
})
157+
158+
it('useFluent updates locale even if component is unmounted github.com/orgs/fluent-vue/discussions/834', async () => {
159+
// Arrange
160+
bundleEn = new FluentBundle('en-US')
161+
bundleUk = new FluentBundle('uk-UA')
162+
163+
const fluent = createFluentVue({
164+
bundles: [bundleUk],
165+
})
166+
167+
const child = {
168+
setup() {
169+
useFluent()
170+
},
171+
template: '<span>{{ $t("child") }}</span>',
172+
fluent: {
173+
'en-US': new FluentResource(ftl`
174+
child = Child message
175+
`),
176+
'uk-UA': new FluentResource(ftl`
177+
child = Повідомлення
178+
`),
179+
},
180+
}
181+
182+
const component = {
183+
components: {
184+
child,
185+
},
186+
data: () => ({
187+
show: true,
188+
}),
189+
template: '<child v-if="show" />',
190+
}
191+
192+
// Act
193+
const mounted = mountWithFluent(fluent, component)
194+
195+
expect(mounted.html()).toEqual('<span>Повідомлення</span>')
196+
197+
await mounted.setData({ show: false })
198+
199+
if (isVue3)
200+
expect(mounted.html()).toEqual('<!--v-if-->')
201+
else
202+
expect(mounted.html()).toEqual('')
203+
204+
fluent.bundles = [bundleEn]
205+
206+
await mounted.setData({ show: true })
207+
208+
// Assert
209+
expect(mounted.html()).toEqual('<span>Child message</span>')
210+
})
211+
107212
it('works when dynamically adding bundles', async () => {
108213
// Arrange
109214
bundleEn = new FluentBundle('en-US')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.