fix: unified handling of editor reloading (#32)

Co-authored-by: hugo <hugoms@me.com>
This commit is contained in:
Georg Bauer
2026-03-04 09:28:20 +01:00
committed by GitHub
parent 32b66e1677
commit 08ef72a802
19 changed files with 633 additions and 239 deletions

View File

@@ -86,6 +86,7 @@ describe('ScriptsView', () => {
};
useAppStore.setState({
activeProject: { id: 'project-1', name: 'Test', path: '/tmp/test' } as any,
panelVisible: false,
panelActiveTab: 'tasks',
panelOutputEntries: [],
@@ -437,4 +438,30 @@ describe('ScriptsView', () => {
expect(startTaskMock).not.toHaveBeenCalled();
});
});
it('defers loading until activeProject is set to avoid startup race condition', async () => {
useAppStore.setState({ activeProject: null });
const getMock = (window as any).electronAPI.scripts.get;
const { rerender } = render(<ScriptsView scriptId="script-1" />);
// Give the effect a chance to run
await vi.waitFor(() => {
expect(getMock).not.toHaveBeenCalled();
});
// Now simulate project context becoming available
useAppStore.setState({
activeProject: { id: 'project-1', name: 'Test', path: '/tmp/test' } as any,
});
// Re-render to pick up store change
rerender(<ScriptsView scriptId="script-1" />);
await vi.waitFor(() => {
expect(getMock).toHaveBeenCalledWith('script-1');
const textarea = screen.getByLabelText('Script Content') as HTMLTextAreaElement;
expect(textarea.value).toContain('print("hello")');
});
});
});