summaryrefslogtreecommitdiff
path: root/source/github-helpers/hotkeys.test.ts
blob: 887263f909fd01adb7c0716598b52aed9b410b6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {test, assert} from 'vitest';

import {
	addHotkey,
} from './hotkey.js';

function testAddHotkey(existing: string | undefined, added: string, final: string): void {
	const link = document.createElement('a');
	if (existing) {
		link.setAttribute('data-hotkey', existing);
	}

	addHotkey(link, added);
	assert.equal(link.dataset.hotkey, final);
}

test('addHotkey if one is specified', testAddHotkey.bind(null,
	'T-REX',
	'CHICKEN',
	'T-REX,CHICKEN',
));
test('addHotkey if the same is already specified', testAddHotkey.bind(null,
	'CHICKEN',
	'CHICKEN',
	'CHICKEN',
));
test('addHotkey when none are specified', testAddHotkey.bind(null,
	undefined,
	'CHICKEN',
	'CHICKEN',
));