fix(tui): reserve control on macOS

This commit is contained in:
kshitijk4poor 2026-04-19 12:48:02 +05:30 committed by kshitij
parent 88396698ea
commit 1d0b94a1b9
6 changed files with 63 additions and 66 deletions

View file

@ -3,27 +3,23 @@ import { describe, expect, it, vi } from 'vitest'
import { readClipboardText } from '../lib/clipboard.js'
describe('readClipboardText', () => {
it('does nothing off macOS', () => {
it('does nothing off macOS', async () => {
const run = vi.fn()
expect(readClipboardText('linux', run)).toBeNull()
await expect(readClipboardText('linux', run)).resolves.toBeNull()
expect(run).not.toHaveBeenCalled()
})
it('reads text from pbpaste on macOS', () => {
const run = vi.fn().mockReturnValue({ status: 0, stdout: 'hello world\n' })
it('reads text from pbpaste on macOS', async () => {
const run = vi.fn().mockResolvedValue({ stdout: 'hello world\n' })
expect(readClipboardText('darwin', run)).toBe('hello world\n')
expect(run).toHaveBeenCalledWith(
'pbpaste',
[],
expect.objectContaining({ encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })
)
await expect(readClipboardText('darwin', run)).resolves.toBe('hello world\n')
expect(run).toHaveBeenCalledWith('pbpaste', [], expect.objectContaining({ encoding: 'utf8', windowsHide: true }))
})
it('returns null when pbpaste fails', () => {
const run = vi.fn().mockReturnValue({ status: 1, stdout: '' })
it('returns null when pbpaste fails', async () => {
const run = vi.fn().mockRejectedValue(new Error('pbpaste failed'))
expect(readClipboardText('darwin', run)).toBeNull()
await expect(readClipboardText('darwin', run)).resolves.toBeNull()
})
})