mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
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:
@@ -15,27 +15,28 @@ vi.mock('@/lib/ipc', () => ({
|
||||
|
||||
import { ipc } from '@/lib/ipc';
|
||||
|
||||
describe('ExportHtmlDialog', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
vi.clearAllMocks();
|
||||
(ipc.app.showSaveDialog as any).mockImplementation(async (args) => ({
|
||||
ok: true,
|
||||
data: args?.defaultPath ?? '/out.html',
|
||||
}));
|
||||
(ipc.file.writeBuffer as any).mockResolvedValue({ ok: true });
|
||||
useSettingsStore.setState(useSettingsStore.getInitialState());
|
||||
useFileStore.setState({
|
||||
activeTabId: '/test.md',
|
||||
openTabs: [{ id: '/test.md', path: '/test.md', title: 'test.md', dirty: false }],
|
||||
} as any);
|
||||
useEditorStore.setState({
|
||||
buffers: new Map([
|
||||
['/test.md', { id: '/test.md', path: '/test.md', content: '# hi', dirty: false }],
|
||||
]),
|
||||
} as any);
|
||||
});
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
vi.clearAllMocks();
|
||||
(window.electronAPI as any) = {};
|
||||
(ipc.app.showSaveDialog as any).mockImplementation(async (args) => ({
|
||||
ok: true,
|
||||
data: args?.defaultPath ?? '/out.html',
|
||||
}));
|
||||
(ipc.file.writeBuffer as any).mockResolvedValue({ ok: true });
|
||||
useSettingsStore.setState(useSettingsStore.getInitialState());
|
||||
useFileStore.setState({
|
||||
activeTabId: '/test.md',
|
||||
openTabs: [{ id: '/test.md', path: '/test.md', title: 'test.md', dirty: false }],
|
||||
} as any);
|
||||
useEditorStore.setState({
|
||||
buffers: new Map([
|
||||
['/test.md', { id: '/test.md', path: '/test.md', content: '# hi', dirty: false }],
|
||||
]),
|
||||
} as any);
|
||||
});
|
||||
|
||||
describe('ExportHtmlDialog', () => {
|
||||
it('renders with default github highlight style', () => {
|
||||
render(<ExportHtmlDialog sourcePath="/test.md" />);
|
||||
expect(screen.getByText(/export to html/i)).toBeInTheDocument();
|
||||
@@ -49,9 +50,41 @@ describe('ExportHtmlDialog', () => {
|
||||
expect(ipc.file.writeBuffer).toHaveBeenCalledTimes(1);
|
||||
const callArg = (ipc.file.writeBuffer as any).mock.calls[0][0];
|
||||
expect(callArg.path).toBe('/test.html');
|
||||
// The buffer is a Uint8Array; in JSDOM cross-realm the prototype check
|
||||
// is unreliable, so verify shape instead.
|
||||
expect(callArg.buffer).toBeDefined();
|
||||
expect(callArg.buffer.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('shows self-contained toggle', () => {
|
||||
render(<ExportHtmlDialog sourcePath="/test.md" />);
|
||||
expect(screen.getByRole('switch', { name: /self-contained/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows TOC toggle and number sections toggle', () => {
|
||||
render(<ExportHtmlDialog sourcePath="/test.md" />);
|
||||
expect(screen.getByRole('switch', { name: /table of contents/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('switch', { name: /number sections/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows TOC depth when TOC is enabled', async () => {
|
||||
render(<ExportHtmlDialog sourcePath="/test.md" />);
|
||||
await userEvent.click(screen.getByRole('switch', { name: /table of contents/i }));
|
||||
expect(screen.getByLabelText(/toc depth/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows custom CSS input', () => {
|
||||
render(<ExportHtmlDialog sourcePath="/test.md" />);
|
||||
expect(screen.getByLabelText(/custom css file path/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('sends options via electronAPI.export.withOptions when available', async () => {
|
||||
const mockWithOptions = vi.fn().mockResolvedValue({ ok: true });
|
||||
(window.electronAPI as any) = {
|
||||
export: { withOptions: mockWithOptions },
|
||||
};
|
||||
render(<ExportHtmlDialog sourcePath="/test.md" />);
|
||||
await userEvent.click(screen.getByRole('button', { name: /^export$/i }));
|
||||
await waitFor(() => expect(mockWithOptions).toHaveBeenCalledWith('html', expect.any(Object)));
|
||||
expect(mockWithOptions.mock.calls[0][1].standalone).toBe(true);
|
||||
expect(mockWithOptions.mock.calls[0][1].selfContained).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user