Files
crawler-plugin/admin-frontend-vue/tests/jd-category-cascader-position.test.ts
T

38 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { clampPanelLeftX } from '../src/pages/jd/jd-category-cascader-position.ts'
/** 类目面板水平钳制(2026-11-16 客户截图「超出视窗了」回归判据):面板锚 left:0 最宽
* 4 栏 ×200px,触发框落在筛选行中部偏右时面板伸出视窗右缘。判据形状统一=「右缘装
* 不下必须左移、左移过头贴左缘、装得下不动」三种写法一格定红;把组件改回无条件锚左
* 即红(JdCategoryCascader.vue 的 reposition 必须经本函数算偏移)。 */
test('视口装得下=不偏移(默认锚左)', () => {
// 宽视口:触发框在 x=300,4 栏 800px,右缘 1100 < 1920-8。
assert.equal(clampPanelLeftX({ hostLeft: 300, panelWidth: 800, viewportWidth: 1920 }), 0)
// 恰好贴齐:右缘正好压在 viewport-margin 上=零偏移(≤0 分支)。
assert.equal(clampPanelLeftX({ hostLeft: 300, panelWidth: 800, viewportWidth: 1108 }), 0)
})
test('右缘越界=整体左移到右缘贴齐(客户截图形状:末栏被窗缘裁掉)', () => {
// 截图形状:触发框 x=250、3 栏 600px、窗宽 830 ⇒ 右缘 850 越界 28px ⇒ 左移 28。
assert.equal(clampPanelLeftX({ hostLeft: 250, panelWidth: 600, viewportWidth: 830 }), -28)
// 宽视口下钻到 4 栈仍越界(触发框靠右):1920 窗、触发框 x=1200、800px 面板。
assert.equal(clampPanelLeftX({ hostLeft: 1200, panelWidth: 800, viewportWidth: 1920 }), -88)
})
test('越界过头不得把面板推出左缘=钳在 margin', () => {
// 窄窗:触发框 x=100、面板 800、窗宽 830 ⇒ 直移要 -78,但那样左缘到 22>8 可行;
// 极端:触发框 x=4、面板 800、窗宽 500 ⇒ 直移 -312 ⇒ 左缘 -308 越左,钳到 margin=8。
assert.equal(clampPanelLeftX({ hostLeft: 4, panelWidth: 800, viewportWidth: 500, margin: 8 }), 4)
// 钳制后面板左缘=margin:偏移=margin-hostLeft。
assert.equal(clampPanelLeftX({ hostLeft: 2, panelWidth: 600, viewportWidth: 400, margin: 8 }), 6)
})
test('窄窗越界:直移后左缘仍够留白就正常左移;不够则钳在 margin(物理极限,不假装能塞下)', () => {
// 窗宽 400、margin 8:面板 380 ⇒ 直移 -138 后左缘 12 ≥ 8 可行;
// 面板 390 ⇒ 直移后左缘 2 < 8 ⇒ 钳到左缘 8(偏移 -142),右侧溢出是物理极限。
assert.equal(clampPanelLeftX({ hostLeft: 150, panelWidth: 380, viewportWidth: 400, margin: 8 }), -138)
assert.equal(clampPanelLeftX({ hostLeft: 150, panelWidth: 390, viewportWidth: 400, margin: 8 }), -142)
})