2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2022-09-28 08:28:21 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
2018-07-23 00:45:46 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const keydown_util = zrequire("keydown_util");
|
2018-07-23 00:45:46 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("test_early_returns", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stub = $.create("stub");
|
2018-12-04 19:15:31 +01:00
|
|
|
const opts = {
|
2022-01-25 11:36:19 +01:00
|
|
|
$elem: $stub,
|
2018-12-04 19:15:31 +01:00
|
|
|
handlers: {
|
2022-11-17 23:33:43 +01:00
|
|
|
/* istanbul ignore next */
|
|
|
|
ArrowLeft() {
|
2020-10-07 09:58:04 +02:00
|
|
|
throw new Error("do not dispatch this with alt key");
|
2018-12-04 19:15:31 +01:00
|
|
|
},
|
|
|
|
},
|
2018-07-23 00:45:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
keydown_util.handle(opts);
|
|
|
|
|
2018-12-04 19:15:31 +01:00
|
|
|
const e1 = {
|
2020-07-20 21:24:26 +02:00
|
|
|
type: "keydown",
|
2021-05-26 19:51:07 +02:00
|
|
|
key: "a", // not in keys
|
2018-07-23 00:45:46 +02:00
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$stub.trigger(e1);
|
2018-07-23 00:45:46 +02:00
|
|
|
|
2018-12-04 19:15:31 +01:00
|
|
|
const e2 = {
|
2020-07-20 21:24:26 +02:00
|
|
|
type: "keydown",
|
2021-05-26 19:51:07 +02:00
|
|
|
key: "Enter", // no handler
|
2018-07-23 00:45:46 +02:00
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$stub.trigger(e2);
|
2018-12-04 19:15:31 +01:00
|
|
|
|
|
|
|
const e3 = {
|
2020-07-20 21:24:26 +02:00
|
|
|
type: "keydown",
|
2021-05-26 19:51:07 +02:00
|
|
|
key: "ArrowLeft",
|
2018-12-04 19:15:31 +01:00
|
|
|
altKey: true, // let browser handle
|
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$stub.trigger(e3);
|
2018-07-23 00:45:46 +02:00
|
|
|
});
|
2022-09-28 08:28:21 +02:00
|
|
|
|
|
|
|
run_test("test_ime_enter_events", () => {
|
|
|
|
// these events shouldn't be recognized as a return keypress.
|
|
|
|
const event_1 = {
|
|
|
|
key: "Enter",
|
|
|
|
originalEvent: {
|
|
|
|
isComposing: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const event_2 = {
|
|
|
|
key: "Random",
|
|
|
|
originalEvent: {
|
|
|
|
isComposing: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
assert.ok(!keydown_util.is_enter_event(event_1));
|
|
|
|
assert.ok(!keydown_util.is_enter_event(event_2));
|
|
|
|
|
|
|
|
// these are valid return keypress events.
|
|
|
|
const event_3 = {
|
|
|
|
key: "Enter",
|
|
|
|
originalEvent: {
|
|
|
|
isComposing: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const event_4 = {
|
|
|
|
key: "Enter",
|
|
|
|
// Edgacase: if there is no originalEvent, JQuery didn't provide the object.
|
|
|
|
};
|
|
|
|
assert.ok(keydown_util.is_enter_event(event_3));
|
|
|
|
assert.ok(keydown_util.is_enter_event(event_4));
|
|
|
|
});
|