mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-09-01 18:58:58 +00:00
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { computed, nextTick, ref } from 'vue'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { useComposedFieldValue } from '@/ui/controls/useComposedFieldValue'
|
|
|
|
describe('useComposedFieldValue', () => {
|
|
it('does not overwrite active IME composition from external state', async () => {
|
|
const externalValue = ref('before')
|
|
const updates: string[] = []
|
|
const field = useComposedFieldValue(
|
|
computed(() => externalValue.value),
|
|
(value) => updates.push(value),
|
|
)
|
|
|
|
field.startComposition()
|
|
field.input('composing')
|
|
externalValue.value = 'external'
|
|
await nextTick()
|
|
|
|
expect(field.localValue.value).toBe('composing')
|
|
|
|
field.endComposition('completed')
|
|
|
|
expect(field.localValue.value).toBe('completed')
|
|
expect(updates).toEqual(['composing', 'completed'])
|
|
})
|
|
|
|
it('resumes controlled updates after composition and clears explicitly', async () => {
|
|
const externalValue = ref('before')
|
|
const updates: string[] = []
|
|
const field = useComposedFieldValue(
|
|
computed(() => externalValue.value),
|
|
(value) => updates.push(value),
|
|
)
|
|
|
|
field.startComposition()
|
|
field.endComposition('completed')
|
|
externalValue.value = 'after'
|
|
await nextTick()
|
|
|
|
expect(field.localValue.value).toBe('after')
|
|
|
|
field.clear()
|
|
|
|
expect(field.composing.value).toBe(false)
|
|
expect(field.localValue.value).toBe('')
|
|
expect(updates.at(-1)).toBe('')
|
|
})
|
|
})
|