diff --git a/src/renderer/src/components/editor/useEditorPanelVisibilityContentState.test.tsx b/src/renderer/src/components/editor/useEditorPanelVisibilityContentState.test.tsx index 93ba2482bf0..eacc6c8fec3 100644 --- a/src/renderer/src/components/editor/useEditorPanelVisibilityContentState.test.tsx +++ b/src/renderer/src/components/editor/useEditorPanelVisibilityContentState.test.tsx @@ -1,6 +1,6 @@ // @vitest-environment happy-dom -import { act, useMemo } from 'react' +import { act, useLayoutEffect, useMemo } from 'react' import { createRoot, type Root } from 'react-dom/client' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { OpenFile } from '@/store/slices/editor' @@ -124,6 +124,21 @@ function dispatchExternalChange(file: OpenFile): void { }) } +function ExternalChangeLayoutEmitter({ file }: { file: OpenFile }): null { + useLayoutEffect(() => { + window.dispatchEvent( + new CustomEvent(ORCA_EDITOR_EXTERNAL_FILE_CHANGE_EVENT, { + detail: { + worktreeId: file.worktreeId, + worktreePath: '/repo', + relativePath: file.relativePath + } + }) + ) + }, [file]) + return null +} + function textDiff(modifiedContent: string): DiffContent { return { kind: 'text', @@ -202,6 +217,26 @@ describe('useEditorPanelContentState visibility', () => { ) }) + it('publishes hidden visibility before a watcher event in the same commit', async () => { + const file = makeFile('commit-visibility') + mocks.readRuntimeFileContent.mockResolvedValue({ content: 'old', isBinary: false }) + + await act(async () => root.render()) + await vi.waitFor(() => expect(mocks.readRuntimeFileContent).toHaveBeenCalledOnce()) + + await act(async () => + root.render( + <> + + + + ) + ) + + expect(mocks.readRuntimeFileContent).toHaveBeenCalledOnce() + expect(snapshots.get('main')?.fileContents[file.id]).toBeUndefined() + }) + it('shares one post-change read between visible source and preview panels', async () => { const source = makeFile('source', { filePath: '/repo/readme.md',