Skip to content

Commit

Permalink
fix(keyboard): parse modifiers as characters (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche committed Mar 17, 2021
1 parent f251d15 commit fa9299e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/__tests__/keyboard/getNextKeyDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ cases(
key,
code,
}) as keyboardKey,
consumedLength: text.length,
}),
)
expect(getNextKeyDef(`${text}/foo`, options)).toEqual(
expect.objectContaining({
keyDef: expect.objectContaining({
key,
code,
}) as keyboardKey,
consumedLength: text.length,
}),
)
},
Expand All @@ -29,6 +39,7 @@ cases(
'unimplemented key': {text: '{Foo}', key: 'Foo', code: 'Unknown'},
'legacy modifier': {text: '{ctrl}', key: 'Control', code: 'ControlLeft'},
'printable character': {text: 'a', key: 'a', code: 'KeyA'},
'modifiers as printable characters': {text: '/', key: '/', code: 'Unknown'},
'{ as printable': {text: '{{', key: '{', code: 'Unknown'},
'[ as printable': {text: '[[', key: '[', code: 'Unknown'},
},
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -1514,3 +1514,11 @@ test('{enter} fires click on links', () => {
a - keyup: Enter (13)
`)
})

test('type non-alphanumeric characters', () => {
const {element} = setup(`<input/>`)

userEvent.type(element, 'https://test.local')

expect(element).toHaveValue('https://test.local')
})
6 changes: 4 additions & 2 deletions src/keyboard/getNextKeyDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getNextKeyDef(
releaseSelf: boolean
} {
const startBracket = ['{', '['].includes(text[0]) ? text[0] : ''
const startModifier = text[1] === '/' ? '/' : ''
const startModifier = startBracket && text[1] === '/' ? '/' : ''

const descriptorStart = startBracket.length + startModifier.length
const descriptor = startBracket
Expand All @@ -37,7 +37,9 @@ export function getNextKeyDef(

const descriptorEnd = descriptorStart + descriptor.length
const endModifier =
descriptor !== startBracket && ['/', '>'].includes(text[descriptorEnd])
startBracket &&
descriptor !== startBracket &&
['/', '>'].includes(text[descriptorEnd])
? text[descriptorEnd]
: ''

Expand Down

0 comments on commit fa9299e

Please sign in to comment.