|
| 1 | +import { describe, it, expect, vi } from 'vitest'; |
| 2 | + |
| 3 | +vi.hoisted(() => { |
| 4 | + const g = globalThis as any; |
| 5 | + g.android = { |
| 6 | + ...g.android, |
| 7 | + text: { |
| 8 | + ...g.android?.text, |
| 9 | + InputType: { TYPE_NULL: 0, TYPE_CLASS_TEXT: 1, TYPE_CLASS_NUMBER: 2, TYPE_CLASS_PHONE: 3, TYPE_TEXT_VARIATION_EMAIL_ADDRESS: 32 }, |
| 10 | + }, |
| 11 | + }; |
| 12 | +}); |
| 13 | + |
| 14 | +import { EditableTextBase } from './index.android'; |
| 15 | +import { keyboardTypeProperty } from './editable-text-base-common'; |
| 16 | + |
| 17 | +function inputTypeFor(value: unknown): number { |
| 18 | + const target = { _setInputType: vi.fn() }; |
| 19 | + (EditableTextBase.prototype as any)[keyboardTypeProperty.setNative].call(target, value); |
| 20 | + return target._setInputType.mock.calls[0][0]; |
| 21 | +} |
| 22 | + |
| 23 | +describe('EditableTextBase keyboardType (Android)', () => { |
| 24 | + const InputType = (globalThis as any).android.text.InputType; |
| 25 | + |
| 26 | + it('uses the text keyboard for null and undefined', () => { |
| 27 | + expect(inputTypeFor(null)).toBe(InputType.TYPE_CLASS_TEXT); |
| 28 | + expect(inputTypeFor(undefined)).toBe(InputType.TYPE_CLASS_TEXT); |
| 29 | + }); |
| 30 | + |
| 31 | + it('uses the text keyboard for unknown names', () => { |
| 32 | + expect(inputTypeFor('text')).toBe(InputType.TYPE_CLASS_TEXT); |
| 33 | + }); |
| 34 | + |
| 35 | + it('passes native input type numbers through, including TYPE_NULL', () => { |
| 36 | + expect(inputTypeFor(InputType.TYPE_CLASS_PHONE)).toBe(InputType.TYPE_CLASS_PHONE); |
| 37 | + expect(inputTypeFor('3')).toBe(InputType.TYPE_CLASS_PHONE); |
| 38 | + expect(inputTypeFor(0)).toBe(InputType.TYPE_NULL); |
| 39 | + }); |
| 40 | + |
| 41 | + it('maps named keyboard types', () => { |
| 42 | + expect(inputTypeFor('integer')).toBe(InputType.TYPE_CLASS_NUMBER); |
| 43 | + }); |
| 44 | +}); |
0 commit comments