feat: composer block fits its content, keeps a height the person dragged to

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 12:23:06 +01:00
1 parent 360d93f589
commit 406f00f0e4
6 files changed
+260 -14

No files matched your search

+17
View File
@@ -132,3 +132,20 @@ test("queue roundtrip keeps a countdown entry (restart turns it into held)", ()
saveQueue(store, "a", q);
assert.deepEqual(loadQueue(store, "a"), q);
});
import { loadUserMin, saveUserMin } from "../mod/ovis-composer/storage.js";
test("userMin: the height the person dragged the composer to; 0 is none", () => {
const store = memStore();
assert.equal(loadUserMin(store), 0);
saveUserMin(store, 300);
assert.equal(loadUserMin(store), 300);
saveUserMin(store, 0);
assert.equal(loadUserMin(store), 0);
store.set("ovis-composer.userMin", "x");
assert.equal(loadUserMin(store), 0);
store.set("ovis-composer.userMin", -5);
assert.equal(loadUserMin(store), 0);
saveUserMin(store, NaN);
assert.equal(store.get("ovis-composer.userMin"), -5);
});
+44
View File
@@ -100,3 +100,47 @@ test("directSendBlocked: who must wait behind the queue", () => {
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [] }), false);
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [{ state: "held" }] }), false);
});
import { blockTargetPx, shouldResize, isManualResize } from "../mod/ovis-composer/view.js";
const fit = (over = {}) => ({ contentHeight: 100, padding: 16, zoom: 1.2, userMin: 0, min: 120, max: 520, ...over });
test("blockTargetPx: the content (plus padding) in layout px, clamped to the layout's range", () => {
// (100 + 16) / 1.2 = 96.7 -> 97, under the minimum of 120
assert.equal(blockTargetPx(fit()), 120);
// (300 + 16) / 1.2 = 263.3 -> 264
assert.equal(blockTargetPx(fit({ contentHeight: 300 })), 264);
assert.equal(blockTargetPx(fit({ contentHeight: 5000 })), 520);
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: 1 })), 316);
});
test("blockTargetPx: the height the person dragged to is kept, and content that needs more wins", () => {
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 300 })), 300);
assert.equal(blockTargetPx(fit({ contentHeight: 500, userMin: 300 })), 430);
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 9999 })), 520);
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 0 })), 120);
});
test("blockTargetPx: a zoom that is not a number counts as 1", () => {
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: 0 })), 316);
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: NaN })), 316);
});
test("shouldResize: only for a difference over 4 px", () => {
assert.equal(shouldResize(150, 154), false);
assert.equal(shouldResize(150, 155), true);
assert.equal(shouldResize(150, 145), true);
assert.equal(shouldResize(150, 146), false);
assert.equal(shouldResize(null, 150), false);
assert.equal(shouldResize(150, undefined), false);
});
test("isManualResize: a height nobody ordered is the person's drag", () => {
assert.equal(isManualResize({ reportedPx: 200, orderedPx: 200 }), false);
assert.equal(isManualResize({ reportedPx: 202, orderedPx: 200 }), false);
assert.equal(isManualResize({ reportedPx: 260, orderedPx: 200 }), true);
assert.equal(isManualResize({ reportedPx: 100, orderedPx: 200 }), true);
// nothing was ordered yet: the first size is the layout's, not a drag
assert.equal(isManualResize({ reportedPx: 150, orderedPx: null }), false);
assert.equal(isManualResize({ reportedPx: NaN, orderedPx: 200 }), false);
});