import test from "node:test";
import assert from "node:assert/strict";
import { galleryIndexAfterSwipe, isGallerySwipe, moveGalleryIndex } from "./image-gallery.js";

test("gallery navigation stays inside the message attachment list", () => {
  assert.equal(moveGalleryIndex(0, -1, 3), 0);
  assert.equal(moveGalleryIndex(0, 1, 3), 1);
  assert.equal(moveGalleryIndex(2, 1, 3), 2);
});

test("gallery swipe changes images only after a deliberate horizontal gesture", () => {
  assert.equal(isGallerySwipe(140, 40), true);
  assert.equal(isGallerySwipe(140, 100), false);
  assert.equal(galleryIndexAfterSwipe(1, 140, 40, 3), 2);
  assert.equal(galleryIndexAfterSwipe(1, 140, 100, 3), 1);
  assert.equal(galleryIndexAfterSwipe(1, 100, 170, 3), 0);
});
