Files
prompt-optimizer/packages/ui/tests/unit/variable-extraction/useTextSelection.spec.ts
linshen c75afa89e9 feat(i18n): establish english-first locale baseline
- split UI locale packs into en-US, zh-CN, and zh-TW modules
- switch runtime defaults, docs, and repository guidance toward an English-first baseline
- update core, MCP, and UI runtime copy to remove hardcoded Chinese fallbacks
- add locale parity and no-hardcoded-runtime guardrails across the repo
2026-04-08 20:18:27 +08:00

38 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { ref } from 'vue'
import {
TEXT_SELECTION_ERRORS,
useTextSelection,
} from '../../../src/components/variable-extraction/useTextSelection'
describe('useTextSelection', () => {
it('returns an english fallback when the input is not ready', () => {
const { getSelection } = useTextSelection(ref(null))
expect(getSelection()).toEqual({
text: '',
start: 0,
end: 0,
isValid: false,
invalidReason: TEXT_SELECTION_ERRORS.inputNotReady,
})
})
it('returns english validation reasons for invalid selections', () => {
const element = document.createElement('textarea')
element.value = 'Hello {{name}} world'
element.selectionStart = 3
element.selectionEnd = 10
const { getSelection, validateSelection } = useTextSelection(ref(element))
expect(getSelection().invalidReason).toBe(
TEXT_SELECTION_ERRORS.crossesVariableBoundary
)
expect(validateSelection(element.value, 5, 5, '').reason).toBe(
TEXT_SELECTION_ERRORS.emptySelection
)
})
})