feat: 首页交互的
This commit is contained in:
114
scripts/test-discovery-panel-scroll.mjs
Normal file
114
scripts/test-discovery-panel-scroll.mjs
Normal file
@@ -0,0 +1,114 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
const helperUrl = new URL("../src/utils/discoveryPanelScroll.js", import.meta.url);
|
||||
const chatMainListUrl = new URL("../src/pages/ChatMain/ChatMainList/index.vue", import.meta.url);
|
||||
const helperSource = await readFile(helperUrl, "utf8");
|
||||
const chatMainListSource = await readFile(chatMainListUrl, "utf8");
|
||||
const helperModule = await import(
|
||||
`data:text/javascript;charset=utf-8,${encodeURIComponent(helperSource)}`
|
||||
);
|
||||
|
||||
const {
|
||||
canExpandDiscoveryPanelFromScroll,
|
||||
getDiscoveryPanelCollapseState,
|
||||
} = helperModule;
|
||||
|
||||
assert.equal(
|
||||
getDiscoveryPanelCollapseState({
|
||||
currentScrollTop: 24,
|
||||
lastScrollTop: 0,
|
||||
isCollapsed: false,
|
||||
threshold: 16,
|
||||
}),
|
||||
true,
|
||||
"scrolling up into discovery content should collapse the welcome panel"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
getDiscoveryPanelCollapseState({
|
||||
currentScrollTop: 18,
|
||||
lastScrollTop: 15,
|
||||
isCollapsed: false,
|
||||
threshold: 16,
|
||||
}),
|
||||
true,
|
||||
"slow upward scrolling past the threshold should collapse the welcome panel"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
getDiscoveryPanelCollapseState({
|
||||
currentScrollTop: 40,
|
||||
lastScrollTop: 64,
|
||||
isCollapsed: true,
|
||||
threshold: 16,
|
||||
allowExpand: true,
|
||||
}),
|
||||
false,
|
||||
"scrolling down should reveal the welcome panel"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
getDiscoveryPanelCollapseState({
|
||||
currentScrollTop: 40,
|
||||
lastScrollTop: 64,
|
||||
isCollapsed: true,
|
||||
threshold: 16,
|
||||
allowExpand: false,
|
||||
}),
|
||||
true,
|
||||
"layout-driven reverse scroll after release should not reveal the welcome panel"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
getDiscoveryPanelCollapseState({
|
||||
currentScrollTop: 63,
|
||||
lastScrollTop: 64,
|
||||
isCollapsed: true,
|
||||
threshold: 16,
|
||||
}),
|
||||
true,
|
||||
"small scroll jitter should keep the current panel state"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
chatMainListSource,
|
||||
/@touchmove\.capture="handleDiscoveryPanelTouchMove"/,
|
||||
"discovery shell should capture touchmove before nested scroll-view consumes the gesture"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
canExpandDiscoveryPanelFromScroll({
|
||||
isTouching: false,
|
||||
touchDirection: "",
|
||||
lastDownGestureAt: 1000,
|
||||
now: 1400,
|
||||
gestureRetainMs: 800,
|
||||
}),
|
||||
true,
|
||||
"momentum scroll after a down gesture should still be allowed to reveal the welcome panel"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
canExpandDiscoveryPanelFromScroll({
|
||||
isTouching: false,
|
||||
touchDirection: "",
|
||||
lastDownGestureAt: 1000,
|
||||
now: 1901,
|
||||
gestureRetainMs: 800,
|
||||
}),
|
||||
false,
|
||||
"old reverse scroll should not be treated as an active down gesture"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
canExpandDiscoveryPanelFromScroll({
|
||||
isTouching: true,
|
||||
touchDirection: "up",
|
||||
lastDownGestureAt: 1000,
|
||||
now: 1200,
|
||||
gestureRetainMs: 800,
|
||||
}),
|
||||
false,
|
||||
"an active upward gesture should block reveal even if a down gesture happened earlier"
|
||||
);
|
||||
Reference in New Issue
Block a user