feat: enhance WelcomeDialog, export dialogs, GitStatusPanel, add CommandPalette, FindReplaceBar, and new converter dialogs

- WelcomeDialog: add quick start, feature showcase, keyboard shortcuts, recent files, version display
- ExportDocxDialog/ExportHtmlDialog/ExportPdfDialog: add header/footer, paper size, margin controls
- GitStatusPanel: full staging/unstaging, discard, commit workflow
- CommandPalette: fuzzy command search with keyboard navigation
- FindReplaceBar: find/replace with regex, case, whole-word options
- New dialogs: BatchMediaConverterDialog, HeaderFooterDialog, PdfEditorDialog, UniversalConverterDialog
- Tests: comprehensive coverage for all new/updated components
This commit is contained in:
2026-06-13 19:34:42 +05:30
parent 6b564a4569
commit f2398e6e1a
52 changed files with 4309 additions and 250 deletions
+81 -32
View File
@@ -1,21 +1,79 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { render, screen } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { WelcomeDialog } from '@/components/modals/WelcomeDialog';
import { useSettingsStore } from '@/stores/settings-store';
import { useAppStore } from '@/stores/app-store';
import { useCommandStore } from '@/stores/command-store';
beforeEach(() => {
localStorage.clear();
useSettingsStore.setState(useSettingsStore.getInitialState());
useAppStore.setState({ modal: { kind: null } } as any);
useCommandStore.setState({ handlers: {}, userBindings: {} } as any);
useCommandStore.getState().register('file.new', vi.fn());
useCommandStore.getState().register('file.open', vi.fn());
useCommandStore.getState().register('file.openFolder', vi.fn());
useCommandStore.getState().register('shortcuts.show', vi.fn());
useCommandStore.getState().register('file.opened', vi.fn());
(window.electronAPI as any) = {
app: {
getVersion: vi.fn().mockResolvedValue({ data: '1.2.3' }),
},
};
});
describe('WelcomeDialog', () => {
beforeEach(() => {
localStorage.clear();
useSettingsStore.setState(useSettingsStore.getInitialState());
useAppStore.setState({ modal: { kind: null } } as any);
});
it('renders a heading and quick-start content', () => {
it('renders a heading with app name', () => {
render(<WelcomeDialog />);
expect(screen.getByRole('heading', { name: /welcome/i })).toBeInTheDocument();
expect(screen.getByText(/open a folder/i)).toBeInTheDocument();
});
it('renders the 3-column layout: Quick Start, Features, Recent Files', () => {
render(<WelcomeDialog />);
expect(screen.getByText(/quick start/i)).toBeInTheDocument();
expect(screen.getByText(/features/i)).toBeInTheDocument();
expect(screen.getAllByText(/recent files/i).length).toBeGreaterThanOrEqual(1);
});
it('renders all 4 quick start items with shortcuts', () => {
render(<WelcomeDialog />);
expect(screen.getByText('New File')).toBeInTheDocument();
expect(screen.getByText('Open File')).toBeInTheDocument();
expect(screen.getByText('Open Folder')).toBeInTheDocument();
expect(screen.getByText('Command Palette')).toBeInTheDocument();
expect(screen.getByText('Ctrl+N')).toBeInTheDocument();
expect(screen.getByText('Ctrl+O')).toBeInTheDocument();
});
it('renders feature cards', () => {
render(<WelcomeDialog />);
expect(screen.getByText('CodeMirror 6')).toBeInTheDocument();
expect(screen.getByText('Live Preview')).toBeInTheDocument();
expect(screen.getByText('PDF Editing')).toBeInTheDocument();
expect(screen.getByText('25+ Themes')).toBeInTheDocument();
});
it('renders keyboard shortcuts section', () => {
render(<WelcomeDialog />);
expect(screen.getByText(/shortcuts/i)).toBeInTheDocument();
expect(screen.getByText('Ctrl+S')).toBeInTheDocument();
expect(screen.getByText('Toggle sidebar')).toBeInTheDocument();
});
it('shows no recent files when none exist', () => {
render(<WelcomeDialog />);
expect(screen.getByText('No recent files')).toBeInTheDocument();
});
it('shows recent files from localStorage', () => {
localStorage.setItem(
'mc-recent-files',
JSON.stringify(['/home/user/doc1.md', '/home/user/doc2.md'])
);
render(<WelcomeDialog />);
expect(screen.getByText('doc1.md')).toBeInTheDocument();
expect(screen.getByText('doc2.md')).toBeInTheDocument();
});
it('closing without the checkbox does not dismiss future welcome dialogs', async () => {
@@ -25,33 +83,24 @@ describe('WelcomeDialog', () => {
expect(useAppStore.getState().modal).toEqual({ kind: null });
});
it('checking "don\'t show again" persists the flag', async () => {
it('checking "don\'t show on startup" persists the flag', async () => {
render(<WelcomeDialog />);
await userEvent.click(screen.getByRole('checkbox', { name: /don't show again/i }));
await userEvent.click(screen.getByRole('checkbox', { name: /don't show/i }));
await userEvent.click(screen.getByRole('button', { name: /get started/i }));
expect(useSettingsStore.getState().welcomeDismissed).toBe(true);
});
// Regression guard: Radix Dialog emits a console.warn when the Content's
// aria-describedby points at an id that isn't in the DOM. The default
// shadcn/ui pattern (custom id="X-desc" on DialogDescription) breaks that
// link because Radix's internal descriptionId is auto-generated via useId.
// The fix is to drop the override and let Radix manage the id itself.
it('does not emit the Radix "Missing Description" warning', async () => {
const warnings: string[] = [];
const spy = vi.spyOn(console, 'warn').mockImplementation((...args) => {
warnings.push(args.map(String).join(' '));
it('quick start buttons dispatch commands and close', async () => {
render(<WelcomeDialog />);
await userEvent.click(screen.getByText('New File'));
expect(useCommandStore.getState().handlers['file.new']).toBeDefined();
expect(useAppStore.getState().modal).toEqual({ kind: null });
});
it('fetches and displays version number', async () => {
render(<WelcomeDialog />);
await waitFor(() => {
expect(screen.getByText(/v1\.2\.3/)).toBeInTheDocument();
});
try {
render(<WelcomeDialog />);
// Effects that fire the warning run in a microtask; one tick is enough.
await Promise.resolve();
const offending = warnings.filter((w) =>
/Missing\s+`?Description`?|aria-describedby=\{undefined\}/.test(w)
);
expect(offending).toEqual([]);
} finally {
spy.mockRestore();
}
});
});