diff --git a/src/keyboard/getNextKeyDef.ts b/src/keyboard/getNextKeyDef.ts index e4b458d0..4ef37e71 100644 --- a/src/keyboard/getNextKeyDef.ts +++ b/src/keyboard/getNextKeyDef.ts @@ -1,20 +1,6 @@ import {readNextDescriptor} from '../utils' import {keyboardKey, keyboardOptions} from './types' -enum legacyModifiers { - 'alt' = 'alt', - 'ctrl' = 'ctrl', - 'meta' = 'meta', - 'shift' = 'shift', -} - -enum legacyKeyMap { - ctrl = 'Control', - del = 'Delete', - esc = 'Escape', - space = ' ', -} - /** * Get the next key from keyMap * @@ -24,7 +10,6 @@ enum legacyKeyMap { * Keeping the key pressed can be written as `{key>}`. * When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`. * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key. - * Modifiers like `{shift}` imply being kept pressed. This can be turned of per `{shift/}`. */ export function getNextKeyDef( text: string, @@ -41,9 +26,7 @@ export function getNextKeyDef( descriptor, consumedLength, releasePrevious, - releaseSelf = !( - type === '{' && getEnumValue(legacyModifiers, descriptor.toLowerCase()) - ), + releaseSelf = true, repeat, } = readNextDescriptor(text) @@ -51,8 +34,7 @@ export function getNextKeyDef( if (type === '[') { return def.code?.toLowerCase() === descriptor.toLowerCase() } else if (type === '{') { - const key = mapLegacyKey(descriptor) - return def.key?.toLowerCase() === key.toLowerCase() + return def.key?.toLowerCase() === descriptor.toLowerCase() } return def.key === descriptor }) ?? { @@ -69,11 +51,3 @@ export function getNextKeyDef( repeat, } } - -function getEnumValue(f: Record, key: string): T | undefined { - return f[key] -} - -function mapLegacyKey(descriptor: string) { - return getEnumValue(legacyKeyMap, descriptor) ?? descriptor -} diff --git a/tests/keyboard/getNextKeyDef.ts b/tests/keyboard/getNextKeyDef.ts index 49717db5..ba6a2967 100644 --- a/tests/keyboard/getNextKeyDef.ts +++ b/tests/keyboard/getNextKeyDef.ts @@ -37,7 +37,6 @@ cases( 'unimplemented code': {text: '[Foo]', key: 'Unknown', code: 'Foo'}, key: {text: '{Control}', key: 'Control', code: 'ControlLeft'}, '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'}, @@ -85,14 +84,6 @@ cases( text: '{Control>2/}', modifiers: {releaseSelf: true}, }, - 'no releaseSelf on legacy modifier': { - text: '{ctrl}', - modifiers: {releaseSelf: false}, - }, - 'release legacy modifier': { - text: '{ctrl/}', - modifiers: {releaseSelf: true}, - }, }, ) diff --git a/tests/type/modifiers.js b/tests/type/modifiers.js index 63aaa0cb..648f238a 100644 --- a/tests/type/modifiers.js +++ b/tests/type/modifiers.js @@ -1,24 +1,18 @@ import userEvent from '#src' import {setup} from '#testHelpers/utils' -// Note, use the setup function at the bottom of the file... -// but don't hurt yourself trying to read it 😅 - -// keep in mind that we do not handle modifier interactions. This is primarily -// because modifiers behave differently on different operating systems. -// For example: {alt}{backspace}{/alt} will remove everything from the current -// cursor position to the beginning of the word on Mac, but you need to use -// {ctrl}{backspace}{/ctrl} to do that on Windows. And that doesn't appear to -// be consistent within an OS either 🙃 -// So we're not going to even try. - -// This also means that '{shift}a' will fire an input event with the shiftKey, -// but will not capitalize "a". - -test('{esc} triggers typing the escape character', () => { +// This test suite contains a lot of legacy code. +// A lot of tests performed here could be skipped +// as the current keyboard implementation merged different previous implementations +// that needed to be tested seperately. +// What will be left should be moved into keyboard/plugins. +// Keeping these for now to demonstrate changes. +// TODO: clean up this test suite + +test('{escape} triggers typing the escape character', () => { const {element, getEventSnapshot} = setup('') - userEvent.type(element, '{esc}') + userEvent.type(element, '{escape}') expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[value=""] @@ -231,10 +225,10 @@ test('{backspace} on an input type that does not support selection ranges', () = expect(element).toHaveValue('yo@example.ca') }) -test('{alt}a{/alt}', () => { +test('{alt>}a{/alt}', () => { const {element, getEventSnapshot} = setup('') - userEvent.type(element, '{alt}a{/alt}') + userEvent.type(element, '{alt>}a{/alt}') expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[value=""] @@ -259,10 +253,10 @@ test('{alt}a{/alt}', () => { `) }) -test('{meta}a{/meta}', () => { +test('{meta>}a{/meta}', () => { const {element, getEventSnapshot} = setup('') - userEvent.type(element, '{meta}a{/meta}') + userEvent.type(element, '{meta>}a{/meta}') expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[value="a"] @@ -289,10 +283,10 @@ test('{meta}a{/meta}', () => { `) }) -test('{ctrl}a{/ctrl}', () => { +test('{control>}a{/control}', () => { const {element, getEventSnapshot} = setup('') - userEvent.type(element, '{ctrl}a{/ctrl}') + userEvent.type(element, '{control>}a{/control}') expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[value=""] @@ -317,10 +311,10 @@ test('{ctrl}a{/ctrl}', () => { `) }) -test('{shift}a{/shift}', () => { +test('{shift>}a{/shift}', () => { const {element, getEventSnapshot} = setup('') - userEvent.type(element, '{shift}a{/shift}') + userEvent.type(element, '{shift>}a{/shift}') expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[value="a"] @@ -530,10 +524,10 @@ test('{enter} on a button when keypress calls prevent default', () => { `) }) -test('{space} on a button', () => { +test('[space] on a button', () => { const {element, getEventSnapshot} = setup('