64 lines
2.6 KiB
TypeScript
64 lines
2.6 KiB
TypeScript
/* Minimal preload bridge for the renderer tests: real git rows over a flat file
|
|
* list. Without `window.helder` the store falls back to the mock project, so a
|
|
* test that needs its own git payload has to install one of these first. */
|
|
import { DEFAULT_CONFIG } from '../src/renderer/src/types'
|
|
import type { GitStatus } from '../src/renderer/src/types'
|
|
|
|
export interface StubRow {
|
|
path: string
|
|
status: GitStatus
|
|
staged: boolean
|
|
original: string
|
|
updated: string
|
|
}
|
|
|
|
/** Install the bridge. `files` is the working tree: one entry per path. */
|
|
export function installBridge(rows: StubRow[], files: Record<string, string>): void {
|
|
const noop = (): void => {}
|
|
const off = (): (() => void) => noop
|
|
const children = Object.keys(files).map((path) => ({ name: path, type: 'file' as const, path }))
|
|
;(window as unknown as { helder: unknown }).helder = {
|
|
platform: 'darwin',
|
|
clipboard: { writeText: noop, readText: () => '' },
|
|
project: {
|
|
current: async () => ({ root: '/repo', name: 'repo' }),
|
|
open: async () => ({ root: '/repo', name: 'repo' }),
|
|
openPath: async () => ({ root: '/repo', name: 'repo' }),
|
|
recent: async () => [],
|
|
},
|
|
fs: {
|
|
tree: async () => ({ name: 'repo', type: 'dir', path: '', children }),
|
|
readDir: async () => [],
|
|
files: async () => files,
|
|
read: async (path: string) => files[path] ?? '',
|
|
imageDataUrl: async () => '',
|
|
write: async () => {},
|
|
delete: async () => {},
|
|
create: async () => {},
|
|
mkdir: async () => {},
|
|
},
|
|
shell: { reveal: noop },
|
|
notes: { read: async () => '', write: async () => {} },
|
|
git: {
|
|
load: async () => ({ branch: 'main', changes: rows }),
|
|
stage: async () => {}, unstage: async () => {}, commit: async () => {},
|
|
push: async () => ({ ok: true, message: '' }), discard: async () => {},
|
|
},
|
|
pty: { available: async () => false, create: async () => 1, write: noop, resize: noop, kill: noop, onData: off, onExit: off },
|
|
config: { get: async () => DEFAULT_CONFIG, theme: async () => '' },
|
|
recent: { get: async () => [], set: async () => {} },
|
|
search: { content: async () => [], files: async () => [] },
|
|
symbols: { names: async () => [], lookup: async () => ({ name: '', defs: [], refs: [], refCount: 0 }) },
|
|
dialog: { unsavedClose: async () => 'cancel' },
|
|
log: { write: noop, path: async () => null, open: async () => {}, reveal: async () => {} },
|
|
onFullscreen: off,
|
|
onProjectChanged: off,
|
|
onConfigChanged: off,
|
|
onRefresh: off,
|
|
}
|
|
}
|
|
|
|
export function removeBridge(): void {
|
|
delete (window as unknown as { helder?: unknown }).helder
|
|
}
|