42 lines
2.0 KiB
TypeScript
42 lines
2.0 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { calculateResizedWidth } from './ResizeHandle';
|
|
|
|
test('左侧栏鼠标严密绝对跟随与夹紧测试 (Left Rail Exact Pointer Following & Clamping)', () => {
|
|
const startWidth = 280;
|
|
const startX = 280;
|
|
const min = 200;
|
|
const max = 420;
|
|
|
|
// 1. 鼠标向右平滑移动 +40px,宽度必须精准等于 320px (与鼠标位置 1:1 绝对重合)
|
|
assert.equal(calculateResizedWidth(startWidth, startX, 320, 'left', min, max), 320);
|
|
|
|
// 2. 鼠标向左平滑移动 -30px,宽度必须精准等于 250px
|
|
assert.equal(calculateResizedWidth(startWidth, startX, 250, 'left', min, max), 250);
|
|
|
|
// 3. 鼠标大幅向右拖动超过最大界限 (x=600px),宽度被安全夹紧在 420px
|
|
assert.equal(calculateResizedWidth(startWidth, startX, 600, 'left', min, max), 420);
|
|
|
|
// 4. 鼠标大幅向左拖动低于最小界限 (x=100px),宽度被安全夹紧在 200px
|
|
assert.equal(calculateResizedWidth(startWidth, startX, 100, 'left', min, max), 200);
|
|
});
|
|
|
|
test('右侧栏鼠标严密绝对跟随与反向位移测试 (Right Rail Exact Pointer Following & Inverted Delta)', () => {
|
|
const startWidth = 500;
|
|
const startX = 940; // 假设 1440px 屏幕,右侧栏初始位置为 1440 - 500 = 940px
|
|
const min = 360;
|
|
const max = 850;
|
|
|
|
// 1. 鼠标向左拖动 100px (startX=940 -> currentX=840),右侧栏展开加宽至 600px (手柄仍严格在 x=840 鼠标下)
|
|
assert.equal(calculateResizedWidth(startWidth, startX, 840, 'right', min, max), 600);
|
|
|
|
// 2. 鼠标向右拖动 100px (startX=940 -> currentX=1040),右侧栏收窄缩减至 400px (手柄仍严格在 x=1040 鼠标下)
|
|
assert.equal(calculateResizedWidth(startWidth, startX, 1040, 'right', min, max), 400);
|
|
|
|
// 3. 边界溢出保护:过度向左扩展夹紧至 850px
|
|
assert.equal(calculateResizedWidth(startWidth, startX, 0, 'right', min, max), 850);
|
|
|
|
// 4. 边界溢出保护:过度向右收缩夹紧至 360px
|
|
assert.equal(calculateResizedWidth(startWidth, startX, 1400, 'right', min, max), 360);
|
|
});
|