Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

61 lines
1.6 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { ShortcutService } from './shortcut.service';
describe('ShortcutService', () => {
it('should instantiate', () => {
const shortcutService = new ShortcutService();
expect(shortcutService).toBeDefined();
});
it('should raise event if triggered', () => {
const shortcutService = new ShortcutService();
let triggered = 0;
shortcutService.listen('ctrl+a', () => { triggered++; });
shortcutService.raise('ctrl+a');
expect(triggered).toEqual(1);
});
it('should not raise event if triggered but unsubscribed', () => {
const shortcutService = new ShortcutService();
let triggered = 0;
shortcutService.listen('ctrl+a', () => { triggered++; })();
shortcutService.raise('ctrl+a');
expect(triggered).toEqual(0);
});
it('should transform shortcut', () => {
const shortcutService = new ShortcutService();
let triggered = 0;
shortcutService.listen('CTRL + A', () => { triggered++; });
shortcutService.raise('ctrl+a');
expect(triggered).toEqual(1);
});
it('should register multiple shortcuts', () => {
const shortcutService = new ShortcutService();
let triggered = 0;
shortcutService.listen('ctrl+a,ctrl+b', () => { triggered++; });
shortcutService.raise('ctrl+a');
shortcutService.raise('ctrl+b');
expect(triggered).toEqual(2);
});
});