feat(renderer): GitStatusPanel sidebar tab + git.refresh event

This commit is contained in:
2026-06-06 08:28:37 +05:30
parent 2d77fa5456
commit 95bbe171b5
7 changed files with 202 additions and 5 deletions
@@ -0,0 +1,73 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { GitStatusPanel } from '@/components/sidebar/GitStatusPanel';
import { useFileStore } from '@/stores/file-store';
vi.mock('@/lib/ipc', () => ({
ipc: {
file: {
gitStatus: vi.fn(),
},
},
}));
import { ipc } from '@/lib/ipc';
describe('GitStatusPanel', () => {
beforeEach(() => {
localStorage.clear();
vi.clearAllMocks();
});
it('shows "No folder open" when rootPath is null', () => {
useFileStore.setState({ rootPath: null } as any);
render(<GitStatusPanel />);
expect(screen.getByText(/no folder open/i)).toBeInTheDocument();
});
it('fetches and shows git status', async () => {
(ipc.file.gitStatus as any).mockResolvedValueOnce({
ok: true,
data: [
{ filePath: '/project/a.md', status: 'modified' },
{ filePath: '/project/b.md', status: 'added' },
],
});
useFileStore.setState({ rootPath: '/project' } as any);
render(<GitStatusPanel />);
expect(await screen.findByText('a.md')).toBeInTheDocument();
expect(await screen.findByText('b.md')).toBeInTheDocument();
});
it('shows "Working tree clean" when no changes', async () => {
(ipc.file.gitStatus as any).mockResolvedValueOnce({ ok: true, data: [] });
useFileStore.setState({ rootPath: '/project' } as any);
render(<GitStatusPanel />);
expect(await screen.findByText(/working tree clean/i)).toBeInTheDocument();
});
it('shows error state when gitStatus fails', async () => {
(ipc.file.gitStatus as any).mockResolvedValueOnce({
ok: false,
error: { code: 'IPC_ERROR', message: 'Not a git repository' },
});
useFileStore.setState({ rootPath: '/project' } as any);
render(<GitStatusPanel />);
// The helper text appears in a <p> element distinct from the error heading
expect(await screen.findByText('Not a git repository, or git not installed.')).toBeInTheDocument();
});
it('opens file on click', async () => {
const openFile = vi.fn();
(ipc.file.gitStatus as any).mockResolvedValueOnce({
ok: true,
data: [{ filePath: '/project/a.md', status: 'modified' }],
});
useFileStore.setState({ rootPath: '/project', openFile } as any);
render(<GitStatusPanel />);
const row = await screen.findByTestId('git-status-row');
await userEvent.click(row);
expect(openFile).toHaveBeenCalledWith('/project/a.md');
});
});
+1
View File
@@ -13,6 +13,7 @@ vi.mock('@/lib/ipc', () => ({
pickFile: vi.fn(),
read: vi.fn(),
write: vi.fn(),
gitStatus: vi.fn().mockResolvedValue({ ok: true, data: [] }),
},
},
}));
+9 -4
View File
@@ -36,6 +36,7 @@ vi.mock('@/lib/ipc', () => ({
pickFolder: vi.fn().mockResolvedValue({ ok: true, data: '/root' }),
pickFile: vi.fn().mockResolvedValue({ ok: true, data: '/root/README.md' }),
onChange: vi.fn(() => () => {}),
gitStatus: vi.fn().mockResolvedValue({ ok: true, data: [] }),
},
menu: {
on: vi.fn(() => () => {}),
@@ -54,6 +55,8 @@ describe('Phase 5 integration', () => {
activeTabId: null,
});
useEditorStore.setState({ buffers: new Map(), activeId: null });
// Also clear the active buffer so breadcrumb symbols won't show stale heading text
useEditorStore.getState().buffers.clear();
useAppStore.setState({
sidebarVisible: true,
previewVisible: true,
@@ -128,12 +131,14 @@ describe('Phase 5 integration', () => {
],
activeTabId: '/a.md',
});
// Use a buffer content that won't conflict with tab title in breadcrumb symbols
useEditorStore.setState({ buffers: new Map([['/a.md', { id: '/a.md', path: '/a.md', content: '# Hello', dirty: false }], ['/b.md', { id: '/b.md', path: '/b.md', content: '# World', dirty: false }]]), activeId: '/a.md' });
render(<AppShell />);
const aTab = screen.getByText('a.md').closest('[role="tab"]')!;
const bTab = screen.getByText('b.md').closest('[role="tab"]')!;
expect(aTab).toHaveAttribute('aria-current', 'page');
// Use role="tab" to find tabs specifically, avoiding breadcrumb "a.md" text
const tabs = screen.getAllByRole('tab');
expect(tabs[0]).toHaveAttribute('aria-current', 'page');
await act(async () => {
fireEvent.click(bTab);
fireEvent.click(tabs[1]);
});
expect(useFileStore.getState().activeTabId).toBe('/b.md');
});
+1
View File
@@ -35,6 +35,7 @@ vi.mock('@/lib/ipc', () => ({
pickFolder: vi.fn().mockResolvedValue({ ok: true, data: '/root' }),
pickFile: vi.fn().mockResolvedValue({ ok: true, data: '/root/README.md' }),
onChange: vi.fn(() => () => {}),
gitStatus: vi.fn().mockResolvedValue({ ok: true, data: [] }),
},
menu: {
on: vi.fn((channel: string, cb: (...args: unknown[]) => void) => {