| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { FOLLOW_SLACK, endPlace } from "./log-follow.ts"; |
| 5 | |
| 6 | const end = (bottom: number) => ({ top: bottom - 1, bottom, width: 600, height: 1 }); |
| 7 | |
| 8 | test("the end above the window's bottom edge is in view", () => { |
| 9 | assert.equal(endPlace(end(700), { height: 800, covered: 12 }), "here"); |
| 10 | assert.equal(endPlace(end(788), { height: 800, covered: 12 }), "here"); |
| 11 | // Scrolled past it, the latest is still on screen. |
| 12 | assert.equal(endPlace(end(-40), { height: 800, covered: 12 }), "here"); |
| 13 | }); |
| 14 | |
| 15 | test("an end one row below the edge is not reached: following stops there", () => { |
| 16 | // Before, anything within 160 px below the window counted, so a log |
| 17 | // could stop with its last lines cut off and no Jump to latest. |
| 18 | assert.equal(endPlace(end(800 - 12 + 20), { height: 800, covered: 12 }), "below"); |
| 19 | assert.equal(endPlace(end(800 + 20), { height: 800, covered: 0 }), "below"); |
| 20 | assert.equal(endPlace(end(800 + FOLLOW_SLACK), { height: 800, covered: 0 }), "here"); |
| 21 | }); |
| 22 | |
| 23 | test("what covers the bottom of the window hides the end: a phone's tab bar", () => { |
| 24 | // 56 px of tab bar and 12 px of room: an end at 760 is under the bar. |
| 25 | assert.equal(endPlace(end(760), { height: 812, covered: 68 }), "below"); |
| 26 | assert.equal(endPlace(end(744), { height: 812, covered: 68 }), "here"); |
| 27 | }); |
| 28 | |
| 29 | test("a folded step has no end to follow", () => { |
| 30 | assert.equal(endPlace(null, { height: 800, covered: 0 }), "folded"); |
| 31 | assert.equal(endPlace({ top: 0, bottom: 0, width: 0, height: 0 }, { height: 800, covered: 0 }), "folded"); |
| 32 | }); |