2022-03-21 02:59:26 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2024-01-01 02:43:48 -06:00
|
|
|
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2022-03-21 02:59:26 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
import React from 'react';
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2022-03-21 02:59:26 -05:00
|
|
|
import { withTheme } from '../fake_theme';
|
2023-10-23 07:13:17 -05:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
|
|
|
|
|
|
|
2022-03-21 02:59:26 -05:00
|
|
|
import KeyboardShortcuts from '../../../pgadmin/static/js/components/KeyboardShortcuts';
|
|
|
|
|
|
|
|
/* MUI Components need to be wrapped in Theme for theme vars */
|
|
|
|
describe('KeyboardShortcuts', () => {
|
|
|
|
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'
|
|
|
|
}];
|
|
|
|
|
|
|
|
describe('KeyboardShortcuts', () => {
|
2023-10-23 07:13:17 -05:00
|
|
|
let ThemedFormInputKeyboardShortcuts = withTheme(KeyboardShortcuts);
|
|
|
|
let onChange = jest.fn();
|
2022-03-21 02:59:26 -05:00
|
|
|
beforeEach(() => {
|
2023-10-23 07:13:17 -05:00
|
|
|
render(
|
2022-03-21 02:59:26 -05:00
|
|
|
<ThemedFormInputKeyboardShortcuts
|
|
|
|
value={defult_value}
|
|
|
|
fields={fields}
|
|
|
|
controlProps={{
|
2022-03-23 02:58:35 -05:00
|
|
|
extraprop: 'test',
|
2023-12-21 00:37:26 -06:00
|
|
|
'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', () => {
|
2023-10-23 07:13:17 -05:00
|
|
|
expect(screen.getByRole('textbox').getAttribute('value')).toBe('a');
|
2022-03-21 02:59:26 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('Key change', () => {
|
|
|
|
fireEvent.keyDown(screen.getByRole('textbox'), {
|
|
|
|
key: 'Space', code: 32, 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
|
|
|
});
|
2022-03-21 02:59:26 -05:00
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('Shift option', () => {
|
|
|
|
const input = screen.getAllByRole('checkbox').at(0);
|
|
|
|
fireEvent.click(input);
|
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
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('Control option', () => {
|
|
|
|
const input = screen.getAllByRole('checkbox').at(1);
|
|
|
|
fireEvent.click(input);
|
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
|
|
|
});
|
|
|
|
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('Alt option', () => {
|
|
|
|
const input = screen.getAllByRole('checkbox').at(2);
|
|
|
|
fireEvent.click(input);
|
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-21 02:59:26 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|