fix: macosx UI cleanup

This commit is contained in:
2026-02-19 22:50:21 +01:00
parent 7e593b587b
commit 0d66939eb7
8 changed files with 333 additions and 176 deletions

View File

@@ -1461,6 +1461,110 @@ describe('IPC Handlers', () => {
expect(shell.openExternal).toHaveBeenCalledWith('https://github.com/rfc1437/bDS');
expect(send).not.toHaveBeenCalled();
});
it('should open preview root URL when action is openInBrowser', async () => {
const { shell } = await import('electron');
const send = vi.fn();
const event = { sender: { send } };
await invokeHandlerWithEvent(event, 'app:triggerMenuAction', 'openInBrowser');
expect(shell.openExternal).toHaveBeenCalledWith('http://localhost:4123/');
expect(send).not.toHaveBeenCalled();
});
it('should open the data folder when action is openDataFolder', async () => {
const { shell } = await import('electron');
const send = vi.fn();
const event = { sender: { send } };
await invokeHandlerWithEvent(event, 'app:triggerMenuAction', 'openDataFolder');
expect(shell.openPath).toHaveBeenCalledWith('/mock/data');
expect(send).not.toHaveBeenCalled();
});
it('should forward previewPost to renderer menu channel', async () => {
const send = vi.fn();
const event = { sender: { send } };
await invokeHandlerWithEvent(event, 'app:triggerMenuAction', 'previewPost');
expect(send).toHaveBeenCalledWith('menu:previewPost');
});
it('should reload sender when action is reload', async () => {
const reload = vi.fn();
const send = vi.fn();
const event = { sender: { reload, send } };
await invokeHandlerWithEvent(event, 'app:triggerMenuAction', 'reload');
expect(reload).toHaveBeenCalled();
expect(send).not.toHaveBeenCalled();
});
it('should force reload sender when action is forceReload', async () => {
const reloadIgnoringCache = vi.fn();
const send = vi.fn();
const event = { sender: { reloadIgnoringCache, send } };
await invokeHandlerWithEvent(event, 'app:triggerMenuAction', 'forceReload');
expect(reloadIgnoringCache).toHaveBeenCalled();
expect(send).not.toHaveBeenCalled();
});
it('should reset zoom level when action is resetZoom', async () => {
const setZoomLevel = vi.fn();
const send = vi.fn();
const event = { sender: { setZoomLevel, send } };
await invokeHandlerWithEvent(event, 'app:triggerMenuAction', 'resetZoom');
expect(setZoomLevel).toHaveBeenCalledWith(0);
expect(send).not.toHaveBeenCalled();
});
it('should zoom in when action is zoomIn', async () => {
const getZoomLevel = vi.fn(() => 0);
const setZoomLevel = vi.fn();
const send = vi.fn();
const event = { sender: { getZoomLevel, setZoomLevel, send } };
await invokeHandlerWithEvent(event, 'app:triggerMenuAction', 'zoomIn');
expect(setZoomLevel).toHaveBeenCalledWith(0.5);
expect(send).not.toHaveBeenCalled();
});
it('should zoom out when action is zoomOut', async () => {
const getZoomLevel = vi.fn(() => 0.5);
const setZoomLevel = vi.fn();
const send = vi.fn();
const event = { sender: { getZoomLevel, setZoomLevel, send } };
await invokeHandlerWithEvent(event, 'app:triggerMenuAction', 'zoomOut');
expect(setZoomLevel).toHaveBeenCalledWith(0);
expect(send).not.toHaveBeenCalled();
});
it('should toggle fullscreen on owner window when action is toggleFullScreen', async () => {
const { BrowserWindow } = await import('electron');
const sender = { send: vi.fn() };
const ownerWindow = {
isFullScreen: vi.fn(() => false),
setFullScreen: vi.fn(),
};
vi.mocked(BrowserWindow.fromWebContents).mockReturnValue(ownerWindow as unknown as ReturnType<typeof BrowserWindow.fromWebContents>);
await invokeHandlerWithEvent({ sender }, 'app:triggerMenuAction', 'toggleFullScreen');
expect(BrowserWindow.fromWebContents).toHaveBeenCalledWith(sender);
expect(ownerWindow.setFullScreen).toHaveBeenCalledWith(true);
});
});
});

View File

@@ -19,7 +19,7 @@ describe('WindowTitleBar', () => {
});
});
it('applies a macOS class to the title bar root for platform-specific spacing', () => {
it('renders title bar on macOS but hides simulated menu buttons', () => {
Object.defineProperty(navigator, 'platform', {
value: 'MacIntel',
configurable: true,
@@ -27,10 +27,14 @@ describe('WindowTitleBar', () => {
render(<WindowTitleBar />);
expect(screen.getByTestId('window-titlebar')).toHaveClass('is-mac');
expect(screen.getByTestId('window-titlebar')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'File' })).toBeNull();
expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull();
expect(screen.getByLabelText('Toggle Sidebar')).toBeInTheDocument();
expect(screen.getByLabelText('Toggle Panel')).toBeInTheDocument();
});
it('sets macOS title bar inset CSS variable from dynamic native metrics', async () => {
it('does not request macOS title bar metrics when simulated title bar is disabled', async () => {
Object.defineProperty(navigator, 'platform', {
value: 'MacIntel',
configurable: true,
@@ -48,8 +52,8 @@ describe('WindowTitleBar', () => {
await Promise.resolve();
});
expect(getTitleBarMetrics).toHaveBeenCalled();
expect(document.documentElement.style.getPropertyValue('--bds-titlebar-macos-left-inset')).toBe('102px');
expect(getTitleBarMetrics).not.toHaveBeenCalled();
expect(document.documentElement.style.getPropertyValue('--bds-titlebar-macos-left-inset')).toBe('');
});
it('renders a right-side sidebar toggle button and toggles store state', () => {

View File

@@ -12,4 +12,31 @@ describe('Help menu documentation entry', () => {
it('maps Open Documentation to a renderer menu event', () => {
expect(APP_MENU_ACTION_EVENT_MAP.openDocumentation).toBe('menu:openDocumentation');
});
it('includes Open in Browser and Open Data Folder actions in File menu', () => {
const fileGroup = APP_MENU_GROUPS.find((group) => group.label === 'File');
expect(fileGroup).toBeDefined();
expect(fileGroup?.items.some((item) => item.action === 'openInBrowser')).toBe(true);
expect(fileGroup?.items.some((item) => item.action === 'openDataFolder')).toBe(true);
});
it('includes Preview Post action in Blog menu', () => {
const blogGroup = APP_MENU_GROUPS.find((group) => group.label === 'Blog');
expect(blogGroup).toBeDefined();
expect(blogGroup?.items.some((item) => item.action === 'previewPost')).toBe(true);
});
it('includes shared View actions for reload, zoom and fullscreen controls', () => {
const viewGroup = APP_MENU_GROUPS.find((group) => group.label === 'View');
expect(viewGroup).toBeDefined();
expect(viewGroup?.items.some((item) => item.action === 'reload')).toBe(true);
expect(viewGroup?.items.some((item) => item.action === 'forceReload')).toBe(true);
expect(viewGroup?.items.some((item) => item.action === 'resetZoom')).toBe(true);
expect(viewGroup?.items.some((item) => item.action === 'zoomIn')).toBe(true);
expect(viewGroup?.items.some((item) => item.action === 'zoomOut')).toBe(true);
expect(viewGroup?.items.some((item) => item.action === 'toggleFullScreen')).toBe(true);
});
});