Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/__tests__/shortcuts.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
import AppShortcuts, {
clearShortcuts,
getInitialShortcut,
getShortcuts,
setShortcuts,
shortcutKey,
type ShortcutItem,
} from '../index';
import * as namedExports from '../index';
import NativeAppShortcuts from '../NativeAppShortcuts';

jest.mock('../NativeAppShortcuts', () => ({
Expand Down Expand Up @@ -153,4 +154,28 @@ describe('shortcutKey', () => {
shortcutKey({ id: 'b', title: 'T' })
);
});

// The key is public API and ends up in logs, Map keys and React keys, so a
// stray control character in the separator is a defect callers cannot see.
it('contains no control characters', () => {
const key = shortcutKey({ id: 'a', title: 'T', data: { x: '1' } });

expect([...key].filter((char) => char.charCodeAt(0) < 0x20)).toEqual([]);
expect(key).toBe('a {"x":"1"}');
});
});

describe('default export', () => {
// The README promises every function is reachable both ways, so this is
// derived from the module rather than a hand-kept list that can drift.
it('carries every function the module exports by name', () => {
const functionExports = Object.entries(namedExports)
.filter(
([name, value]) => name !== 'default' && typeof value === 'function'
)
.map(([name]) => name);

expect(functionExports).toContain('shortcutKey');
expect(Object.keys(AppShortcuts).sort()).toEqual(functionExports.sort());
});
});
Binary file modified src/index.tsx
Binary file not shown.
Loading