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

@@ -42,6 +42,10 @@ describe('TemplatesView', () => {
beforeEach(() => {
vi.clearAllMocks();
useAppStore.setState({
activeProject: { id: 'project-1', name: 'Test', path: '/tmp/test' } as any,
});
(window as any).electronAPI = {
...(window as any).electronAPI,
templates: {
@@ -208,4 +212,27 @@ describe('TemplatesView', () => {
expect(saveButton).toBeDisabled();
});
});
it('defers loading until activeProject is set to avoid startup race condition', async () => {
useAppStore.setState({ activeProject: null });
const getMock = (window as any).electronAPI.templates.get;
const { rerender } = render(<TemplatesView templateId="template-1" />);
await vi.waitFor(() => {
expect(getMock).not.toHaveBeenCalled();
});
useAppStore.setState({
activeProject: { id: 'project-1', name: 'Test', path: '/tmp/test' } as any,
});
rerender(<TemplatesView templateId="template-1" />);
await vi.waitFor(() => {
expect(getMock).toHaveBeenCalledWith('template-1');
const titleInput = screen.getByLabelText('Title') as HTMLInputElement;
expect(titleInput.value).toBe('Custom Post');
});
});
});