From c33e89556d4896ffae542dc74f69d06ba51b22d4 Mon Sep 17 00:00:00 2001 From: Luca Rossi Date: Fri, 27 Feb 2026 14:41:23 +0100 Subject: [PATCH] fix: use Tauri opener plugin for git commit link in status bar (#117) The commit hash link in the status bar used an tag which doesn't open external URLs in Tauri's webview. Replaced with onClick handler that calls openExternalUrl (Tauri opener plugin in native, window.open in browser). Co-authored-by: Claude Opus 4.6 --- src/components/StatusBar.test.tsx | 22 +++++++++++++++++----- src/components/StatusBar.tsx | 10 +++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/components/StatusBar.test.tsx b/src/components/StatusBar.test.tsx index a3655cbe..4ce455d5 100644 --- a/src/components/StatusBar.test.tsx +++ b/src/components/StatusBar.test.tsx @@ -1,14 +1,25 @@ -import { describe, it, expect, vi } from 'vitest' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { render, screen, fireEvent } from '@testing-library/react' import { StatusBar } from './StatusBar' import type { VaultOption } from './StatusBar' +vi.mock('../utils/url', async () => { + const actual = await vi.importActual('../utils/url') + return { ...actual, openExternalUrl: vi.fn().mockResolvedValue(undefined) } +}) + +const { openExternalUrl } = await import('../utils/url') as typeof import('../utils/url') & { openExternalUrl: ReturnType } + const vaults: VaultOption[] = [ { label: 'Main Vault', path: '/Users/luca/Laputa' }, { label: 'Work Vault', path: '/Users/luca/Work' }, ] describe('StatusBar', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + it('displays note count', () => { render() expect(screen.getByText('9,200 notes')).toBeInTheDocument() @@ -24,7 +35,7 @@ describe('StatusBar', () => { expect(screen.queryByText('main')).not.toBeInTheDocument() }) - it('shows clickable commit hash when commitUrl is available', () => { + it('shows clickable commit hash that opens URL via openExternalUrl', () => { render( { ) const link = screen.getByTestId('status-commit-link') expect(link).toBeInTheDocument() - expect(link.tagName).toBe('A') - expect(link).toHaveAttribute('href', 'https://github.com/owner/repo/commit/abc123') - expect(link).toHaveAttribute('target', '_blank') + expect(link.tagName).toBe('SPAN') expect(screen.getByText('a3f9b1c')).toBeInTheDocument() + + fireEvent.click(link) + expect(openExternalUrl).toHaveBeenCalledWith('https://github.com/owner/repo/commit/abc123') }) it('shows non-clickable commit hash when no commitUrl', () => { diff --git a/src/components/StatusBar.tsx b/src/components/StatusBar.tsx index 3968ee57..9e1d8f20 100644 --- a/src/components/StatusBar.tsx +++ b/src/components/StatusBar.tsx @@ -1,6 +1,7 @@ import { useState, useRef, useEffect } from 'react' import { Package, RefreshCw, Sparkles, FileText, Bell, Settings, FolderOpen, Check, Github, CircleDot, AlertTriangle, Loader2, GitCommitHorizontal } from 'lucide-react' import type { LastCommitInfo, SyncStatus } from '../types' +import { openExternalUrl } from '../utils/url' export interface VaultOption { label: string @@ -157,10 +158,9 @@ export function StatusBar({ noteCount, modifiedCount = 0, vaultPath, vaults, onS {lastCommitInfo && ( lastCommitInfo.commitUrl ? ( - openExternalUrl(lastCommitInfo.commitUrl!)} style={{ ...ICON_STYLE, color: 'var(--muted-foreground)', textDecoration: 'none', cursor: 'pointer', padding: '2px 4px', borderRadius: 3 }} title={`Open commit ${lastCommitInfo.shortHash} on GitHub`} data-testid="status-commit-link" @@ -168,7 +168,7 @@ export function StatusBar({ noteCount, modifiedCount = 0, vaultPath, vaults, onS onMouseLeave={e => { e.currentTarget.style.color = 'var(--muted-foreground)' }} > {lastCommitInfo.shortHash} - + ) : ( {lastCommitInfo.shortHash}