Files
marco/tests/unit/utils/sheet-detents-test.js
raucao 64d26951d4
CI / Lint (pull_request) Successful in 56s
CI / Test (pull_request) Successful in 1m27s
Release Drafter / Update release notes draft (pull_request) Successful in 16s
Extend the expanded mobile sheet up to the search field
The tallest detent now fills the viewport down from the top of the search
field, so a fully expanded sheet covers the search field and avatar while
leaving that little strip visible above.

- DETENT_FRACTIONS.expanded is now the whole sheet; the sheet height is the
  viewport minus a top gap (replacing the 0.92 fraction cap).
- The modifier measures that gap from the search field, relative to the sheet's
  container (the viewport top is not the app's top), falling back to 8px.
- Update the sheet-detents unit test and read the real --sheet-height in the
  stacked-sheets acceptance test.
2026-11-30 18:08:02 +04:00

144 lines
3.9 KiB
JavaScript

import { module, test } from 'qunit';
import {
computeDetentLayout,
computeSheetHeight,
findDetent,
nearestDetentIndex,
resolveSnap,
} from 'marco/utils/sheet-detents';
const VIEWPORT = 800;
// No top gap, so the sheet fills the viewport.
const SHEET = computeSheetHeight(VIEWPORT); // 800
// expanded: 800 - 800 = 0, medium: 800 - 440 = 360, collapsed: 800 - 240 = 560
const LAYOUT = computeDetentLayout({
viewportHeight: VIEWPORT,
sheetHeight: SHEET,
});
module('Unit | Utility | sheet-detents', function () {
test('computeSheetHeight fills the viewport minus the top gap', function (assert) {
assert.strictEqual(computeSheetHeight(800), 800);
assert.strictEqual(computeSheetHeight(800, 8), 792);
assert.strictEqual(computeSheetHeight(100, 200), 0, 'never negative');
});
test('computeDetentLayout produces ascending offsets with expanded first', function (assert) {
assert.deepEqual(
LAYOUT.map((detent) => detent.name),
['expanded', 'medium', 'collapsed'],
'detents are ordered by ascending offset'
);
assert.strictEqual(findDetent(LAYOUT, 'expanded').offset, 0);
assert.strictEqual(findDetent(LAYOUT, 'medium').offset, 360);
assert.strictEqual(findDetent(LAYOUT, 'collapsed').offset, 560);
});
test('computeDetentLayout keeps a single clamped detent for short sheets', function (assert) {
const layout = computeDetentLayout({
viewportHeight: VIEWPORT,
sheetHeight: 100,
});
assert.strictEqual(layout.length, 1, 'only one reachable position remains');
assert.strictEqual(
layout[0].offset,
0,
'the remaining detent is fully open'
);
assert.strictEqual(layout[0].visibleHeight, 100);
});
test('nearestDetentIndex picks the closest offset', function (assert) {
assert.strictEqual(nearestDetentIndex(LAYOUT, 10), 0, 'near expanded');
assert.strictEqual(nearestDetentIndex(LAYOUT, 300), 1, 'near medium');
assert.strictEqual(nearestDetentIndex(LAYOUT, 480), 2, 'near collapsed');
});
test('resolveSnap snaps to the nearest detent without velocity', function (assert) {
assert.strictEqual(
resolveSnap({
offset: 100,
velocity: 0,
layout: LAYOUT,
sheetHeight: SHEET,
}),
'expanded'
);
assert.strictEqual(
resolveSnap({
offset: 290,
velocity: 0,
layout: LAYOUT,
sheetHeight: SHEET,
}),
'medium'
);
assert.strictEqual(
resolveSnap({
offset: 490,
velocity: 0,
layout: LAYOUT,
sheetHeight: SHEET,
}),
'collapsed'
);
});
test('resolveSnap flings one detent in the gesture direction', function (assert) {
assert.strictEqual(
resolveSnap({
offset: 300,
velocity: -0.8,
layout: LAYOUT,
sheetHeight: SHEET,
}),
'expanded',
'a fast upward flick moves to the next detent up'
);
assert.strictEqual(
resolveSnap({
offset: 290,
velocity: 0.8,
layout: LAYOUT,
sheetHeight: SHEET,
}),
'collapsed',
'a fast downward flick moves to the next detent down'
);
});
test('resolveSnap dismisses past the collapsed threshold', function (assert) {
assert.strictEqual(
resolveSnap({
offset: 700,
velocity: 0,
layout: LAYOUT,
sheetHeight: SHEET,
}),
'dismissed',
'dragging well past collapsed dismisses'
);
assert.strictEqual(
resolveSnap({
offset: 570,
velocity: 0.6,
layout: LAYOUT,
sheetHeight: SHEET,
}),
'dismissed',
'a fast downward flick past collapsed dismisses'
);
assert.strictEqual(
resolveSnap({
offset: 500,
velocity: 0,
layout: LAYOUT,
sheetHeight: SHEET,
}),
'collapsed',
'the same offset without velocity just collapses'
);
});
});