fix; tab bars didn't update on post creation without restart of app

This commit is contained in:
2026-02-20 22:19:59 +01:00
parent 5a2a6c9edb
commit 7f20a5efa2
2 changed files with 73 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import { TabBar } from '../../../src/renderer/components/TabBar/TabBar';
import { useAppStore } from '../../../src/renderer/store';
@@ -97,4 +97,43 @@ describe('TabBar', () => {
expect(await screen.findByText('Style')).toBeInTheDocument();
});
it('updates post tab title when post title changes in store', async () => {
useAppStore.setState({
tabs: [{ type: 'post', id: 'post-1', isTransient: false }],
activeTabId: 'post-1',
posts: [{
id: 'post-1',
title: '',
slug: 'post-1',
content: '',
excerpt: null,
author: null,
status: 'draft',
publishedAt: null,
scheduledAt: null,
tags: [],
categories: [],
metadata: {},
projectId: 'project-1',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
}],
});
(window as any).electronAPI.posts.get = vi.fn().mockResolvedValue({
id: 'post-1',
title: '',
});
render(<TabBar />);
expect(await screen.findByText('Untitled')).toBeInTheDocument();
act(() => {
useAppStore.getState().updatePost('post-1', { title: 'Updated Title' });
});
expect(await screen.findByText('Updated Title')).toBeInTheDocument();
});
});