mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 02:05:45 +03:00
Fix tests that mock incomplete key events
This commit is contained in:
parent
efc5d413c4
commit
71d63f016a
1 changed files with 17 additions and 12 deletions
|
@ -147,30 +147,35 @@ export function isKeyComboMatch(ev: KeyboardEvent | React.KeyboardEvent, combo:
|
|||
const comboAlt = combo.altKey ?? false;
|
||||
const comboShift = combo.shiftKey ?? 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
|
||||
if (combo.ctrlOrCmd) {
|
||||
if (onMac) {
|
||||
if (!ev.metaKey
|
||||
|| ev.ctrlKey !== comboCtrl
|
||||
|| ev.altKey !== comboAlt
|
||||
|| ev.shiftKey !== comboShift) {
|
||||
if (!evMeta
|
||||
|| evCtrl !== comboCtrl
|
||||
|| evAlt !== comboAlt
|
||||
|| evShift !== comboShift) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!ev.ctrlKey
|
||||
|| ev.metaKey !== comboMeta
|
||||
|| ev.altKey !== comboAlt
|
||||
|| ev.shiftKey !== comboShift) {
|
||||
if (!evCtrl
|
||||
|| evMeta !== comboMeta
|
||||
|| evAlt !== comboAlt
|
||||
|| evShift !== comboShift) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ev.metaKey !== comboMeta
|
||||
|| ev.ctrlKey !== comboCtrl
|
||||
|| ev.altKey !== comboAlt
|
||||
|| ev.shiftKey !== comboShift) {
|
||||
if (evMeta !== comboMeta
|
||||
|| evCtrl !== comboCtrl
|
||||
|| evAlt !== comboAlt
|
||||
|| evShift !== comboShift) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue