Match-id-63262d0c24ba5fc84d007fb93feb560ad185abb3
This commit is contained in:
parent
b4cd6a575b
commit
b14bf9f4c0
|
@ -1,8 +1,17 @@
|
||||||
import * as Horizon from '@cloudsop/horizon/index.ts';
|
import * as Horizon from '@cloudsop/horizon/index.ts';
|
||||||
import { getLogUtils } from '../jest/testUtils';
|
import {getLogUtils} from '../jest/testUtils';
|
||||||
|
|
||||||
describe('Keyboard Event', () => {
|
describe('Keyboard Event', () => {
|
||||||
const LogUtils = getLogUtils();
|
const LogUtils = getLogUtils();
|
||||||
|
const getKeyboardEvent = (type, keyCode, code, charCode) => {
|
||||||
|
return new KeyboardEvent(type, {
|
||||||
|
keyCode: keyCode ?? undefined,
|
||||||
|
code: code ?? undefined,
|
||||||
|
charCode: charCode ?? undefined,
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
it('keydown,keypress,keyup的keycode,charcode', () => {
|
it('keydown,keypress,keyup的keycode,charcode', () => {
|
||||||
const node = Horizon.render(
|
const node = Horizon.render(
|
||||||
|
@ -16,26 +25,12 @@ describe('Keyboard Event', () => {
|
||||||
/>,
|
/>,
|
||||||
container,
|
container,
|
||||||
);
|
);
|
||||||
node.dispatchEvent(
|
node.dispatchEvent(getKeyboardEvent('keydown', 50, 'Digit2'));
|
||||||
new KeyboardEvent('keydown', {
|
node.dispatchEvent(getKeyboardEvent('keyup', 50, 'Digit2'));
|
||||||
keyCode: 50,
|
|
||||||
code: 'Digit2',
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
node.dispatchEvent(
|
|
||||||
new KeyboardEvent('keyup', {
|
|
||||||
keyCode: 50,
|
|
||||||
code: 'Digit2',
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(LogUtils.getAndClear()).toEqual([
|
expect(LogUtils.getAndClear()).toEqual([
|
||||||
'onKeyDown: keycode: 50,charcode: 0',
|
'onKeyDown: keycode: 50,charcode: 0',
|
||||||
'onKeyUp: keycode: 50,charcode: 0'
|
'onKeyUp: keycode: 50,charcode: 0',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48,17 +43,10 @@ describe('Keyboard Event', () => {
|
||||||
/>,
|
/>,
|
||||||
container,
|
container,
|
||||||
);
|
);
|
||||||
node.dispatchEvent(
|
node.dispatchEvent(getKeyboardEvent('keypress', undefined, 'Digit2', 50));
|
||||||
new KeyboardEvent('keypress', {
|
|
||||||
charCode: 50,
|
|
||||||
code: 'Digit2',
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(LogUtils.getAndClear()).toEqual([
|
expect(LogUtils.getAndClear()).toEqual([
|
||||||
'onKeyPress: keycode: 0,charcode: 50'
|
'onKeyPress: keycode: 0,charcode: 50',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -71,15 +59,9 @@ describe('Keyboard Event', () => {
|
||||||
/>,
|
/>,
|
||||||
container,
|
container,
|
||||||
);
|
);
|
||||||
node.dispatchEvent(
|
node.dispatchEvent(getKeyboardEvent('keypress', undefined, undefined, 13));
|
||||||
new KeyboardEvent('keypress', {
|
|
||||||
charCode: 13,
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
expect(LogUtils.getAndClear()).toEqual([
|
expect(LogUtils.getAndClear()).toEqual([
|
||||||
'onKeyPress: keycode: 0,charcode: 13'
|
'onKeyPress: keycode: 0,charcode: 13',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -98,22 +80,8 @@ describe('Keyboard Event', () => {
|
||||||
/>,
|
/>,
|
||||||
container,
|
container,
|
||||||
);
|
);
|
||||||
node.dispatchEvent(
|
node.dispatchEvent(getKeyboardEvent('keydown', undefined, 'Digit2'));
|
||||||
new KeyboardEvent('keydown', {
|
node.dispatchEvent(getKeyboardEvent('keypress', undefined, 'Digit2', 50));
|
||||||
code: 'Digit2',
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
node.dispatchEvent(
|
|
||||||
new KeyboardEvent('keypress', {
|
|
||||||
keyCode: 50,
|
|
||||||
code: 'Digit2',
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
node.dispatchEvent(
|
node.dispatchEvent(
|
||||||
new KeyboardEvent('keyup', {
|
new KeyboardEvent('keyup', {
|
||||||
|
@ -126,7 +94,7 @@ describe('Keyboard Event', () => {
|
||||||
expect(LogUtils.getAndClear()).toEqual([
|
expect(LogUtils.getAndClear()).toEqual([
|
||||||
'onKeyDown: code: Digit2',
|
'onKeyDown: code: Digit2',
|
||||||
'onKeyPress: code: Digit2',
|
'onKeyPress: code: Digit2',
|
||||||
'onKeyUp: code: Digit2'
|
'onKeyUp: code: Digit2',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -149,32 +117,14 @@ describe('Keyboard Event', () => {
|
||||||
/>,
|
/>,
|
||||||
container,
|
container,
|
||||||
);
|
);
|
||||||
|
div.dispatchEvent(getKeyboardEvent('keydown', 40));
|
||||||
|
div.dispatchEvent(getKeyboardEvent('keyup', 40));
|
||||||
|
div.dispatchEvent(getKeyboardEvent('keypress', 40));
|
||||||
|
|
||||||
div.dispatchEvent(
|
|
||||||
new KeyboardEvent('keydown', {
|
|
||||||
keyCode: 40,
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
div.dispatchEvent(
|
|
||||||
new KeyboardEvent('keyup', {
|
|
||||||
keyCode: 40,
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
div.dispatchEvent(
|
|
||||||
new KeyboardEvent('keypress', {
|
|
||||||
charCode: 40,
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
expect(LogUtils.getAndClear()).toEqual([
|
expect(LogUtils.getAndClear()).toEqual([
|
||||||
'keydown handle',
|
'keydown handle',
|
||||||
'keyup handle',
|
'keyup handle',
|
||||||
'keypress handle'
|
'keypress handle',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue