fix: make the pulse header draggable

This commit is contained in:
lucaronin
2026-04-16 05:41:41 +02:00
parent a448945ed5
commit e8e2004aa8
2 changed files with 43 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ const mockCommits: PulseCommit[] = [
]
const mockInvokeFn = vi.fn()
const dragRegionMouseDown = vi.fn()
vi.mock('@tauri-apps/api/core', () => ({
invoke: (...args: unknown[]) => mockInvokeFn(...args),
}))
@@ -41,10 +42,14 @@ vi.mock('../mock-tauri', () => ({
isTauri: () => false,
mockInvoke: (...args: unknown[]) => mockInvokeFn(...args),
}))
vi.mock('../hooks/useDragRegion', () => ({
useDragRegion: () => ({ onMouseDown: dragRegionMouseDown }),
}))
describe('PulseView', () => {
beforeEach(() => {
vi.clearAllMocks()
dragRegionMouseDown.mockClear()
})
it('shows loading state initially', () => {
@@ -243,4 +248,33 @@ describe('PulseView', () => {
expect(screen.getByText('Pulse')).toBeInTheDocument()
})
})
it('wires the Pulse header into the shared drag-region handler', async () => {
mockInvokeFn.mockResolvedValue([])
render(<PulseView vaultPath="/test/vault" />)
const header = await screen.findByTestId('pulse-header')
fireEvent.mouseDown(header)
expect(dragRegionMouseDown).toHaveBeenCalledTimes(1)
})
it('keeps the expand-sidebar button clickable when the header is draggable', async () => {
mockInvokeFn.mockResolvedValue([])
const onExpandSidebar = vi.fn()
render(
<PulseView
vaultPath="/test/vault"
sidebarCollapsed
onExpandSidebar={onExpandSidebar}
/>,
)
const button = await screen.findByRole('button', { name: 'Expand sidebar' })
fireEvent.click(button)
expect(onExpandSidebar).toHaveBeenCalledTimes(1)
})
})

View File

@@ -1,6 +1,7 @@
import { useState, useEffect, useCallback, useRef, memo, type KeyboardEvent } from 'react'
import { invoke } from '@tauri-apps/api/core'
import { isTauri, mockInvoke } from '../mock-tauri'
import { useDragRegion } from '../hooks/useDragRegion'
import type { PulseCommit, PulseFile } from '../types'
import { relativeDate } from '../utils/noteListHelpers'
import {
@@ -234,8 +235,15 @@ function PulseHeader({
sidebarCollapsed,
onExpandSidebar,
}: Pick<PulseViewProps, 'sidebarCollapsed' | 'onExpandSidebar'>) {
const { onMouseDown } = useDragRegion()
return (
<div className="flex shrink-0 items-center justify-between border-b border-border" style={{ height: 52, padding: '0 16px' }}>
<div
className="flex shrink-0 items-center justify-between border-b border-border"
style={{ height: 52, padding: '0 16px', cursor: 'default' }}
onMouseDown={onMouseDown}
data-testid="pulse-header"
>
<div className="flex items-center" style={{ gap: 8 }}>
{sidebarCollapsed && onExpandSidebar && (
<button