35 lines
1.8 KiB
JavaScript
35 lines
1.8 KiB
JavaScript
// Run: docker run --rm -v $PWD:/w -w /w node:22-alpine node --test ide/ui/js/follow.test.mjs
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { nearBottom, isProgrammatic, releasesOnWheel, releasesOnKey, releasesOnTouchMove, pickAnchor, anchorDelta, nextUnread, distanceFromBottom } from './follow.js';
|
|
|
|
test('near the bottom within the tolerance only', () => {
|
|
assert.equal(distanceFromBottom(900, 100, 1100), 100);
|
|
assert.ok(nearBottom(1000, 100, 1100));
|
|
assert.ok(nearBottom(970, 100, 1100));
|
|
assert.ok(!nearBottom(960, 100, 1100));
|
|
});
|
|
test('own scrolls are recognised, the reader\'s are not', () => {
|
|
assert.ok(isProgrammatic(1000, 1000, 10));
|
|
assert.ok(!isProgrammatic(600, 1000, 10));
|
|
assert.ok(!isProgrammatic(1000, 1000, 5000));
|
|
assert.ok(!isProgrammatic(1000, null, 1));
|
|
});
|
|
test('wheel up, keys up, a finger going down release the follow', () => {
|
|
assert.ok(releasesOnWheel(-3)); assert.ok(!releasesOnWheel(3)); assert.ok(!releasesOnWheel(undefined));
|
|
assert.ok(releasesOnKey('PageUp')); assert.ok(releasesOnKey('ArrowUp')); assert.ok(!releasesOnKey('a'));
|
|
assert.ok(releasesOnTouchMove(100, 140)); assert.ok(!releasesOnTouchMove(100, 90));
|
|
});
|
|
test('anchor: first element still visible, and the correction after a change above', () => {
|
|
assert.equal(pickAnchor([{ bottom: -20 }, { bottom: 10 }, { bottom: 50 }]), 1);
|
|
assert.equal(pickAnchor([{ bottom: -5 }]), -1);
|
|
assert.equal(anchorDelta(40, 40.2), 0);
|
|
assert.equal(anchorDelta(40, 90), 50); // it moved down by 50: scroll down by 50
|
|
assert.equal(anchorDelta(40, 10), -30);
|
|
});
|
|
test('unread counts only while away from the end', () => {
|
|
assert.equal(nextUnread(0, true, true), 0);
|
|
assert.equal(nextUnread(2, false, true), 3);
|
|
assert.equal(nextUnread(2, false, false), 2);
|
|
assert.equal(nextUnread(2, true, true), 0);
|
|
});
|