Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Feb 29, 2024
1 parent f69dd4a commit 6dea4c3
Showing 1 changed file with 42 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import * as undo from 'roosterjs-content-model-core/lib/publicApi/undo/undo';
import { EditorEnvironment, IEditor, PluginEvent } from 'roosterjs-content-model-types';
import { ShortcutPlugin } from '../../lib/shortcut/ShortcutPlugin';

const enum Keys {
BACKSPACE = 8,
SPACE = 32,
A = 65,
B = 66,
I = 73,
U = 85,
Y = 89,
Z = 90,
COMMA = 188,
PERIOD = 190,
FORWARD_SLASH = 191,
}

describe('ShortcutPlugin', () => {
let preventDefaultSpy: jasmine.Spy;
let mockedEditor: IEditor;
Expand All @@ -24,14 +38,14 @@ describe('ShortcutPlugin', () => {
});

function createMockedEvent(
key: string,
which: number,
ctrlKey: boolean,
altKey: boolean,
shiftKey: boolean,
metaKey: boolean
): KeyboardEvent {
return {
key,
which,
ctrlKey,
shiftKey,
altKey,
Expand All @@ -46,7 +60,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('a', true, false, false, false),
rawEvent: createMockedEvent(Keys.A, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -66,7 +80,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('b', true, false, false, false),
rawEvent: createMockedEvent(Keys.B, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -87,7 +101,7 @@ describe('ShortcutPlugin', () => {

const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('i', true, false, false, false),
rawEvent: createMockedEvent(Keys.I, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -107,7 +121,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('u', true, false, false, false),
rawEvent: createMockedEvent(Keys.U, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -127,7 +141,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent(' ', true, false, false, false),
rawEvent: createMockedEvent(Keys.SPACE, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -147,7 +161,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('z', true, false, false, false),
rawEvent: createMockedEvent(Keys.Z, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -167,7 +181,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('Backspace', false, true, false, false),
rawEvent: createMockedEvent(Keys.BACKSPACE, false, true, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -187,7 +201,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('y', true, false, false, false),
rawEvent: createMockedEvent(Keys.Y, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -207,7 +221,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('z', true, false, true, false),
rawEvent: createMockedEvent(Keys.Z, true, false, true, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -227,7 +241,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('.', true, false, false, false),
rawEvent: createMockedEvent(Keys.PERIOD, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -247,7 +261,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('/', true, false, false, false),
rawEvent: createMockedEvent(Keys.FORWARD_SLASH, true, false, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -267,7 +281,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('>', true, false, true, false),
rawEvent: createMockedEvent(Keys.PERIOD, true, false, true, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -287,7 +301,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('<', true, false, true, false),
rawEvent: createMockedEvent(Keys.COMMA, true, false, true, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -313,7 +327,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('a', false, false, false, true),
rawEvent: createMockedEvent(Keys.A, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -333,7 +347,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('b', false, false, false, true),
rawEvent: createMockedEvent(Keys.B, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -354,7 +368,7 @@ describe('ShortcutPlugin', () => {

const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('i', false, false, false, true),
rawEvent: createMockedEvent(Keys.I, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -374,7 +388,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('u', false, false, false, true),
rawEvent: createMockedEvent(Keys.U, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -394,7 +408,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent(' ', false, false, false, true),
rawEvent: createMockedEvent(Keys.SPACE, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -414,7 +428,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('z', false, false, false, true),
rawEvent: createMockedEvent(Keys.Z, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -435,7 +449,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('Backspace', false, true, false, false),
rawEvent: createMockedEvent(Keys.BACKSPACE, false, true, false, false),
};

plugin.initialize(mockedEditor);
Expand All @@ -456,7 +470,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('y', false, false, false, true),
rawEvent: createMockedEvent(Keys.Y, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -477,7 +491,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('z', false, false, true, true),
rawEvent: createMockedEvent(Keys.Z, false, false, true, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -497,7 +511,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('.', false, false, false, true),
rawEvent: createMockedEvent(Keys.PERIOD, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -517,7 +531,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('/', false, false, false, true),
rawEvent: createMockedEvent(Keys.FORWARD_SLASH, false, false, false, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -537,7 +551,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('>', false, false, true, true),
rawEvent: createMockedEvent(Keys.PERIOD, false, false, true, true),
};

plugin.initialize(mockedEditor);
Expand All @@ -557,7 +571,7 @@ describe('ShortcutPlugin', () => {
const plugin = new ShortcutPlugin();
const event: PluginEvent = {
eventType: 'keyDown',
rawEvent: createMockedEvent('<', false, false, true, true),
rawEvent: createMockedEvent(Keys.COMMA, false, false, true, true),
};

plugin.initialize(mockedEditor);
Expand Down

0 comments on commit 6dea4c3

Please sign in to comment.