okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4fb068a8c
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { readFile } from 'node:fs/promises' ; 4import { transform } from 'esbuild' ; 5 6const { code} = await transform ( await readFile ( new URL ( '../src/lib/clipboard.ts' , import . meta. url ), 'utf8' ), { loader :'ts' , format :'esm' }); 7const { copyText} = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 8const toasts = () => { const list = []; return { list, toast :( ...a ) => list . push ( a ) }; }; 9 10test ( 'Copy says Copied when the clipboard takes the text (#3731)' , async () => { 11const t = toasts (); let got = '' ; 12assert . equal ( await copyText ( 'hello' , 'Response' , { clipboard :{ writeText :async v => { got = v ; } }, toast :t . toast }), true ); 13assert . equal ( got , 'hello' ); assert . equal ( t . list [ 0 ][ 0 ], 'success' ); 14}); 15test ( 'a refused clipboard falls back to the older copy command' , async () => { 16const t = toasts (); let got = '' ; 17assert . equal ( await copyText ( 'x' , 'Response' , { clipboard :{ writeText :async () => { throw new Error ( 'denied' ); } }, legacyCopy :v => { got = v ; return true ; }, toast :t . toast }), true ); 18assert . equal ( got , 'x' ); assert . equal ( t . list [ 0 ][ 0 ], 'success' ); 19}); 20test ( 'when nothing works the person is told, never left with a silent click' , async () => { 21const t = toasts (); 22assert . equal ( await copyText ( 'x' , 'Response' , { clipboard :null , legacyCopy :() => false , toast :t . toast }), false ); 23assert . equal ( t . list . length , 1 ); assert . equal ( t . list [ 0 ][ 0 ], 'warn' ); assert . match ( t . list [ 0 ][ 2 ], / Ctrl\+C / ); 24}); 25test ( 'the typed message keeps its line breaks (#3720) and the chat uses the shared copy' , async () => { 26const css = await readFile ( new URL ( '../src/styles/app.css' , import . meta. url ), 'utf8' ); 27assert . match ( css , / \.st-bubble__text\s * \{ [ ^ } ] * white-space:\s * pre-wrap / ); 28const chat = await readFile ( new URL ( '../src/screens/Chat.tsx' , import . meta. url ), 'utf8' ); 29assert . doesNotMatch ( chat , / void navigator\.clipboard\.writeText / ); 30}); 31 32test ( 'a copy that worked shows no corner popover: the control shows it; a failed copy still has its toast' , async () => { 33const { readFile} = await import ( 'node:fs/promises' ); 34const hook = await readFile ( new URL ( '../src/lib/use-copy.ts' , import . meta. url ), 'utf8' ); 35assert . match ( hook , / toast: \(tone, title, body\) => \{ if \(tone !== 'success'\) pushToast\(tone, title, body\); \} / ); 36assert . match ( hook , / pushToast\('warn', 'Couldn’t copy'\) / ); 37});