Skip to content

Commit 1000036

Browse files
tylergraydevTyler Grayclaude
authored
fix(types): close 6 svelte-check errors — keybindings test Input cast (#214 Group E) (#236)
Part of the #214 cleanup. Brings `npm run check` from 53 -> 47 errors (closes 6). Test-only change, no production behavior. ## What was wrong `keybindingsLibrary.test.ts` mocks `$lib/types` (lines 4-21) to provide a minimal universe with an extra `'Input'` context and a `'newline'` action — that's how the conflict-detection tests have something cross-context to exercise (e.g. `detectConflicts('Global', 'Shift+Enter')` expects an `Input` conflict, where `newline` defaults to `Shift+Enter`). `vi.mock` is runtime-only, so TypeScript still reads the real `KeybindingContext` union from `$lib/types`, which doesn't include `'Input'`. The store methods are typed `(context: KeybindingContext, ...)` so the 6 test sites passing `'Input'` errored. ## Fix Imported `KeybindingContext` and added one cast alias at the top of the file: const Input = 'Input' as unknown as KeybindingContext; Replaced the 6 `'Input'` literals at call sites typed against `KeybindingContext` (setBinding, detectConflicts, Map.has, binding.context comparison). Comment explains why the cast is needed so future readers don't try to delete it. NOT adding `'Input'` to the production `KeybindingContext` union — that would be a phantom value (nothing in real `KEYBINDING_CONTEXTS` or `KEYBINDING_ACTIONS` uses it; it only exists in this test's mock). Same principle as #221's spinnerverbs decision. ## Test plan - [x] `npm run check` — 47 errors (down from 53 on `main`) - [x] `npx vitest run keybindingsLibrary` — 31/31 pass Co-authored-by: Tyler Gray <tylerg@emergentsoftware.net> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 87846ef commit 1000036

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/tests/stores/keybindingsLibrary.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { describe, it, expect, vi, beforeEach } from 'vitest';
22
import { invoke } from '@tauri-apps/api/core';
3+
import type { KeybindingContext } from '$lib/types';
4+
5+
// The vi.mock below extends the real KEYBINDING_CONTEXTS / KEYBINDING_ACTIONS
6+
// universe with an "Input" context + a "newline" action so the conflict-detection
7+
// tests have something cross-context to exercise. TypeScript only sees the real
8+
// $lib/types (mocks are runtime-only), so 'Input' needs an explicit cast where
9+
// it's passed to store methods typed as KeybindingContext.
10+
const Input = 'Input' as unknown as KeybindingContext;
311

412
vi.mock('$lib/types', () => {
513
const contexts = [
@@ -89,8 +97,8 @@ describe('Keybindings Library Store', () => {
8997

9098
it('should create new context block if needed', async () => {
9199
const { keybindingsLibrary } = await import('$lib/stores/keybindingsLibrary.svelte');
92-
keybindingsLibrary.setBinding('Input', 'Ctrl+A', 'newline');
93-
const block = keybindingsLibrary.overrides.find((b) => b.context === 'Input');
100+
keybindingsLibrary.setBinding(Input, 'Ctrl+A', 'newline');
101+
const block = keybindingsLibrary.overrides.find((b) => b.context === Input);
94102
expect(block?.bindings['Ctrl+A']).toBe('newline');
95103
});
96104
});
@@ -134,7 +142,7 @@ describe('Keybindings Library Store', () => {
134142
it('should clear all overrides', async () => {
135143
const { keybindingsLibrary } = await import('$lib/stores/keybindingsLibrary.svelte');
136144
keybindingsLibrary.setBinding('Global', 'Ctrl+K', 'cancel');
137-
keybindingsLibrary.setBinding('Input', 'Ctrl+A', 'newline');
145+
keybindingsLibrary.setBinding(Input, 'Ctrl+A', 'newline');
138146
keybindingsLibrary.resetAll();
139147
expect(keybindingsLibrary.overrides).toEqual([]);
140148
});
@@ -145,7 +153,7 @@ describe('Keybindings Library Store', () => {
145153
const { keybindingsLibrary } = await import('$lib/stores/keybindingsLibrary.svelte');
146154
keybindingsLibrary.setBinding('Global', 'Ctrl+K', 'cancel');
147155
keybindingsLibrary.setBinding('Global', 'Ctrl+S', 'submit');
148-
keybindingsLibrary.setBinding('Input', 'Ctrl+A', 'newline');
156+
keybindingsLibrary.setBinding(Input, 'Ctrl+A', 'newline');
149157
expect(keybindingsLibrary.overrideCount).toBe(3);
150158
});
151159
});
@@ -191,7 +199,7 @@ describe('Keybindings Library Store', () => {
191199

192200
it('should check Global context for non-global contexts', async () => {
193201
const { keybindingsLibrary } = await import('$lib/stores/keybindingsLibrary.svelte');
194-
const conflicts = keybindingsLibrary.detectConflicts('Input', 'Enter');
202+
const conflicts = keybindingsLibrary.detectConflicts(Input, 'Enter');
195203
// Should find conflict with Global's 'submit' action on Enter
196204
const globalConflict = conflicts.find((c) => c.context === 'Global');
197205
expect(globalConflict).toBeDefined();
@@ -201,7 +209,7 @@ describe('Keybindings Library Store', () => {
201209
const { keybindingsLibrary } = await import('$lib/stores/keybindingsLibrary.svelte');
202210
const conflicts = keybindingsLibrary.detectConflicts('Global', 'Shift+Enter');
203211
// Shift+Enter is default for 'newline' in Input context
204-
const inputConflict = conflicts.find((c) => c.context === 'Input');
212+
const inputConflict = conflicts.find((c) => c.context === Input);
205213
expect(inputConflict).toBeDefined();
206214
});
207215
});
@@ -302,7 +310,7 @@ describe('Keybindings Library Store', () => {
302310
keybindingsLibrary.searchQuery = 'newline';
303311
const filtered = keybindingsLibrary.filteredByContext;
304312
expect(filtered.has('Global')).toBe(false);
305-
expect(filtered.has('Input')).toBe(true);
313+
expect(filtered.has(Input)).toBe(true);
306314
});
307315
});
308316
});

0 commit comments

Comments
 (0)