#!/bin/bash set -euo pipefail source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" run_node_test <<'JS' const clipboard = requireFromRoot('shell/plugins/clipboard/ClipboardHistory.js') assertDeepEqual( clipboard.normalizeEntry('hello'), { type: 'text', text: 'hello' }, 'clipboard normalizes string entries' ) assertDeepEqual( clipboard.normalizeEntry({ kind: 'image', path: '/tmp/a.png' }), { type: 'image', path: '/tmp/a.png', mime: 'image/png' }, 'clipboard normalizes image entries with default mime' ) assertDeepEqual( clipboard.parseHistory(JSON.stringify(['one', '', { type: 'text', text: 'two' }, { type: 'image', path: '/tmp/a.jpg', mime: 'image/jpeg' }])), [ { type: 'text', text: 'one' }, { type: 'text', text: 'two' }, { type: 'image', path: '/tmp/a.jpg', mime: 'image/jpeg' } ], 'clipboard history parser drops invalid entries' ) const history = [ { type: 'text', text: 'old' }, { type: 'text', text: 'new' }, { type: 'image', path: '/tmp/a.png', mime: 'image/png' } ] assertDeepEqual( clipboard.addEntry(history, { type: 'text', text: 'new' }, 100), [ { type: 'text', text: 'new' }, { type: 'text', text: 'old' }, { type: 'image', path: '/tmp/a.png', mime: 'image/png' } ], 'clipboard addEntry moves duplicate text to front' ) assertDeepEqual( clipboard.displayRows(history, 'image', 50).map(row => ({ type: row.entryType, preview: row.previewText, mime: row.mime })), [{ type: 'image', preview: 'Image', mime: 'image/png' }], 'clipboard display rows search image metadata' ) assertDeepEqual( clipboard.displayRows([{ type: 'text', text: 'line one\nline two' }], '', 50)[0].previewText, 'line one line two', 'clipboard display rows collapse text whitespace' ) assertDeepEqual(clipboard.displayRows(history, '', 0), [], 'clipboard display rows supports zero result limit') assertDeepEqual(clipboard.addEntry(history, 'next', 0), [], 'clipboard addEntry supports zero history limit') JS