Skip to content

Commit

Permalink
chore(web): improve auto-test references to globals in #11881
Browse files Browse the repository at this point in the history
  • Loading branch information
jahorton committed Jul 23, 2024
1 parent 186ec71 commit 253e28c
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { assert } from 'chai';

import { DOMKeyboardLoader } from '@keymanapp/keyboard-processor/dom-keyboard-loader';
import { extendString, KeyboardHarness, Keyboard, KeyboardInterface, MinimalKeymanGlobal, Mock, DeviceSpec } from '@keymanapp/keyboard-processor';
import { extendString, KeyboardHarness, Keyboard, KeyboardInterface, MinimalKeymanGlobal, Mock, DeviceSpec, KeyboardKeymanGlobal } from '@keymanapp/keyboard-processor';

declare let window: typeof globalThis;
// KeymanEngine from the web/ folder... when available.
// At this level, though... we just mock it.
declare let keyman: KeyboardKeymanGlobal;
declare let KeymanWeb: KeyboardInterface;

// Note: rule processing tests will fail if string extensions are not established beforehand.
extendString();
Expand All @@ -15,8 +21,8 @@ const device: DeviceSpec = {

describe('Keyboard loading in DOM', function() {
afterEach(() => {
if(window['KeymanWeb']) {
window['KeymanWeb'].uninstall();
if (KeymanWeb) {
(KeymanWeb as KeyboardInterface).uninstall();
}
})

Expand All @@ -29,8 +35,10 @@ describe('Keyboard loading in DOM', function() {
assert.equal(keyboard.id, 'Keyboard_khmer_angkor');
assert.isTrue(keyboard.isChiral);
assert.isFalse(keyboard.isCJK);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);
assert.isOk(KeymanWeb);
assert.isOk(keyman);
assert.isOk(keyman.osk);
assert.isOk(keyman.osk.keyCodes);

// Should be cleared post-keyboard-load.
assert.isNotOk(harness.loadedKeyboard);
Expand All @@ -46,17 +54,21 @@ describe('Keyboard loading in DOM', function() {
assert.equal(keyboard.id, 'Keyboard_khmer_angkor');
assert.isTrue(keyboard.isChiral);
assert.isFalse(keyboard.isCJK);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);
assert.isOk(KeymanWeb);
assert.isOk(keyman);
assert.isOk(keyman.osk);
assert.isOk(keyman.osk.keyCodes);

// TODO: verify actual rule processing.
const nullKeyEvent = keyboard.constructNullKeyEvent(device);
const mock = new Mock();
const result = harness.processKeystroke(mock, nullKeyEvent);

assert.isOk(result);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);
assert.isOk(KeymanWeb);
assert.isOk(keyman);
assert.isOk(keyman.osk);
assert.isOk(keyman.osk.keyCodes);

// Should be cleared post-keyboard-load.
assert.isNotOk(harness.loadedKeyboard);
Expand Down Expand Up @@ -95,4 +107,4 @@ describe('Keyboard loading in DOM', function() {

harness.activeKeyboard = lao_keyboard;
});
});
});

0 comments on commit 253e28c

Please sign in to comment.