-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Johann Jacobsohn
committed
Oct 16, 2023
1 parent
28c00ed
commit a1e83f6
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[test] | ||
preload = "./happydom.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { GlobalRegistrator } from "@happy-dom/global-registrator"; | ||
GlobalRegistrator.register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/// <reference lib="dom" /> | ||
|
||
import {test, expect} from 'bun:test'; | ||
import ShoSho from '../dist/index.js'; | ||
|
||
const keys = { | ||
f: {'key': 'f'}, | ||
g: {'key': 'g'}, | ||
h: {'key': 'h'}, | ||
} | ||
|
||
function keypress(key){ | ||
document.dispatchEvent(new KeyboardEvent('keydown', keys[key])); | ||
document.dispatchEvent(new KeyboardEvent('keyup', keys[key])); | ||
} | ||
|
||
test ( 'key sequences do not trigger single key shortcuts', async () => { | ||
let f_pressed = 0; | ||
let g_pressed = 0; | ||
let fg_pressed = 0; | ||
|
||
const sho = new ShoSho (); | ||
sho.register('f', () => { f_pressed++; }); | ||
sho.register('g', () => { g_pressed++; }); | ||
sho.register('f g', () => { fg_pressed++; return true }); | ||
sho.start() | ||
|
||
keypress('f') | ||
expect(f_pressed).toEqual(1) | ||
|
||
await new Promise(resolve => setTimeout(() => resolve(''), 1000)); | ||
|
||
keypress('g') | ||
expect(g_pressed).toEqual(1) | ||
expect(fg_pressed).toEqual(0) | ||
|
||
keypress('f') | ||
keypress('g') | ||
expect(f_pressed).toEqual(1) | ||
expect(g_pressed).toEqual(1) | ||
expect(fg_pressed).toEqual(1) | ||
}) | ||
|
||
test ( 'key sequences are not triggered by single keys', () => { | ||
let fg_pressed = 0; | ||
let fh_pressed = 0; | ||
|
||
const sho = new ShoSho (); | ||
|
||
sho.register('f g', () => { fg_pressed++; return true }); | ||
sho.register('f h', () => { fh_pressed++; return true }); | ||
sho.start() | ||
|
||
keypress('f') | ||
keypress('g') | ||
expect(fg_pressed).toEqual(1) | ||
expect(fh_pressed).toEqual(0) | ||
|
||
keypress('f') | ||
keypress('h') | ||
expect(fg_pressed).toEqual(1) | ||
expect(fh_pressed).toEqual(1) | ||
|
||
keypress('g') | ||
keypress('h') | ||
expect(fg_pressed).toEqual(1) | ||
expect(fh_pressed).toEqual(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"extends": "tsex/tsconfig.json", | ||
"compilerOptions": { | ||
"lib": ["esnext", "dom"], | ||
"noImplicitAny": false | ||
} | ||
} |