okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3cabb9e3f
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/follow-scroll.ts' , import . meta. url ), 'utf8' ), { loader :'ts' , format :'esm' }); 7const f = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 8 9test ( 'a wheel notch up while an answer streams lets go at once (#4014)' , () => { 10assert . equal ( f . wheelLeavesBottom ( - 100 ), true ); 11assert . equal ( f . wheelLeavesBottom ( 100 ), false ); 12// the notch lands about 100 px from the bottom, inside the old 120 px band: it must not be pulled back 13assert . equal ( f . followAfterScroll ( 100 , true , 20 ), false ); 14assert . equal ( f . followAfterScroll ( 40 , true , 20 ), false ); 15}); 16 17test ( 'back at the bottom the chat follows again, by wheel, key, drag or the jump button' , () => { 18assert . equal ( f . followAfterScroll ( 0 , false , 10_000 ), true ); 19assert . equal ( f . followAfterScroll ( f . FOLLOW_SLACK , false , 10_000 ), true ); 20assert . equal ( f . followAfterScroll ( f . FOLLOW_SLACK + 1 , false , 10_000 ), false ); 21}); 22 23test ( 'the page growing under a following reader does not make the chat let go' , () => { 24// no input from the reader for a while, a few lines of the answer arrived: keep following 25assert . equal ( f . followAfterScroll ( 80 , true , 5_000 ), true ); 26// a reader who had let go stays away while the answer grows 27assert . equal ( f . followAfterScroll ( 80 , false , 5_000 ), false ); 28// far away whatever moved it (a scrollbar drag or a jump) 29assert . equal ( f . followAfterScroll ( f . PILL_DISTANCE + 1 , true , 5_000 ), false ); 30}); 31 32test ( 'the chat screen uses the reader-driven rule, not the 120 px band' , async () => { 33const chat = await readFile ( new URL ( '../src/screens/Chat.tsx' , import . meta. url ), 'utf8' ); 34assert . doesNotMatch ( chat , / clientHeight < 120 / ); 35assert . match ( chat , / followAfterScroll\( / ); 36assert . match ( chat , / onWheel= / ); 37// sending a message still brings the reader to it, even from far up 38assert . match ( chat , / pinned\.current \|\| sent / ); 39// an upward wheel on a transcript that cannot scroll must not switch following off 40assert . match ( chat , / wheelLeavesBottom\(e\.deltaY\) && e\.currentTarget\.scrollTop > 0 / ); 41});