2022-03-21 02:59:26 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2023-01-02 00:23:55 -06:00
|
|
|
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2022-03-21 02:59:26 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
import jasmineEnzyme from 'jasmine-enzyme';
|
|
|
|
import React from 'react';
|
|
|
|
import '../helper/enzyme.helper';
|
|
|
|
import { withTheme } from '../fake_theme';
|
|
|
|
import { createMount } from '@material-ui/core/test-utils';
|
|
|
|
import {
|
|
|
|
OutlinedInput,
|
|
|
|
} from '@material-ui/core';
|
|
|
|
import KeyboardShortcuts from '../../../pgadmin/static/js/components/KeyboardShortcuts';
|
2022-03-23 02:58:35 -05:00
|
|
|
import { InputCheckbox } from '../../../pgadmin/static/js/components/FormComponents';
|
2022-03-21 02:59:26 -05:00
|
|
|
|
|
|
|
/* MUI Components need to be wrapped in Theme for theme vars */
|
|
|
|
describe('KeyboardShortcuts', () => {
|
|
|
|
let mount;
|
|
|
|
let defult_value = {
|
2022-03-29 05:57:33 -05:00
|
|
|
'control': true,
|
2022-03-21 02:59:26 -05:00
|
|
|
'alt': true,
|
|
|
|
'key': {
|
|
|
|
'char': 'a',
|
|
|
|
'key_code': 97
|
2022-03-23 02:58:35 -05:00
|
|
|
},
|
|
|
|
'shift': false
|
2022-03-21 02:59:26 -05:00
|
|
|
};
|
|
|
|
let fields = [{
|
|
|
|
type: 'keyCode',
|
|
|
|
label: 'Key'
|
|
|
|
}, {
|
|
|
|
name: 'shift',
|
|
|
|
label: 'Shift',
|
|
|
|
type: 'checkbox'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'control',
|
|
|
|
label: 'Control',
|
|
|
|
type: 'checkbox'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'alt',
|
|
|
|
label: 'Alt/Option',
|
|
|
|
type: 'checkbox'
|
|
|
|
}];
|
|
|
|
|
|
|
|
/* Use createMount so that material ui components gets the required context */
|
|
|
|
/* https://material-ui.com/guides/testing/#api */
|
|
|
|
beforeAll(() => {
|
|
|
|
mount = createMount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
mount.cleanUp();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jasmineEnzyme();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('KeyboardShortcuts', () => {
|
|
|
|
let ThemedFormInputKeyboardShortcuts = withTheme(KeyboardShortcuts), ctrl;
|
2022-03-23 02:58:35 -05:00
|
|
|
let onChange = jasmine.createSpy('onChange');
|
2022-03-21 02:59:26 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
ctrl = mount(
|
|
|
|
<ThemedFormInputKeyboardShortcuts
|
|
|
|
value={defult_value}
|
|
|
|
fields={fields}
|
|
|
|
controlProps={{
|
2022-03-23 02:58:35 -05:00
|
|
|
extraprop: 'test',
|
|
|
|
keyDown: onChange
|
2022-03-21 02:59:26 -05:00
|
|
|
}}
|
2022-03-23 02:58:35 -05:00
|
|
|
onChange={onChange}
|
2022-03-21 02:59:26 -05:00
|
|
|
/>);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('init', () => {
|
|
|
|
expect(ctrl.find(OutlinedInput).prop('value')).toBe('a');
|
|
|
|
});
|
|
|
|
|
2022-03-23 02:58:35 -05:00
|
|
|
it('Key change', (done) => {
|
|
|
|
ctrl.find(OutlinedInput).at(0).find('input').simulate('keydown', { key: '', keyCode: 32});
|
2022-03-29 05:57:33 -05:00
|
|
|
expect(onChange).toHaveBeenCalledWith({ control: true, alt: true, key: { char: 'Space', key_code: 32 }, shift: false });
|
2022-03-23 02:58:35 -05:00
|
|
|
done();
|
|
|
|
});
|
2022-03-21 02:59:26 -05:00
|
|
|
|
2022-03-23 02:58:35 -05:00
|
|
|
it('Shift option', (done) => {
|
|
|
|
ctrl.find(InputCheckbox).at(0).find('input').simulate('change', { target: { checked: true, name: 'shift' } });
|
2022-03-29 05:57:33 -05:00
|
|
|
expect(onChange).toHaveBeenCalledWith({ control: true, alt: true, key: { char: 'a', key_code: 97 }, shift: true });
|
2022-03-23 02:58:35 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2022-03-29 05:57:33 -05:00
|
|
|
it('Control option', (done) => {
|
2022-03-23 02:58:35 -05:00
|
|
|
ctrl.find(InputCheckbox).at(1).find('input').simulate('change', { target: { checked: false, name: 'ctrl' } });
|
2022-03-29 05:57:33 -05:00
|
|
|
expect(onChange).toHaveBeenCalledWith({ control: false, alt: true, key: { char: 'a', key_code: 97 }, shift: false });
|
2022-03-23 02:58:35 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('Alt option', (done) => {
|
|
|
|
ctrl.find(InputCheckbox).at(2).find('input').simulate('change', { target: { checked: false, name: 'alt' } });
|
2022-03-29 05:57:33 -05:00
|
|
|
expect(onChange).toHaveBeenCalledWith({ control: true, alt: false, key: { char: 'a', key_code: 97 }, shift: false });
|
2022-03-23 02:58:35 -05:00
|
|
|
done();
|
2022-03-21 02:59:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|