import test from "node:test";
import assert from "node:assert/strict";
import {
  NOTIFICATION_SWIPE_DISMISS_DISTANCE,
  NOTIFICATION_SWIPE_MAX_OFFSET,
  notificationSwipeAxis,
  notificationSwipeOffset,
  shouldDismissNotificationSwipe
} from "./notification-swipe.js";

test("a deliberate left swipe dismisses one notification", () => {
  assert.equal(NOTIFICATION_SWIPE_DISMISS_DISTANCE, 72);
  assert.equal(shouldDismissNotificationSwipe(-72, 18), true);
  assert.equal(shouldDismissNotificationSwipe(-120, 60), true);
});

test("short, rightward, vertical, and near-diagonal gestures do not dismiss a notification", () => {
  assert.equal(shouldDismissNotificationSwipe(-71, 0), false);
  assert.equal(shouldDismissNotificationSwipe(120, 0), false);
  assert.equal(shouldDismissNotificationSwipe(-100, 120), false);
  assert.equal(shouldDismissNotificationSwipe(-120, 119), false);
});

test("gesture direction waits for movement slop and preserves vertical scrolling", () => {
  assert.equal(notificationSwipeAxis(-4, 3), null);
  assert.equal(notificationSwipeAxis(-12, 4), "horizontal");
  assert.equal(notificationSwipeAxis(-12, 10), "vertical");
  assert.equal(notificationSwipeAxis(-12, 20), "vertical");
});

test("only a locked horizontal gesture moves the row to the left", () => {
  assert.equal(NOTIFICATION_SWIPE_MAX_OFFSET, 64);
  assert.equal(notificationSwipeOffset(-50, "horizontal", 320), -50);
  assert.equal(notificationSwipeOffset(-500, "horizontal", 320), -64);
  assert.equal(notificationSwipeOffset(-500, "horizontal", 80), -64);
  assert.equal(notificationSwipeOffset(50, "horizontal", 320), 0);
  assert.equal(notificationSwipeOffset(-50, "vertical", 320), 0);
});
