Skip to content

Commit 2d3d694

Browse files
committed
fix: add in support for keyboarding { and }
1 parent 4525a27 commit 2d3d694

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/__tests__/user-keyboard.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const {resolve} = require('path')
2+
const {render} = require('../pure')
3+
const {fireEvent} = require("../events");
4+
5+
test('Should render { and } in user keyboard', async () => {
6+
const {findByText, userEvent: userEventLocal} = await render('node', [
7+
resolve(__dirname, './execute-scripts/stdio-inquirer-input.js'),
8+
])
9+
10+
const instance = await findByText('What is your name?')
11+
expect(instance).toBeTruthy()
12+
13+
userEventLocal.keyboard('{Hello}')
14+
15+
expect(await findByText('{Hello}')).toBeTruthy()
16+
17+
await fireEvent.sigterm(instance)
18+
})

src/user-event/keyboard/getNextKeyDef.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {keyboardKey, keyboardOptions} from './types'
22

33
enum bracketDict {
4-
'{' = '}',
54
'[' = ']',
65
}
76

@@ -28,14 +27,11 @@ export function getNextKeyDef(
2827
const keyDef: keyboardKey = options.keyboardMap.find(def => {
2928
if (type === '[') {
3029
return def.code?.toLowerCase() === descriptor.toLowerCase()
31-
} else if (type === '{') {
32-
return def.hex?.toLowerCase() === descriptor.toLowerCase()
3330
}
3431
return def.hex === descriptor
3532
}) ?? {
36-
code: 'Unknown',
33+
code: descriptor,
3734
hex: 'Unknown',
38-
[type === '[' ? 'code' : 'key']: descriptor,
3935
}
4036

4137
return {
@@ -51,15 +47,14 @@ function readNextDescriptor(text: string) {
5147

5248
pos += startBracket.length
5349

54-
// `foo{{bar` is an escaped char at position 3,
55-
// but `foo{{{>5}bar` should be treated as `{` pressed down for 5 keydowns.
50+
// `foo[[bar` is an escaped char at position 3,
51+
// but `foo[[[>5}bar` should be treated as `{` pressed down for 5 keydowns.
5652
const startBracketRepeated = startBracket
5753
? (text.match(new RegExp(`^\\${startBracket}+`)) as RegExpMatchArray)[0]
5854
.length
5955
: 0
6056
const isEscapedChar =
61-
startBracketRepeated === 2 ||
62-
(startBracket === '{' && startBracketRepeated > 3)
57+
startBracketRepeated === 2
6358

6459
const type = isEscapedChar ? '' : startBracket
6560

src/user-event/keyboard/keyMap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const defaultKeyMap: keyboardKey[] = [
2121
{code: 'Digit-', hex: '\x2d'},
2222
{code: 'Digit@', hex: '\x40'},
2323
{code: 'Digit^', hex: '\x5e'},
24+
{code: 'Digit{', hex: '\x7b'},
25+
{code: 'Digit|', hex: '\x7c'},
26+
{code: 'Digit}', hex: '\x7d'},
27+
{code: 'Digit~', hex: '\x7e'},
2428
{code: 'Digit0', hex: '\x30'},
2529
{code: 'Digit1', hex: '\x31'},
2630
{code: 'Digit2', hex: '\x32'},

0 commit comments

Comments
 (0)