okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-gh-app: GitHub app and Terminal items for 0.2.73cabb9e3f

main
2.2 KiB41 linesraw
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)', () => {
10  assert.equal(f.wheelLeavesBottom(-100), true);
11  assert.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
13  assert.equal(f.followAfterScroll(100, true, 20), false);
14  assert.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', () => {
18  assert.equal(f.followAfterScroll(0, false, 10_000), true);
19  assert.equal(f.followAfterScroll(f.FOLLOW_SLACK, false, 10_000), true);
20  assert.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
25  assert.equal(f.followAfterScroll(80, true, 5_000), true);
26  // a reader who had let go stays away while the answer grows
27  assert.equal(f.followAfterScroll(80, false, 5_000), false);
28  // far away whatever moved it (a scrollbar drag or a jump)
29  assert.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 () => {
33  const chat = await readFile(new URL('../src/screens/Chat.tsx', import.meta.url), 'utf8');
34  assert.doesNotMatch(chat, /clientHeight < 120/);
35  assert.match(chat, /followAfterScroll\(/);
36  assert.match(chat, /onWheel=/);
37  // sending a message still brings the reader to it, even from far up
38  assert.match(chat, /pinned\.current \|\| sent/);
39  // an upward wheel on a transcript that cannot scroll must not switch following off
40  assert.match(chat, /wheelLeavesBottom\(e\.deltaY\) && e\.currentTarget\.scrollTop > 0/);
41});