mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
1. ThemeSettings: change 'auto' radio value to 'system' to match the v5 settingsSchema enum. Storing 'auto' silently wipes all settings on next launch. 2. UpdateBanner: render an 'available' branch so users see a CTA when a new version is detected (the store already had this state, but the banner was silent). Added a test. 3. feed-config: remove the unused resolveFeedUrl / FEEDS exports. feedConfigFor is the actual implementation used by the IPC handler. Updated tests to match. 4. main/index.js: tighten app:open-external regex to https:// only.
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
import { describe, expect, test, beforeEach, vi } from 'vitest';
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { useUpdaterStore } from '@/lib/updater-store';
|
|
import { UpdateBanner } from '@/components/UpdateBanner';
|
|
|
|
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
|
vi.mock('@/lib/ipc', () => ({
|
|
ipc: {
|
|
app: { openExternal: vi.fn() },
|
|
updater: { check: vi.fn(), install: vi.fn() },
|
|
},
|
|
}));
|
|
|
|
describe('UpdateBanner', () => {
|
|
beforeEach(() => {
|
|
useUpdaterStore.setState({ state: 'idle', version: null, percent: 0 });
|
|
});
|
|
|
|
test('renders nothing when state is idle', () => {
|
|
const { container } = render(<UpdateBanner />);
|
|
expect(container.firstChild).toBeNull();
|
|
});
|
|
|
|
test('shows version and restart button when state is ready', () => {
|
|
useUpdaterStore.setState({ state: 'ready', version: '5.0.2' });
|
|
render(<UpdateBanner />);
|
|
expect(screen.getByText(/5\.0\.2/)).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: /restart/i })).toBeInTheDocument();
|
|
});
|
|
|
|
test('shows download progress when state is downloading', () => {
|
|
useUpdaterStore.setState({ state: 'downloading', percent: 42 });
|
|
render(<UpdateBanner />);
|
|
expect(screen.getByText(/42%/)).toBeInTheDocument();
|
|
});
|
|
|
|
test('shows error copy when state is error', () => {
|
|
useUpdaterStore.setState({ state: 'error' });
|
|
render(<UpdateBanner />);
|
|
expect(screen.getByText(/couldn.?t check/i)).toBeInTheDocument();
|
|
});
|
|
|
|
test('shows download CTA when state is available', () => {
|
|
useUpdaterStore.setState({ state: 'available', version: '5.0.2' });
|
|
render(<UpdateBanner />);
|
|
expect(screen.getByText(/5\.0\.2/)).toBeInTheDocument();
|
|
expect(screen.getByText(/download/i)).toBeInTheDocument();
|
|
});
|
|
|
|
test('restart button calls ipc.updater.install', () => {
|
|
useUpdaterStore.setState({ state: 'ready', version: '5.0.2' });
|
|
render(<UpdateBanner />);
|
|
fireEvent.click(screen.getByRole('button', { name: /restart/i }));
|
|
expect(useUpdaterStore.getState().install).toBeDefined();
|
|
});
|
|
});
|