import assert from "node:assert/strict";
import test from "node:test";
import { readFile } from "node:fs/promises";
import { resizeComposerInput } from "./composer-resize.js";

test("composer grows with content until 60 percent of viewport height", () => {
  const input = { scrollHeight: 640, style: {} };

  resizeComposerInput(input, 800);

  assert.equal(input.style.height, "480px");
  assert.equal(input.style.overflowY, "auto");
});

test("composer uses content height below viewport limit", () => {
  const input = { scrollHeight: 180, style: {} };

  resizeComposerInput(input, 800);

  assert.equal(input.style.height, "180px");
  assert.equal(input.style.overflowY, "hidden");
});

test("composer keeps short drafts at the compact visual height", () => {
  const input = {
    style: {},
    get scrollHeight() {
      return this.style.height === "40px" ? 40 : 128;
    }
  };

  resizeComposerInput(input, 800);

  assert.equal(input.style.height, "40px");
  assert.equal(input.style.overflowY, "hidden");
});

test("composer action buttons stay aligned to the bottom while input grows", async () => {
  const css = await readFile(new URL("./conversation.css", import.meta.url), "utf8");

  assert.match(css, /\.composer-row\{[^}]*align-items:flex-end/);
});
