2022-02-10 23:06:24 -06:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2024-01-01 02:43:48 -06:00
|
|
|
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2022-02-10 23:06:24 -06:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2022-02-10 23:06:24 -06:00
|
|
|
import React from 'react';
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2022-02-10 23:06:24 -06:00
|
|
|
import { withTheme } from '../fake_theme';
|
2023-10-23 07:13:17 -05:00
|
|
|
import { render } from '@testing-library/react';
|
2022-02-10 23:06:24 -06:00
|
|
|
import ShortcutTitle, { shortcutToString } from '../../../pgadmin/static/js/components/ShortcutTitle';
|
|
|
|
import * as keyShort from '../../../pgadmin/static/js/keyboard_shortcuts';
|
|
|
|
|
|
|
|
describe('ShortcutTitle', ()=>{
|
|
|
|
const shortcut = {
|
|
|
|
'control': true,
|
|
|
|
'shift': true,
|
|
|
|
'alt': false,
|
|
|
|
'key': {
|
|
|
|
'key_code': 75,
|
|
|
|
'char': 'k',
|
|
|
|
},
|
|
|
|
};
|
2023-10-23 07:13:17 -05:00
|
|
|
it('ShortcutTitle', ()=>{
|
2022-02-10 23:06:24 -06:00
|
|
|
let ThemedShortcutTitle = withTheme(ShortcutTitle);
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
|
|
|
|
let ctrl = render(
|
2022-02-10 23:06:24 -06:00
|
|
|
<ThemedShortcutTitle
|
|
|
|
title="the title"
|
|
|
|
shortcut={shortcut}
|
|
|
|
/>);
|
2023-10-23 07:13:17 -05:00
|
|
|
expect(ctrl.container.textContent).toBe('the titleCtrlShiftK');
|
2022-02-10 23:06:24 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('shortcutToString', ()=>{
|
|
|
|
it('shortcut', ()=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
|
2022-02-10 23:06:24 -06:00
|
|
|
expect(shortcutToString(shortcut)).toBe('Ctrl + Shift + K');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shortcut as array', ()=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
|
2022-02-10 23:06:24 -06:00
|
|
|
expect(shortcutToString(shortcut, null, true)).toEqual(['Ctrl', 'Shift', 'K']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('accesskey', ()=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(window.navigator, 'userAgent', 'get').mockReturnValue('Unknown');
|
2022-02-10 23:06:24 -06:00
|
|
|
expect(shortcutToString(null, 'A')).toEqual('Accesskey + A');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('both null', ()=>{
|
|
|
|
expect(shortcutToString(null, null)).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('mac meta key', ()=>{
|
|
|
|
shortcut.ctrl_is_meta = true;
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(keyShort, 'isMac').mockReturnValue(true);
|
2022-02-10 23:06:24 -06:00
|
|
|
expect(shortcutToString(shortcut)).toBe('Cmd + Shift + K');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|