fix: small reworks on git log sidebar
This commit is contained in:
22
tests/renderer/components/GitSidebar.styles.test.ts
Normal file
22
tests/renderer/components/GitSidebar.styles.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
describe('GitSidebar styles', () => {
|
||||
const cssPath = path.resolve(
|
||||
__dirname,
|
||||
'../../../src/renderer/components/GitSidebar/GitSidebar.css'
|
||||
);
|
||||
|
||||
it('limits version history section to 50% of available sidebar room', () => {
|
||||
const css = fs.readFileSync(cssPath, 'utf8');
|
||||
|
||||
expect(css).toMatch(/\.git-sidebar-history\s*\{[^}]*flex:\s*0\s+0\s+50%;[^}]*max-height:\s*50%;[^}]*\}/s);
|
||||
});
|
||||
|
||||
it('keeps commit list scrollable within the bounded history section', () => {
|
||||
const css = fs.readFileSync(cssPath, 'utf8');
|
||||
|
||||
expect(css).toMatch(/\.git-sidebar-history-list\s*\{[^}]*overflow:\s*auto;[^}]*\}/s);
|
||||
});
|
||||
});
|
||||
@@ -73,6 +73,49 @@ describe('GitSidebar', () => {
|
||||
expect(screen.getByRole('button', { name: /initialize git/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('ignores stale load results when active project becomes available during async load', async () => {
|
||||
useAppStore.setState({ activeProject: null });
|
||||
|
||||
(window as any).electronAPI.git.getRepoState = vi.fn().mockResolvedValue({
|
||||
isRepo: true,
|
||||
rootPath: '/repo/path',
|
||||
currentBranch: 'main',
|
||||
hasRemote: false,
|
||||
});
|
||||
(window as any).electronAPI.git.getStatus = vi.fn().mockResolvedValue({
|
||||
files: [{ path: 'posts/first.md', status: 'modified' }],
|
||||
counts: { untracked: 0, modified: 1, deleted: 0, renamed: 0, staged: 0, total: 1 },
|
||||
});
|
||||
(window as any).electronAPI.git.getHistory = vi.fn().mockResolvedValue([]);
|
||||
|
||||
let checkAvailabilityCall = 0;
|
||||
(window as any).electronAPI.git.checkAvailability = vi.fn().mockImplementation(async () => {
|
||||
checkAvailabilityCall += 1;
|
||||
if (checkAvailabilityCall === 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 25));
|
||||
}
|
||||
return { gitFound: true, version: '2.49.0' };
|
||||
});
|
||||
|
||||
render(<GitSidebar />);
|
||||
|
||||
await act(async () => {
|
||||
useAppStore.setState({
|
||||
activeProject: {
|
||||
id: 'project-1',
|
||||
name: 'Test Project',
|
||||
slug: 'test-project',
|
||||
isActive: true,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
expect(await screen.findByText(/open changes/i)).toBeInTheDocument();
|
||||
expect(screen.queryByText(/no active project selected/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders open changes list when repository exists', async () => {
|
||||
(window as any).electronAPI.git.getRepoState = vi.fn().mockResolvedValue({
|
||||
isRepo: true,
|
||||
|
||||
Reference in New Issue
Block a user