import assert from "node:assert/strict";
import { describe, it } from "vitest";
import {
	buildStickyScrollVerticalEscapes,
	isStickyViewportAtBottom,
} from "../viewport-sticky.js";

describe("viewport-sticky", () => {
	it("isStickyViewportAtBottom_matches_maxLinesRendering", () => {
		assert.equal(
			isStickyViewportAtBottom({
				maxLinesRendered: 100,
				terminalRows: 24,
				previousContentLineCount: 100,
			}),
			true,
		);
		assert.equal(
			isStickyViewportAtBottom({
				maxLinesRendered: 100,
				terminalRows: 24,
				previousContentLineCount: 150,
			}),
			false,
		);
	});

	it("buildStickyScrollVerticalEscapes_null_when_content_fits", () => {
		assert.equal(
			buildStickyScrollVerticalEscapes({
				contentLineCount: 10,
				terminalRows: 24,
				previousViewportTop: 0,
				hardwareCursorRow: 0,
			}),
			null,
		);
	});

	it("buildStickyScrollVerticalEscapes_emits_down_moves", () => {
		const r = buildStickyScrollVerticalEscapes({
			contentLineCount: 100,
			terminalRows: 24,
			previousViewportTop: 0,
			hardwareCursorRow: 0,
		});
		assert.ok(r);
		assert.ok(r!.escapes.includes("B"));
		assert.ok(r!.nextPreviousViewportTop > 0);
	});
});
