Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

sheet-gesture.test.ts

34 lines1.2 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { sheetOffset, shouldCloseOnRelease } from "./sheet-gesture";
4​
5describe("sheetOffset", () => {
6 it("follows the finger downwards", () => {
7 expect(sheetOffset(0)).toBe(0);
8 expect(sheetOffset(180)).toBe(180);
9 });
10​
11 it("resists upwards, and never moves more than a few pixels", () => {
12 expect(sheetOffset(-30)).toBeLessThan(0);
13 expect(sheetOffset(-30)).toBeGreaterThan(-30);
14 expect(sheetOffset(-1000)).toBeGreaterThanOrEqual(-12);
15 });
16});
17​
18describe("shouldCloseOnRelease", () => {
19 const sheetHeight = 800;
20​
21 it("closes when dragged past a quarter of the sheet", () => {
22 expect(shouldCloseOnRelease({ offset: 200, velocity: 0, sheetHeight })).toBe(true);
23 expect(shouldCloseOnRelease({ offset: 199, velocity: 0, sheetHeight })).toBe(false);
24 });
25​
26 it("closes on a quick downward flick", () => {
27 expect(shouldCloseOnRelease({ offset: 60, velocity: 0.9, sheetHeight })).toBe(true);
28 });
29​
30 it("stays open for a flick upwards or a tiny twitch", () => {
31 expect(shouldCloseOnRelease({ offset: 60, velocity: -0.9, sheetHeight })).toBe(false);
32 expect(shouldCloseOnRelease({ offset: 8, velocity: 2, sheetHeight })).toBe(false);
33 });
34});