summaryrefslogtreecommitdiff
path: root/test/hotkey-util.test.js
diff options
context:
space:
mode:
authorCashew <52880648+Scrub1492@users.noreply.github.com>2024-01-06 08:00:37 +0700
committerGitHub <noreply@github.com>2024-01-06 01:00:37 +0000
commit60276d41ffd90044acc2f95e70b9b0c9a770417a (patch)
tree0bd08871a14d025007ba5453691b27976c39d77d /test/hotkey-util.test.js
parentd17ca4b2ff6e6f359dc5ea72c133f99fb016effd (diff)
Test updates (#501)
* update tests * japanese-util updates * update json-schema tests
Diffstat (limited to 'test/hotkey-util.test.js')
-rw-r--r--test/hotkey-util.test.js33
1 files changed, 19 insertions, 14 deletions
diff --git a/test/hotkey-util.test.js b/test/hotkey-util.test.js
index 5b8c4e73..d89d571d 100644
--- a/test/hotkey-util.test.js
+++ b/test/hotkey-util.test.js
@@ -18,12 +18,12 @@
/* eslint-disable no-multi-spaces */
-import {expect, test} from 'vitest';
+import {describe, expect, test} from 'vitest';
import {HotkeyUtil} from '../ext/js/input/hotkey-util.js';
/** */
function testCommandConversions() {
- test('CommandConversions', () => {
+ describe('CommandConversions', () => {
/** @type {{os: import('environment').OperatingSystem, command: string, expectedCommand: string, expectedInput: {key: string, modifiers: import('input').Modifier[]}}[]} */
const data = [
{os: 'win', command: 'Alt+F', expectedCommand: 'Alt+F', expectedInput: {key: 'KeyF', modifiers: ['alt']}},
@@ -44,18 +44,20 @@ function testCommandConversions() {
const hotkeyUtil = new HotkeyUtil();
for (const {command, os, expectedInput, expectedCommand} of data) {
- hotkeyUtil.os = os;
- const input = structuredClone(hotkeyUtil.convertCommandToInput(command));
- expect(input).toStrictEqual(expectedInput);
- const command2 = hotkeyUtil.convertInputToCommand(input.key, input.modifiers);
- expect(command2).toStrictEqual(expectedCommand);
+ test(`${command} on ${os} -> ${JSON.stringify(expectedInput)}`, () => {
+ hotkeyUtil.os = os;
+ const input = structuredClone(hotkeyUtil.convertCommandToInput(command));
+ expect(input).toStrictEqual(expectedInput);
+ const command2 = hotkeyUtil.convertInputToCommand(input.key, input.modifiers);
+ expect(command2).toStrictEqual(expectedCommand);
+ });
}
});
}
/** */
function testDisplayNames() {
- test('DisplayNames', () => {
+ describe('DisplayNames', () => {
/** @type {{os: import('environment').OperatingSystem, key: ?string, modifiers: import('input').Modifier[], expected: string}[]} */
const data = [
{os: 'win', key: null, modifiers: [], expected: ''},
@@ -136,17 +138,18 @@ function testDisplayNames() {
];
const hotkeyUtil = new HotkeyUtil();
- for (const {os, key, modifiers, expected} of data) {
+
+ test.each(data)('$key with $modifiers on $os -> display value $expected', ({os, key, modifiers, expected}) => {
hotkeyUtil.os = os;
const displayName = hotkeyUtil.getInputDisplayValue(key, modifiers);
expect(displayName).toStrictEqual(expected);
- }
+ });
});
}
/** */
function testSortModifiers() {
- test('SortModifiers', () => {
+ describe('SortModifiers', () => {
/** @type {{modifiers: import('input').Modifier[], expected: import('input').Modifier[]}[]} */
const data = [
{modifiers: [], expected: []},
@@ -155,9 +158,11 @@ function testSortModifiers() {
const hotkeyUtil = new HotkeyUtil();
for (const {modifiers, expected} of data) {
- const modifiers2 = hotkeyUtil.sortModifiers(modifiers);
- expect(modifiers2).toStrictEqual(modifiers);
- expect(modifiers2).toStrictEqual(expected);
+ test(`[${modifiers}] -> [${expected}]`, () => {
+ const modifiers2 = hotkeyUtil.sortModifiers(modifiers);
+ expect(modifiers2).toStrictEqual(modifiers);
+ expect(modifiers2).toStrictEqual(expected);
+ });
}
});
}