mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-08-30 01:38:55 +00:00
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { isTextInputElement } from '@/utils/textInputFocus'
|
|
|
|
function element(
|
|
tagName: string,
|
|
attributes: Record<string, string> = {},
|
|
isContentEditable = false,
|
|
) {
|
|
return {
|
|
getAttribute(name: string) {
|
|
return attributes[name] ?? null
|
|
},
|
|
isContentEditable,
|
|
tagName,
|
|
}
|
|
}
|
|
|
|
describe('text input focus', () => {
|
|
it('recognizes fields that accept typed text', () => {
|
|
expect(isTextInputElement(element('INPUT'))).toBe(true)
|
|
expect(isTextInputElement(element('INPUT', { type: 'number' }))).toBe(true)
|
|
expect(isTextInputElement(element('TEXTAREA'))).toBe(true)
|
|
expect(isTextInputElement(element('DIV', {}, true))).toBe(true)
|
|
expect(isTextInputElement(element('DIV', { role: 'textbox' }))).toBe(true)
|
|
})
|
|
|
|
it('ignores non-text and read-only controls', () => {
|
|
expect(isTextInputElement(element('INPUT', { type: 'checkbox' }))).toBe(
|
|
false,
|
|
)
|
|
expect(isTextInputElement(element('INPUT', { type: 'range' }))).toBe(false)
|
|
expect(isTextInputElement(element('INPUT', { readonly: '' }))).toBe(false)
|
|
expect(isTextInputElement(element('BUTTON'))).toBe(false)
|
|
})
|
|
})
|