pgadmin4/web/regression/javascript/components/ShortcutTitle.spec.js

66 lines
1.9 KiB
JavaScript
Raw Normal View History

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2024-01-01 02:43:48 -06:00
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import React from 'react';
import { withTheme } from '../fake_theme';
import { render } from '@testing-library/react';
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',
},
};
it('ShortcutTitle', ()=>{
let ThemedShortcutTitle = withTheme(ShortcutTitle);
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
let ctrl = render(
<ThemedShortcutTitle
title="the title"
shortcut={shortcut}
/>);
expect(ctrl.container.textContent).toBe('the titleCtrlShiftK');
});
describe('shortcutToString', ()=>{
it('shortcut', ()=>{
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
expect(shortcutToString(shortcut)).toBe('Ctrl + Shift + K');
});
it('shortcut as array', ()=>{
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
expect(shortcutToString(shortcut, null, true)).toEqual(['Ctrl', 'Shift', 'K']);
});
it('accesskey', ()=>{
jest.spyOn(window.navigator, 'userAgent', 'get').mockReturnValue('Unknown');
expect(shortcutToString(null, 'A')).toEqual('Accesskey + A');
});
it('both null', ()=>{
expect(shortcutToString(null, null)).toEqual('');
});
it('mac meta key', ()=>{
shortcut.ctrl_is_meta = true;
jest.spyOn(keyShort, 'isMac').mockReturnValue(true);
expect(shortcutToString(shortcut)).toBe('Cmd + Shift + K');
});
});
});