Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

1.7 KB
Raw Blame
import type { Options } from 'react-hotkeys-hook';
import { describe, expect, it, vi } from 'vitest';

import { getRegisteredHotkeyOptions } from './registeredHotkeyOptions';

type EnabledPredicate = Exclude<Options['enabled'], boolean | undefined>;

const event = {} as Parameters<EnabledPredicate>[0];
const hotkey = {} as Parameters<EnabledPredicate>[1];

describe('getRegisteredHotkeyOptions', () => {
  it('keeps a statically disabled hotkey disabled so it does not intercept a shared key', () => {
    const options: Options = { enabled: false, preventDefault: true };
    const isTextSessionActive = vi.fn(() => false);

    expect(getRegisteredHotkeyOptions(options, isTextSessionActive)).toEqual(options);
  });

  it('suppresses an enabled hotkey during an uncommitted canvas text session', () => {
    const result = getRegisteredHotkeyOptions({ enabled: true }, () => true);

    expect(typeof result.enabled).toBe('function');
    expect((result.enabled as EnabledPredicate)(event, hotkey)).toBe(false);
  });

  it('enables a hotkey with no configured enabled option outside a canvas text session', () => {
    const result = getRegisteredHotkeyOptions({}, () => false);

    expect(typeof result.enabled).toBe('function');
    expect((result.enabled as EnabledPredicate)(event, hotkey)).toBe(true);
  });

  it('preserves a configured enabled predicate outside a canvas text session', () => {
    const configuredEnabled = vi.fn(() => false);
    const result = getRegisteredHotkeyOptions({ enabled: configuredEnabled }, () => false);

    expect((result.enabled as EnabledPredicate)(event, hotkey)).toBe(false);
    expect(configuredEnabled).toHaveBeenCalledWith(event, hotkey);
  });
});