import test from "node:test";
import assert from "node:assert/strict";

import { shouldSubmitComposerKey } from "./composer-keyboard.js";

test("desktop composer submits with Enter and keeps Shift+Enter as a newline", () => {
  assert.equal(shouldSubmitComposerKey({ key: "Enter" }, { compact: false }), true);
  assert.equal(shouldSubmitComposerKey({ key: "Enter", shiftKey: true }, { compact: false }), false);
  assert.equal(shouldSubmitComposerKey({ key: "Enter", ctrlKey: true }, { compact: false }), true);
  assert.equal(shouldSubmitComposerKey({ key: "Enter", metaKey: true }, { compact: false }), true);
});

test("compact mobile composer keeps plain Enter as a newline", () => {
  assert.equal(shouldSubmitComposerKey({ key: "Enter" }, { compact: true }), false);
  assert.equal(shouldSubmitComposerKey({ key: "Enter", shiftKey: true }, { compact: true }), false);
  assert.equal(shouldSubmitComposerKey({ key: "Enter", ctrlKey: true }, { compact: true }), true);
  assert.equal(shouldSubmitComposerKey({ key: "Enter", metaKey: true }, { compact: true }), true);
});

test("composer never submits while an IME composition is active", () => {
  assert.equal(shouldSubmitComposerKey({ key: "Enter", isComposing: true }, { compact: false }), false);
  assert.equal(shouldSubmitComposerKey({ key: "Enter", metaKey: true, nativeEvent: { isComposing: true } }, { compact: false }), false);
  assert.equal(shouldSubmitComposerKey({ key: "Enter", keyCode: 229 }, { compact: false }), false);
});

test("composer ignores non-Enter keyboard shortcuts", () => {
  assert.equal(shouldSubmitComposerKey({ key: "a", ctrlKey: true }), false);
});
