pgadmin4/web/regression/javascript/erd/keyboard_shortcut_action_spec.js
Aditya Toshniwal 0f46f070ed Port the remaining components of the ERD Tool to React. Fixes #7343
1. Make use of MUI styles and remove SCSS.
2. Use the new common components for buttons and tooltips, so that they are consistent.
3. UI design should be aligned with the query tool.
4. Remove tippyjs and Alertify dependencies.
2022-09-06 18:09:13 +05:30

62 lines
2.0 KiB
JavaScript

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import {KeyboardShortcutAction} from 'pgadmin.tools.erd/erd_tool/components/ERDTool';
describe('KeyboardShortcutAction', ()=>{
let keyAction = null;
let key1 = {
alt: true,
control: true,
shift: false,
key: {
key_code: 65,
},
};
let key2 = {
alt: false,
control: true,
shift: false,
key: {
key_code: 66,
},
};
let handler1 = jasmine.createSpy('handler1');
let handler2 = jasmine.createSpy('handler2');
beforeAll(()=>{
spyOn(KeyboardShortcutAction.prototype, 'shortcutKey').and.callThrough();
keyAction = new KeyboardShortcutAction([
[key1, handler1],
[key2, handler2],
]);
});
it('init', ()=>{
expect(Object.keys(keyAction.shortcuts).length).toBe(2);
});
it('shortcutKey', ()=>{
expect(keyAction.shortcutKey(true, true, true, true, 65)).toBe('true:true:true:true:65');
expect(keyAction.shortcutKey(true, false, true, true, 65)).toBe('true:false:true:true:65');
expect(keyAction.shortcutKey(true, true, false, true, 65)).toBe('true:true:false:true:65');
expect(keyAction.shortcutKey(true, true, true, false, 65)).toBe('true:true:true:false:65');
expect(keyAction.shortcutKey(false, true, true, true, 65)).toBe('false:true:true:true:65');
});
it('callHandler', ()=>{
let keyEvent = {altKey: key1.alt, ctrlKey: key1.control, shiftKey: key1.shift, metaKey: false, keyCode:key1.key.key_code};
keyAction.callHandler(keyEvent);
expect(handler1).toHaveBeenCalled();
keyEvent = {altKey: key2.alt, ctrlKey: key2.control, shiftKey: key2.shift, metaKey: false, keyCode:key2.key.key_code};
keyAction.callHandler(keyEvent);
expect(handler2).toHaveBeenCalled();
});
});