Fix tests that mock incomplete key events

pull/21833/head
Clemens Zeidler 2021-03-06 14:17:53 +13:00
parent efc5d413c4
commit 71d63f016a
1 changed files with 17 additions and 12 deletions

View File

@ -147,30 +147,35 @@ export function isKeyComboMatch(ev: KeyboardEvent | React.KeyboardEvent, combo:
const comboAlt = combo.altKey ?? false; const comboAlt = combo.altKey ?? false;
const comboShift = combo.shiftKey ?? false; const comboShift = combo.shiftKey ?? false;
const comboMeta = combo.metaKey ?? false; const comboMeta = combo.metaKey ?? false;
// Tests mock events may keep the modifiers undefined; convert them to booleans
const evCtrl = ev.ctrlKey ?? false;
const evAlt = ev.altKey ?? false;
const evShift = ev.shiftKey ?? false;
const evMeta = ev.metaKey ?? false;
// When ctrlOrCmd is set, the keys need do evaluated differently on PC and Mac // When ctrlOrCmd is set, the keys need do evaluated differently on PC and Mac
if (combo.ctrlOrCmd) { if (combo.ctrlOrCmd) {
if (onMac) { if (onMac) {
if (!ev.metaKey if (!evMeta
|| ev.ctrlKey !== comboCtrl || evCtrl !== comboCtrl
|| ev.altKey !== comboAlt || evAlt !== comboAlt
|| ev.shiftKey !== comboShift) { || evShift !== comboShift) {
return false; return false;
} }
} else { } else {
if (!ev.ctrlKey if (!evCtrl
|| ev.metaKey !== comboMeta || evMeta !== comboMeta
|| ev.altKey !== comboAlt || evAlt !== comboAlt
|| ev.shiftKey !== comboShift) { || evShift !== comboShift) {
return false; return false;
} }
} }
return true; return true;
} }
if (ev.metaKey !== comboMeta if (evMeta !== comboMeta
|| ev.ctrlKey !== comboCtrl || evCtrl !== comboCtrl
|| ev.altKey !== comboAlt || evAlt !== comboAlt
|| ev.shiftKey !== comboShift) { || evShift !== comboShift) {
return false; return false;
} }