dsh-desktop-statusbar 3.0.5 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +614 -179
- package/lib/index.js +456 -93
- package/package.json +1 -1
- package/tests/helpers/client-harness.js +86 -0
- package/tests/verify-balance.js +55 -1
- package/tests/verify-context.js +23 -3
- package/tests/verify-copy.js +6 -2
- package/tests/verify-fixes.js +30 -0
- package/tests/verify-generic-relay.js +405 -6
- package/tests/verify-magpie-quota.mjs +24 -1
- package/tests/verify-modelrow-scroll.js +669 -0
- package/tests/verify-provider-fees.js +131 -1
- package/tests/verify-relay-settings.js +1166 -115
- package/tests/verify-render.js +7 -0
- package/tests/verify.js +23 -8
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 平台「适用模型」可输入筛选下拉回归测试(fix-3.0.6)。
|
|
3
|
+
* 用法:node tests/verify-modelrow-scroll.js
|
|
4
|
+
*
|
|
5
|
+
* 口径(用户最新要求):
|
|
6
|
+
* A. 滚动语义(锁定项,不得退化):
|
|
7
|
+
* ① .dsb-modelrow-menu 内部 wheel/touchmove/scroll 不关闭菜单,也不阻止自身滚动;
|
|
8
|
+
* ② 输入框上的 wheel 改滚候选菜单 scrollTop 并 preventDefault/stopPropagation;
|
|
9
|
+
* ③ 只有落在设置区(.dsb-settings 内部或其真实滚动祖先)的 scroll/wheel/touchmove 才关闭;
|
|
10
|
+
* 背景对话区自身程序滚动/滚轮不关闭;关闭后 input 仍聚焦时 click 可重开;
|
|
11
|
+
* ④ 菜单内 wheel/touchmove stopPropagation,不向 document 冒泡。
|
|
12
|
+
* B. 可输入筛选:原生 text input + 可访问名;清空输入恢复全部候选;
|
|
13
|
+
* 按显示名或原始名大小写无关包含匹配;无匹配时不渲染 listbox,aria-expanded=false。
|
|
14
|
+
* C. 键盘不参与选择:ArrowUp/Down 不改变选择、Enter 不选中 option、无灰色键盘活动项;
|
|
15
|
+
* 仅保留 Escape 关闭并恢复已选显示;鼠标点击仍可选。
|
|
16
|
+
* D. 布局:菜单 portal 到 body + fixed 坐标;最多 3 项完整高度;始终锚定输入框下方;
|
|
17
|
+
* 空间不足时按下方实际可用空间限高,右侧越界夹紧,菜单内部滚动。
|
|
18
|
+
*
|
|
19
|
+
* 做法:用最小 React 替身加载真实 client.js,按真实 hook 顺序跑 SettingsSection;
|
|
20
|
+
* 在 effect 真正挂载后模拟 window 捕获事件与菜单节点事件。
|
|
21
|
+
*/
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const path = require('path');
|
|
24
|
+
const assert = require('assert');
|
|
25
|
+
const { findAll, hasClass, textOf, makeFakeDocument, runPlugin } = require('./helpers/client-harness');
|
|
26
|
+
|
|
27
|
+
const PLUGIN = path.join(__dirname, '..', 'lib', 'client.js');
|
|
28
|
+
const clientSource = fs.readFileSync(PLUGIN, 'utf8');
|
|
29
|
+
|
|
30
|
+
/* 气泡尺寸/滚动/portal 锁定项,防止改动时丢失 */
|
|
31
|
+
assert.ok(clientSource.includes('max-height:calc(3 * 30px + 8px);overflow-y:auto'),
|
|
32
|
+
'.dsb-modelrow-menu 仍应保留 max-height 3 行 + overflow-y:auto');
|
|
33
|
+
assert.ok(clientSource.includes('overscroll-behavior:contain'),
|
|
34
|
+
'.dsb-modelrow-menu 仍应保留 overscroll-behavior:contain');
|
|
35
|
+
assert.ok(clientSource.includes('createPortal(menuNode, portalTarget)'),
|
|
36
|
+
'菜单应 portal 到 body(portalTarget)');
|
|
37
|
+
assert.ok(clientSource.includes('z-index:1100;max-width:100%;max-height:calc(3 * 30px + 8px)'),
|
|
38
|
+
'.dsb-modelrow-menu 应提升到既有 body 浮层 z-index:1100');
|
|
39
|
+
assert.ok(clientSource.includes('position: "fixed"'),
|
|
40
|
+
'菜单应使用 fixed 定位(脱离设置卡片 overflow 裁切)');
|
|
41
|
+
/* 撤销灰色键盘活动项:源码里不应再有该 class */
|
|
42
|
+
assert.ok(!clientSource.includes('dsb-select-item-active'),
|
|
43
|
+
'灰色键盘活动项(dsb-select-item-active)应已撤销');
|
|
44
|
+
/* 模型输入框复用 dsb-select-btn,窄断言其显示文本光标 */
|
|
45
|
+
assert.ok(clientSource.includes('.dsb-modelrow-select .dsb-select-btn{cursor:text}'),
|
|
46
|
+
'.dsb-modelrow-select .dsb-select-btn 应设 cursor:text(模型输入框显示文本光标)');
|
|
47
|
+
|
|
48
|
+
const marker = '\t\texports.apply = apply;';
|
|
49
|
+
assert.ok(clientSource.includes(marker), 'exports.apply marker not found');
|
|
50
|
+
const code = clientSource.replace(marker,
|
|
51
|
+
'\t\texports.__test = { zh: zh, SettingsSection: SettingsSection, setConfig: setConfig };\n' + marker);
|
|
52
|
+
|
|
53
|
+
const price = (a) => ({ tiered: true, currency: 'CNY', peak: { input: a, cacheRead: 0.04, cacheWrite: 0, output: a * 4 }, offPeak: { input: a / 2, cacheRead: 0.02, cacheWrite: 0, output: a * 2 } });
|
|
54
|
+
const CONFIG = {
|
|
55
|
+
models: {
|
|
56
|
+
'deepseek-flash': price(2),
|
|
57
|
+
/* 用于筛选:只有 claude 含 c(原始名与显示名都含);gpt / gemini / qwen 不含 c */
|
|
58
|
+
'claude-opus-test': price(1),
|
|
59
|
+
'gpt-4o-mini-test': price(1),
|
|
60
|
+
'gemini-test': price(1),
|
|
61
|
+
'qwen-max-test': price(1)
|
|
62
|
+
},
|
|
63
|
+
modelOrder: ['deepseek-flash', 'claude-opus-test', 'gpt-4o-mini-test', 'gemini-test', 'qwen-max-test'],
|
|
64
|
+
priceConfigured: true,
|
|
65
|
+
relayPlatforms: {
|
|
66
|
+
'relay-a': {
|
|
67
|
+
endpoint: '', tokenHeader: 'authorization', userIdHeader: '', balancePath: '',
|
|
68
|
+
currency: '', balanceDivisor: null,
|
|
69
|
+
models: [{ model: 'deepseek-flash', feeMultiplier: 1 }]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/* 当前 harness 的 DOM 关系替身:focusEvent 在构造锚点时读取(各测试块顺序使用,不交叉)。 */
|
|
75
|
+
let ACTIVE_DOM = null;
|
|
76
|
+
|
|
77
|
+
/* ------------------------------------------------------------------ 最小替身 */
|
|
78
|
+
function makeHarness(options) {
|
|
79
|
+
options = options || {};
|
|
80
|
+
const store = new Map();
|
|
81
|
+
const windowListeners = [];
|
|
82
|
+
let menuSeq = 0;
|
|
83
|
+
let menuRefSlot = null;
|
|
84
|
+
|
|
85
|
+
const fakeWindow = {
|
|
86
|
+
localStorage: {
|
|
87
|
+
getItem: (key) => (store.has(key) ? store.get(key) : null),
|
|
88
|
+
setItem: (key, value) => { store.set(key, value); },
|
|
89
|
+
removeItem: (key) => { store.delete(key); }
|
|
90
|
+
},
|
|
91
|
+
innerWidth: 1200, innerHeight: 900,
|
|
92
|
+
setInterval: () => 0, clearInterval: () => {}, setTimeout: () => 0, clearTimeout: () => {},
|
|
93
|
+
requestAnimationFrame: (fn) => { fn(); return 0; },
|
|
94
|
+
cancelAnimationFrame: () => {},
|
|
95
|
+
addEventListener: (type, fn, options) => {
|
|
96
|
+
const capture = options === true || (options !== null && options !== undefined && options.capture === true);
|
|
97
|
+
windowListeners.push({ type: type, fn: fn, capture: capture });
|
|
98
|
+
},
|
|
99
|
+
removeEventListener: (type, fn, options) => {
|
|
100
|
+
const capture = options === true || (options !== null && options !== undefined && options.capture === true);
|
|
101
|
+
for (let at = windowListeners.length - 1; at >= 0; at -= 1) {
|
|
102
|
+
if (windowListeners[at].type === type && windowListeners[at].fn === fn && windowListeners[at].capture === capture) {
|
|
103
|
+
windowListeners.splice(at, 1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
fetch: () => Promise.resolve({ json: () => Promise.resolve({ ok: false, reason: 'test' }) })
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const { document: fakeDocument, docClicks } = makeFakeDocument();
|
|
111
|
+
const portalCalls = [];
|
|
112
|
+
const reactDom = options.portal === true ? {
|
|
113
|
+
createPortal: (node, target) => {
|
|
114
|
+
portalCalls.push({ node: node, target: target });
|
|
115
|
+
return { type: '__portal', props: { target: target }, children: [node] };
|
|
116
|
+
}
|
|
117
|
+
} : null;
|
|
118
|
+
|
|
119
|
+
/* 菜单 DOM 替身:effect 会在打开菜单的那一帧把它挂到 platformModelMenuRef 上 */
|
|
120
|
+
const makeMenuNode = () => {
|
|
121
|
+
menuSeq += 1;
|
|
122
|
+
const listeners = [];
|
|
123
|
+
return {
|
|
124
|
+
__menuId: menuSeq,
|
|
125
|
+
style: {},
|
|
126
|
+
scrollTop: 0,
|
|
127
|
+
scrollHeight: 200,
|
|
128
|
+
clientHeight: 100,
|
|
129
|
+
listeners: listeners,
|
|
130
|
+
contains: (target) => target !== null && target !== undefined && target.__insideModelMenu === true,
|
|
131
|
+
addEventListener: (type, fn) => { listeners.push({ type: type, fn: fn }); },
|
|
132
|
+
removeEventListener: (type, fn) => {
|
|
133
|
+
for (let at = listeners.length - 1; at >= 0; at -= 1) {
|
|
134
|
+
if (listeners[at].type === type && listeners[at].fn === fn) listeners.splice(at, 1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/* React 替身:hook 下标与真实渲染顺序一致;effect 按依赖变化在渲染后执行,并保留 cleanup */
|
|
141
|
+
const values = [];
|
|
142
|
+
const refs = [];
|
|
143
|
+
const effects = [];
|
|
144
|
+
let hookIndex = 0;
|
|
145
|
+
let layoutQueue = [];
|
|
146
|
+
let effectQueue = [];
|
|
147
|
+
|
|
148
|
+
const reactStub = {
|
|
149
|
+
createElement: (type, props, ...children) => {
|
|
150
|
+
const node = {
|
|
151
|
+
type: type,
|
|
152
|
+
props: props === null || props === undefined ? {} : props,
|
|
153
|
+
children: children.flat(Infinity).filter((one) => one !== null && one !== undefined && one !== false)
|
|
154
|
+
};
|
|
155
|
+
const ref = node.props.ref;
|
|
156
|
+
if (ref !== null && ref !== undefined && typeof ref === 'object'
|
|
157
|
+
&& typeof node.props.className === 'string' && node.props.className.split(' ').indexOf('dsb-modelrow-menu') !== -1) {
|
|
158
|
+
menuRefSlot = ref;
|
|
159
|
+
ref.current = makeMenuNode();
|
|
160
|
+
}
|
|
161
|
+
return node;
|
|
162
|
+
},
|
|
163
|
+
useState: (init) => {
|
|
164
|
+
const at = hookIndex;
|
|
165
|
+
hookIndex += 1;
|
|
166
|
+
if (!(at in values)) values[at] = typeof init === 'function' ? init() : init;
|
|
167
|
+
return [values[at], (next) => { values[at] = typeof next === 'function' ? next(values[at]) : next; }];
|
|
168
|
+
},
|
|
169
|
+
useEffect: (fn, deps) => {
|
|
170
|
+
if (typeof fn !== 'function') return;
|
|
171
|
+
const at = hookIndex;
|
|
172
|
+
hookIndex += 1;
|
|
173
|
+
const prev = effects[at];
|
|
174
|
+
const same = Array.isArray(deps) === true && prev !== undefined && Array.isArray(prev.deps) === true
|
|
175
|
+
&& deps.length === prev.deps.length && deps.every((one, i) => one === prev.deps[i]);
|
|
176
|
+
if (same) return;
|
|
177
|
+
effectQueue.push({ at: at, fn: fn, deps: Array.isArray(deps) ? deps.slice() : undefined });
|
|
178
|
+
},
|
|
179
|
+
useLayoutEffect: (fn, deps) => {
|
|
180
|
+
if (typeof fn !== 'function') return;
|
|
181
|
+
const at = hookIndex;
|
|
182
|
+
hookIndex += 1;
|
|
183
|
+
const prev = effects[at];
|
|
184
|
+
const same = Array.isArray(deps) === true && prev !== undefined && Array.isArray(prev.deps) === true
|
|
185
|
+
&& deps.length === prev.deps.length && deps.every((one, i) => one === prev.deps[i]);
|
|
186
|
+
if (same) return;
|
|
187
|
+
layoutQueue.push({ at: at, fn: fn, deps: Array.isArray(deps) ? deps.slice() : undefined });
|
|
188
|
+
},
|
|
189
|
+
useRef: (init) => {
|
|
190
|
+
const at = hookIndex;
|
|
191
|
+
hookIndex += 1;
|
|
192
|
+
if (refs[at] === undefined) refs[at] = { current: init === undefined ? null : init };
|
|
193
|
+
return refs[at];
|
|
194
|
+
},
|
|
195
|
+
useMemo: (fn) => { hookIndex += 1; return fn(); },
|
|
196
|
+
useCallback: (fn) => { hookIndex += 1; return fn; },
|
|
197
|
+
useSyncExternalStore: (subscribe, snapshot) => { hookIndex += 1; return snapshot(); },
|
|
198
|
+
Fragment: Symbol('Fragment')
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const flushQueue = (queue) => {
|
|
202
|
+
queue.forEach((item) => {
|
|
203
|
+
const prev = effects[item.at];
|
|
204
|
+
if (prev !== undefined && typeof prev.cleanup === 'function') prev.cleanup();
|
|
205
|
+
const cleanup = item.fn();
|
|
206
|
+
effects[item.at] = { deps: item.deps, cleanup: typeof cleanup === 'function' ? cleanup : null };
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const api = runPlugin(code, reactStub, fakeWindow, fakeDocument, reactDom);
|
|
211
|
+
|
|
212
|
+
/* 最小 DOM 关系:输入框、设置区内部滚动、包住设置 root 的真实滚动祖先、对话区背景 */
|
|
213
|
+
const dom = {
|
|
214
|
+
inputNode: { __modelInput: true },
|
|
215
|
+
settingsPop: { rect: { left: 0, top: 0 }, getBoundingClientRect() { return this.rect; } },
|
|
216
|
+
settingsInner: { __settingsInner: true },
|
|
217
|
+
conversation: { __conversation: true },
|
|
218
|
+
settingsScroller: { scrollHeight: 1200, clientHeight: 600, scrollTop: 0 }
|
|
219
|
+
};
|
|
220
|
+
dom.settingsRoot = {
|
|
221
|
+
parentElement: dom.settingsScroller,
|
|
222
|
+
contains: (node) => node === dom.settingsInner || node === dom.inputNode
|
|
223
|
+
};
|
|
224
|
+
ACTIVE_DOM = dom;
|
|
225
|
+
api.setConfig(CONFIG);
|
|
226
|
+
|
|
227
|
+
const translator = (key, params) => {
|
|
228
|
+
let out = api.zh[key] === undefined ? key : api.zh[key];
|
|
229
|
+
if (params !== undefined && params !== null) {
|
|
230
|
+
out = out.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match));
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
};
|
|
234
|
+
const t = translator;
|
|
235
|
+
|
|
236
|
+
const render = () => {
|
|
237
|
+
/* React 在菜单卸载时会把 ref.current 清空;同步这个关键语义,避免 no-match wheel 误用旧菜单。 */
|
|
238
|
+
if (menuRefSlot !== null) menuRefSlot.current = null;
|
|
239
|
+
hookIndex = 0;
|
|
240
|
+
layoutQueue = [];
|
|
241
|
+
effectQueue = [];
|
|
242
|
+
const tree = api.SettingsSection({ t: t, useProjection: () => undefined });
|
|
243
|
+
flushQueue(layoutQueue);
|
|
244
|
+
flushQueue(effectQueue);
|
|
245
|
+
return tree;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const dispatchWindow = (type, target, extra) => {
|
|
249
|
+
const event = Object.assign({ type: type, target: target }, extra || {});
|
|
250
|
+
windowListeners.filter((one) => one.type === type && one.capture === true).forEach((one) => one.fn(event));
|
|
251
|
+
windowListeners.filter((one) => one.type === type && one.capture !== true).forEach((one) => one.fn(event));
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
api: api, t: t, render: render, dispatchWindow: dispatchWindow, window: fakeWindow,
|
|
256
|
+
windowListenerCount: (type) => windowListeners.filter((one) => one.type === type).length,
|
|
257
|
+
docClickCount: () => docClicks.length,
|
|
258
|
+
portalCalls: portalCalls, document: fakeDocument,
|
|
259
|
+
dom: dom
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const RECT_DEFAULT = { left: 0, top: 0, right: 200, bottom: 100, width: 200, height: 100 };
|
|
264
|
+
const focusEvent = (rowNode, rect) => {
|
|
265
|
+
const r = rect === undefined ? RECT_DEFAULT : rect;
|
|
266
|
+
const dom = ACTIVE_DOM || {};
|
|
267
|
+
const target = Object.assign({}, rowNode, { clientLeft: 0, clientTop: 0, getBoundingClientRect: () => r });
|
|
268
|
+
const anchor = {
|
|
269
|
+
getBoundingClientRect: () => r,
|
|
270
|
+
closest: (sel) => (sel === '.dsb-model' ? target : (sel === '.dsb-edit-pop' ? (dom.settingsPop || null) : (sel === '.dsb-settings' ? (dom.settingsRoot || null) : null))),
|
|
271
|
+
contains: (node) => dom.inputNode !== undefined && node === dom.inputNode
|
|
272
|
+
};
|
|
273
|
+
return { type: 'focus', target: { select: () => { throw new Error('适用模型输入聚焦时不得自动选择文本'); } }, stopPropagation: () => {}, currentTarget: { closest: (sel) => (sel === '.dsb-select' ? anchor : null) } };
|
|
274
|
+
};
|
|
275
|
+
/* 输入/键盘事件:currentTarget 与 focus 一致,target 带 value */
|
|
276
|
+
const inputEvent = (rowNode, value) => {
|
|
277
|
+
const ev = focusEvent(rowNode);
|
|
278
|
+
ev.target = { value: value, select: () => {} };
|
|
279
|
+
return ev;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/* 平台区块 / 行 / 输入 / 菜单 取节点 */
|
|
283
|
+
const sectionOf = (tree) => findAll(tree, (node) => hasClass(node, 'dsb-section') && node.props.key === '__platforms')[0];
|
|
284
|
+
const platformRowOf = (tree) => findAll(sectionOf(tree), (node) => hasClass(node, 'dsb-model') && node.props.key === 'relay-a')[0];
|
|
285
|
+
const rowsOf = (tree) => findAll(platformRowOf(tree), (node) => hasClass(node, 'dsb-modelrow'));
|
|
286
|
+
const inputOfRow = (row) => findAll(row, (node) => node.type === 'input' && hasClass(node, 'dsb-select-btn'))[0];
|
|
287
|
+
const menuOf = (tree) => findAll(tree, (node) => hasClass(node, 'dsb-modelrow-menu'))[0];
|
|
288
|
+
const itemsOf = (menu) => findAll(menu, (node) => node.type === 'button' && hasClass(node, 'dsb-select-item'));
|
|
289
|
+
const headOf = (tree) => findAll(platformRowOf(tree), (node) => hasClass(node, 'dsb-platform-head'))[0];
|
|
290
|
+
|
|
291
|
+
function openPlatformEdit(h) {
|
|
292
|
+
let tree = h.render();
|
|
293
|
+
headOf(tree).props.onClick();
|
|
294
|
+
tree = h.render();
|
|
295
|
+
assert.ok(findAll(platformRowOf(tree), (node) => hasClass(node, 'dsb-platform-pop')).length === 1, '前置:平台编辑区已展开');
|
|
296
|
+
return tree;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/* ============================================================ A. 滚动语义(锁定项) */
|
|
300
|
+
console.log('===== A. 平台「适用模型」下拉:内部滚动不关闭 / 外部滚动仍关闭 =====');
|
|
301
|
+
{
|
|
302
|
+
const h = makeHarness();
|
|
303
|
+
let tree = openPlatformEdit(h);
|
|
304
|
+
const row = () => platformRowOf(tree);
|
|
305
|
+
const input = () => inputOfRow(rowsOf(tree)[0]);
|
|
306
|
+
const openMenu = () => {
|
|
307
|
+
input().props.onClick(focusEvent(row()));
|
|
308
|
+
tree = h.render();
|
|
309
|
+
assert.ok(menuOf(tree) !== undefined, '点击关闭态适用模型输入框应打开候选气泡');
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
openMenu();
|
|
313
|
+
const menuEl = menuOf(tree).props.ref.current;
|
|
314
|
+
assert.ok(menuEl !== null && menuEl !== undefined, '菜单 ref 应指向菜单节点');
|
|
315
|
+
assert.ok(h.windowListenerCount('wheel') >= 1 && h.windowListenerCount('touchmove') >= 1 && h.windowListenerCount('scroll') >= 1,
|
|
316
|
+
'打开菜单后应注册 window 的 scroll/wheel/touchmove 监听');
|
|
317
|
+
|
|
318
|
+
/* ① 菜单内部:wheel / touchmove / scroll 都不关闭 */
|
|
319
|
+
const inside = { __insideModelMenu: true };
|
|
320
|
+
h.dispatchWindow('wheel', inside); tree = h.render();
|
|
321
|
+
assert.ok(menuOf(tree) !== undefined, '菜单内 wheel 不应关闭菜单');
|
|
322
|
+
h.dispatchWindow('touchmove', inside); tree = h.render();
|
|
323
|
+
assert.ok(menuOf(tree) !== undefined, '菜单内 touchmove 不应关闭菜单');
|
|
324
|
+
h.dispatchWindow('scroll', inside); tree = h.render();
|
|
325
|
+
assert.ok(menuOf(tree) !== undefined, '菜单内 scroll 不应关闭菜单');
|
|
326
|
+
|
|
327
|
+
/* 菜单节点自身拦截 wheel / touchmove 冒泡,且不 preventDefault */
|
|
328
|
+
let stopped = 0; let prevented = 0;
|
|
329
|
+
const menuWheelEvent = { target: inside, stopPropagation: () => { stopped += 1; }, preventDefault: () => { prevented += 1; } };
|
|
330
|
+
menuEl.listeners.filter((one) => one.type === 'wheel').forEach((one) => one.fn(menuWheelEvent));
|
|
331
|
+
assert.strictEqual(stopped, 1, '菜单内 wheel 应 stopPropagation(不冒泡到外层关闭逻辑)');
|
|
332
|
+
assert.strictEqual(prevented, 0, '菜单内 wheel 不得 preventDefault(自身滚动照常)');
|
|
333
|
+
menuEl.listeners.filter((one) => one.type === 'touchmove').forEach((one) => one.fn({ target: inside, stopPropagation: () => { stopped += 1; } }));
|
|
334
|
+
assert.strictEqual(stopped, 2, '菜单内 touchmove 应 stopPropagation');
|
|
335
|
+
|
|
336
|
+
/* ② 菜单外部 wheel 立即关闭 */
|
|
337
|
+
h.dispatchWindow('wheel', h.dom.settingsScroller); tree = h.render();
|
|
338
|
+
assert.strictEqual(menuOf(tree), undefined, '菜单外 wheel 仍应立即关闭菜单');
|
|
339
|
+
|
|
340
|
+
/* ③ 菜单外部 scroll(平台列表 / 页面)立即关闭 */
|
|
341
|
+
openMenu();
|
|
342
|
+
h.dispatchWindow('scroll', h.dom.settingsInner); tree = h.render();
|
|
343
|
+
assert.strictEqual(menuOf(tree), undefined, '菜单外 scroll(内部平台列表)仍应立即关闭菜单');
|
|
344
|
+
openMenu();
|
|
345
|
+
h.dispatchWindow('scroll', h.dom.settingsScroller); tree = h.render();
|
|
346
|
+
assert.strictEqual(menuOf(tree), undefined, '菜单外 scroll(页面)仍应立即关闭菜单');
|
|
347
|
+
|
|
348
|
+
/* ④ 外部 touchmove 仍关闭 */
|
|
349
|
+
openMenu();
|
|
350
|
+
h.dispatchWindow('touchmove', h.dom.settingsInner); tree = h.render();
|
|
351
|
+
assert.strictEqual(menuOf(tree), undefined, '菜单外 touchmove 仍应立即关闭菜单');
|
|
352
|
+
|
|
353
|
+
/* ⑤ 输入框滚轮:把 deltaY 滚到菜单 scrollTop,preventDefault + stopPropagation,菜单保持打开 */
|
|
354
|
+
openMenu();
|
|
355
|
+
const curMenu = menuOf(tree).props.ref.current;
|
|
356
|
+
curMenu.scrollTop = 0;
|
|
357
|
+
curMenu.scrollHeight = 200;
|
|
358
|
+
curMenu.clientHeight = 100;
|
|
359
|
+
let wheelPrevented = 0; let wheelStopped = 0;
|
|
360
|
+
h.dispatchWindow('wheel', h.dom.inputNode, {
|
|
361
|
+
deltaY: 64,
|
|
362
|
+
preventDefault: () => { wheelPrevented += 1; },
|
|
363
|
+
stopPropagation: () => { wheelStopped += 1; }
|
|
364
|
+
});
|
|
365
|
+
tree = h.render();
|
|
366
|
+
assert.ok(menuOf(tree) !== undefined, '输入框内 wheel 不应关闭菜单');
|
|
367
|
+
assert.strictEqual(curMenu.scrollTop, 64, '输入框内 wheel 应把 deltaY 滚到菜单 scrollTop');
|
|
368
|
+
assert.strictEqual(wheelPrevented, 1, '输入框内 wheel 应 preventDefault(不把滚轮传给背景页/对话区)');
|
|
369
|
+
assert.ok(wheelStopped >= 1, '输入框内 wheel 应 stopPropagation');
|
|
370
|
+
|
|
371
|
+
/* ⑥ DSH 背景对话区的程序滚动 / 滚轮不关闭菜单 */
|
|
372
|
+
h.dispatchWindow('scroll', h.dom.conversation); tree = h.render();
|
|
373
|
+
assert.ok(menuOf(tree) !== undefined, '背景对话区自动滚动 scroll 不应关闭菜单');
|
|
374
|
+
h.dispatchWindow('wheel', h.dom.conversation); tree = h.render();
|
|
375
|
+
assert.ok(menuOf(tree) !== undefined, '背景对话区 wheel 不应关闭菜单');
|
|
376
|
+
h.dispatchWindow('touchmove', h.dom.conversation); tree = h.render();
|
|
377
|
+
assert.ok(menuOf(tree) !== undefined, '背景对话区 touchmove 不应关闭菜单');
|
|
378
|
+
|
|
379
|
+
/* ⑦ 关闭后 input 仍聚焦:再次 click 应重新打开气泡(不依赖 focus) */
|
|
380
|
+
h.dispatchWindow('scroll', h.dom.settingsInner); tree = h.render();
|
|
381
|
+
assert.strictEqual(menuOf(tree), undefined, '前置:设置区滚动已关闭菜单');
|
|
382
|
+
input().props.onClick(focusEvent(row())); tree = h.render();
|
|
383
|
+
assert.ok(menuOf(tree) !== undefined, '菜单关闭且 input 仍聚焦时,点击 input 应重新打开气泡');
|
|
384
|
+
|
|
385
|
+
/* ⑧ 选项点击仍正常:打开 → 点选项 → 选中并收起 */
|
|
386
|
+
openMenu();
|
|
387
|
+
const item = itemsOf(menuOf(tree)).filter((node) => node.props.key === 'deepseek-flash')[0];
|
|
388
|
+
assert.ok(item !== undefined, '菜单里应有 deepseek-flash 选项');
|
|
389
|
+
item.props.onClick({ stopPropagation: () => {} });
|
|
390
|
+
tree = h.render();
|
|
391
|
+
assert.strictEqual(menuOf(tree), undefined, '点选项后菜单收起');
|
|
392
|
+
assert.strictEqual(input().props['aria-expanded'], 'false', '选项点击后输入框回到收起态');
|
|
393
|
+
|
|
394
|
+
console.log(' 内部滚动不关闭;输入框 wheel 滚候选并阻止背景;设置滚动关闭;背景对话滚动放行;关闭后 click 重开;选项点击正常');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/* ============================================================ A-1. dirty filter 提交 / no-match wheel 放行 / 边界放行 */
|
|
398
|
+
console.log('===== A-1. dirty filter 提交;无菜单与滚动边界 wheel 放行 =====');
|
|
399
|
+
{
|
|
400
|
+
/* 设置区 scroll 关闭菜单时,dirty filter 必须写回模型行,不能恢复旧值。 */
|
|
401
|
+
{
|
|
402
|
+
const h = makeHarness();
|
|
403
|
+
let tree = openPlatformEdit(h);
|
|
404
|
+
const row = () => platformRowOf(tree);
|
|
405
|
+
const input = () => inputOfRow(rowsOf(tree)[0]);
|
|
406
|
+
input().props.onClick(focusEvent(row())); tree = h.render();
|
|
407
|
+
input().props.onChange(inputEvent(row(), 'claude')); tree = h.render();
|
|
408
|
+
h.dispatchWindow('scroll', h.dom.settingsInner); tree = h.render();
|
|
409
|
+
assert.strictEqual(menuOf(tree), undefined, '设置区 scroll 应关闭菜单');
|
|
410
|
+
assert.strictEqual(input().props.value, 'Claude', '设置区 scroll 关闭菜单时必须提交 dirty filter');
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/* 无匹配时没有真实 menu:wheel 不得 prevent/stop,且关闭后保留筛选文本。 */
|
|
414
|
+
{
|
|
415
|
+
const h = makeHarness();
|
|
416
|
+
let tree = openPlatformEdit(h);
|
|
417
|
+
const row = () => platformRowOf(tree);
|
|
418
|
+
const input = () => inputOfRow(rowsOf(tree)[0]);
|
|
419
|
+
input().props.onClick(focusEvent(row())); tree = h.render();
|
|
420
|
+
input().props.onChange(inputEvent(row(), 'zzz')); tree = h.render();
|
|
421
|
+
assert.strictEqual(menuOf(tree), undefined, '无匹配时不应存在真实 menu');
|
|
422
|
+
let prevented = 0; let stopped = 0;
|
|
423
|
+
h.dispatchWindow('wheel', h.dom.inputNode, { deltaY: 20, preventDefault: () => { prevented += 1; }, stopPropagation: () => { stopped += 1; } });
|
|
424
|
+
tree = h.render();
|
|
425
|
+
assert.strictEqual(prevented, 0, '无匹配 wheel 不得 preventDefault,应让设置滚动继续');
|
|
426
|
+
assert.strictEqual(stopped, 0, '无匹配 wheel 不得 stopPropagation,应让设置滚动继续');
|
|
427
|
+
assert.strictEqual(input().props.value, 'Zzz', '无匹配 wheel 关闭后必须保留筛选文本');
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/* 真实 menu 在顶部向上、底部向下都不能再滚时,wheel 放行给设置区。 */
|
|
431
|
+
{
|
|
432
|
+
const h = makeHarness();
|
|
433
|
+
let tree = openPlatformEdit(h);
|
|
434
|
+
const row = () => platformRowOf(tree);
|
|
435
|
+
const input = () => inputOfRow(rowsOf(tree)[0]);
|
|
436
|
+
const open = () => { input().props.onClick(focusEvent(row())); tree = h.render(); assert.ok(menuOf(tree) !== undefined, '边界场景 menu 应打开'); };
|
|
437
|
+
open();
|
|
438
|
+
input().props.onChange(inputEvent(row(), 'c')); tree = h.render();
|
|
439
|
+
let menu = menuOf(tree).props.ref.current;
|
|
440
|
+
menu.scrollHeight = 300; menu.clientHeight = 100; menu.scrollTop = 0;
|
|
441
|
+
let prevented = 0; let stopped = 0;
|
|
442
|
+
h.dispatchWindow('wheel', h.dom.inputNode, { deltaY: -20, preventDefault: () => { prevented += 1; }, stopPropagation: () => { stopped += 1; } });
|
|
443
|
+
tree = h.render();
|
|
444
|
+
assert.strictEqual(prevented, 0, '顶部向上 boundary wheel 不得 preventDefault');
|
|
445
|
+
assert.strictEqual(stopped, 0, '顶部向上 boundary wheel 不得 stopPropagation');
|
|
446
|
+
assert.strictEqual(input().props.value, 'C', '顶部 boundary 关闭后保留 dirty filter');
|
|
447
|
+
open();
|
|
448
|
+
menu = menuOf(tree).props.ref.current;
|
|
449
|
+
menu.scrollHeight = 300; menu.clientHeight = 100; menu.scrollTop = 200;
|
|
450
|
+
prevented = 0; stopped = 0;
|
|
451
|
+
h.dispatchWindow('wheel', h.dom.inputNode, { deltaY: 20, preventDefault: () => { prevented += 1; }, stopPropagation: () => { stopped += 1; } });
|
|
452
|
+
tree = h.render();
|
|
453
|
+
assert.strictEqual(prevented, 0, '底部向下 boundary wheel 不得 preventDefault');
|
|
454
|
+
assert.strictEqual(stopped, 0, '底部向下 boundary wheel 不得 stopPropagation');
|
|
455
|
+
assert.strictEqual(input().props.value, 'C', '底部 boundary 关闭后保留筛选文本');
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
console.log(' dirty filter 随 scroll 提交;no-match wheel 与上下边界 wheel 放行并保留文本');
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/* ============================================================ B. 可输入筛选 + 清空恢复 + 无匹配空白 */
|
|
462
|
+
console.log('===== B. 模型输入控件:原生输入 + 包含匹配 + 清空恢复 + 无匹配空白 =====');
|
|
463
|
+
{
|
|
464
|
+
const h = makeHarness();
|
|
465
|
+
const t = h.t;
|
|
466
|
+
let tree = openPlatformEdit(h);
|
|
467
|
+
const row = () => platformRowOf(tree);
|
|
468
|
+
const input = () => inputOfRow(rowsOf(tree)[0]);
|
|
469
|
+
const menu = () => menuOf(tree);
|
|
470
|
+
const itemKeys = () => itemsOf(menu()).map((node) => node.props.key);
|
|
471
|
+
|
|
472
|
+
/* 原生输入 + 可访问名 + combobox/aria */
|
|
473
|
+
const first = input();
|
|
474
|
+
assert.strictEqual(first.type, 'input', '适用模型应是原生 text input');
|
|
475
|
+
assert.strictEqual(first.props.type, 'text', 'input type 应为 text');
|
|
476
|
+
assert.strictEqual(first.props.role, 'combobox', 'input 角色应为 combobox');
|
|
477
|
+
assert.strictEqual(first.props['aria-label'], t('platformModels'), 'input 应有可访问名(适用模型)');
|
|
478
|
+
assert.strictEqual(first.props['aria-expanded'], 'false', '未打开时 aria-expanded=false');
|
|
479
|
+
assert.ok(typeof first.props['aria-controls'] === 'string' && first.props['aria-controls'].length > 0, '应有 aria-controls 指向 listbox');
|
|
480
|
+
assert.strictEqual(first.props.value, 'DeepSeek-Flash', '收起态保留当前值显示');
|
|
481
|
+
|
|
482
|
+
/* 聚焦已有值:显示气泡,不自动选择文本。 */
|
|
483
|
+
input().props.onFocus(focusEvent(row())); tree = h.render();
|
|
484
|
+
assert.ok(menu() !== undefined, '聚焦时应显示现有下拉气泡');
|
|
485
|
+
assert.strictEqual(input().props.value, 'DeepSeek-Flash', '聚焦已有值时仍显示当前值');
|
|
486
|
+
const listbox = menu();
|
|
487
|
+
assert.strictEqual(listbox.props.role, 'listbox', '气泡 role=listbox');
|
|
488
|
+
assert.ok(typeof listbox.props.id === 'string' && listbox.props.id.length > 0, 'listbox 应有 id');
|
|
489
|
+
assert.strictEqual(input().props['aria-controls'], listbox.props.id, 'aria-controls 应指向该 listbox');
|
|
490
|
+
assert.strictEqual(input().props['aria-expanded'], 'true', '打开时 aria-expanded=true');
|
|
491
|
+
|
|
492
|
+
/* 清空输入恢复全部候选 */
|
|
493
|
+
input().props.onChange(inputEvent(row(), '')); tree = h.render();
|
|
494
|
+
assert.strictEqual(input().props.value, '', '清空后输入框为空');
|
|
495
|
+
assert.strictEqual(itemKeys().length, 5, '清空筛选应恢复全部候选');
|
|
496
|
+
|
|
497
|
+
/* 输入 C:大小写无关包含匹配,命中 Claude,排除其它无 c 的模型 */
|
|
498
|
+
input().props.onChange(inputEvent(row(), 'C')); tree = h.render();
|
|
499
|
+
assert.strictEqual(input().props.value, 'C', '输入后筛选文本写回输入框');
|
|
500
|
+
let keys = itemKeys();
|
|
501
|
+
assert.ok(keys.indexOf('claude-opus-test') !== -1, '输入 C 应命中 Claude(原始名含 c)');
|
|
502
|
+
['deepseek-flash', 'gpt-4o-mini-test', 'gemini-test', 'qwen-max-test'].forEach((name) => {
|
|
503
|
+
assert.strictEqual(keys.indexOf(name), -1, '输入 C 不应命中无 c 的模型:' + name);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
/* 小写 c 结果一致 */
|
|
507
|
+
input().props.onChange(inputEvent(row(), 'c')); tree = h.render();
|
|
508
|
+
assert.ok(itemKeys().indexOf('claude-opus-test') !== -1, '小写 c 同样命中 Claude(大小写无关)');
|
|
509
|
+
|
|
510
|
+
/* 按原始名子串匹配(opus) */
|
|
511
|
+
input().props.onChange(inputEvent(row(), 'opus')); tree = h.render();
|
|
512
|
+
assert.deepStrictEqual(itemKeys(), ['claude-opus-test'], '输入 opus 仅命中 claude(原始名子串)');
|
|
513
|
+
|
|
514
|
+
/* 再次清空恢复全部 */
|
|
515
|
+
input().props.onChange(inputEvent(row(), '')); tree = h.render();
|
|
516
|
+
assert.strictEqual(itemKeys().length, 5, '再次清空应恢复全部候选');
|
|
517
|
+
|
|
518
|
+
/* 无匹配:空列表,不渲染任何提示文案(空白) */
|
|
519
|
+
input().props.onChange(inputEvent(row(), 'zzz')); tree = h.render();
|
|
520
|
+
assert.strictEqual(menu(), undefined, '无匹配时完全不渲染 listbox');
|
|
521
|
+
assert.strictEqual(input().props['aria-expanded'], 'false', '无匹配时 aria-expanded=false');
|
|
522
|
+
input().props.onChange(inputEvent(row(), '')); tree = h.render();
|
|
523
|
+
assert.ok(menu() !== undefined, '清空筛选后重新显示候选 listbox');
|
|
524
|
+
assert.strictEqual(input().props['aria-expanded'], 'true', '清空后候选可见时 aria-expanded=true');
|
|
525
|
+
assert.strictEqual(itemKeys().length, 5, '清空无匹配筛选后恢复全部候选');
|
|
526
|
+
|
|
527
|
+
console.log(' 原生输入 / 可访问名 / C 与 c 包含匹配 / opus 子串 / 清空恢复 / 无匹配空白');
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/* ============================================================ C. 键盘不选择 + Escape + 鼠标可选 */
|
|
531
|
+
console.log('===== C. 键盘不参与选择:方向键/Enter 不选、Escape 关闭、鼠标点击可选 =====');
|
|
532
|
+
{
|
|
533
|
+
const h = makeHarness();
|
|
534
|
+
let tree = openPlatformEdit(h);
|
|
535
|
+
const row = () => platformRowOf(tree);
|
|
536
|
+
const input = () => inputOfRow(rowsOf(tree)[0]);
|
|
537
|
+
const menu = () => menuOf(tree);
|
|
538
|
+
|
|
539
|
+
/* 清空显示全部,确保若键盘误选会改变输入值 */
|
|
540
|
+
input().props.onFocus(focusEvent(row())); tree = h.render();
|
|
541
|
+
input().props.onChange(inputEvent(row(), '')); tree = h.render();
|
|
542
|
+
assert.ok(itemsOf(menu()).length >= 2, '清空后应显示多个候选');
|
|
543
|
+
const beforeValue = input().props.value;
|
|
544
|
+
const beforeKeys = itemsOf(menu()).map((node) => node.props.key);
|
|
545
|
+
|
|
546
|
+
/* 方向键不得改变选择、不得关闭菜单 */
|
|
547
|
+
['ArrowDown', 'ArrowUp', 'ArrowDown'].forEach((key) => {
|
|
548
|
+
input().props.onKeyDown(Object.assign(inputEvent(row(), ''), { key: key, preventDefault: () => {} })); tree = h.render();
|
|
549
|
+
assert.ok(menu() !== undefined, key + ' 不应关闭菜单');
|
|
550
|
+
assert.strictEqual(input().props.value, beforeValue, key + ' 不应改变输入/选择');
|
|
551
|
+
});
|
|
552
|
+
/* 无灰色键盘活动项、无 aria-activedescendant */
|
|
553
|
+
assert.strictEqual(findAll(menu(), (node) => hasClass(node, 'dsb-select-item-active')).length, 0, '不应出现键盘活动灰底项');
|
|
554
|
+
assert.strictEqual(input().props['aria-activedescendant'], undefined, '不应有 aria-activedescendant(无键盘活动项)');
|
|
555
|
+
|
|
556
|
+
/* Enter 不得选中 option / 菜单保持打开 / 候选不变 */
|
|
557
|
+
input().props.onKeyDown(Object.assign(inputEvent(row(), ''), { key: 'Enter', preventDefault: () => {} })); tree = h.render();
|
|
558
|
+
assert.ok(menu() !== undefined, 'Enter 不应选中并关闭菜单');
|
|
559
|
+
assert.deepStrictEqual(itemsOf(menu()).map((node) => node.props.key), beforeKeys, 'Enter 不应改变候选/选择');
|
|
560
|
+
assert.strictEqual(input().props.value, beforeValue, 'Enter 不应改变输入值');
|
|
561
|
+
|
|
562
|
+
/* Escape 关闭并恢复已选显示 */
|
|
563
|
+
input().props.onKeyDown(Object.assign(inputEvent(row(), ''), { key: 'Escape', preventDefault: () => {} })); tree = h.render();
|
|
564
|
+
assert.strictEqual(menu(), undefined, 'Escape 关闭菜单');
|
|
565
|
+
assert.strictEqual(input().props.value, 'DeepSeek-Flash', 'Escape 后恢复已选值显示');
|
|
566
|
+
|
|
567
|
+
/* 鼠标点击仍可选 */
|
|
568
|
+
input().props.onFocus(focusEvent(row())); tree = h.render();
|
|
569
|
+
input().props.onChange(inputEvent(row(), 'claude')); tree = h.render();
|
|
570
|
+
const claude = itemsOf(menu()).filter((node) => node.props.key === 'claude-opus-test')[0];
|
|
571
|
+
assert.ok(claude !== undefined, '筛选 claude 后应出现 claude 候选');
|
|
572
|
+
let mouseDownPrevented = false; let mouseDownStopped = false;
|
|
573
|
+
claude.props.onMouseDown({ preventDefault: () => { mouseDownPrevented = true; }, stopPropagation: () => { mouseDownStopped = true; } });
|
|
574
|
+
assert.strictEqual(mouseDownPrevented, true, '候选 mousedown 必须 preventDefault,避免 input 抢先 blur');
|
|
575
|
+
assert.strictEqual(mouseDownStopped, true, '候选 mousedown 必须阻止冒泡');
|
|
576
|
+
claude.props.onClick({ stopPropagation: () => {} }); tree = h.render();
|
|
577
|
+
assert.strictEqual(menu(), undefined, '点击候选后菜单收起');
|
|
578
|
+
assert.strictEqual(input().props.value, 'Claude-Opus-Test', '点击候选写回所选模型显示名');
|
|
579
|
+
|
|
580
|
+
/* 再次聚焦显示已选模型,筛选文本不残留 */
|
|
581
|
+
input().props.onFocus(focusEvent(row())); tree = h.render();
|
|
582
|
+
assert.strictEqual(input().props.value, 'Claude-Opus-Test', '再次聚焦显示已选模型,筛选文本未残留');
|
|
583
|
+
input().props.onKeyDown(Object.assign(inputEvent(row(), ''), { key: 'Escape', preventDefault: () => {} })); tree = h.render();
|
|
584
|
+
assert.strictEqual(menu(), undefined, 'Escape 关闭');
|
|
585
|
+
|
|
586
|
+
console.log(' 方向键/Enter 不选、无灰底活动项、Escape 关闭、鼠标点击可选、筛选不残留');
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/* ============================================================ D. 布局:fixed / 3 项高度 / 始终向下 / 视口夹紧 */
|
|
590
|
+
console.log('===== D. 布局:fixed 定位 / 最多 3 项完整高度 / 始终向下 / 视口夹紧 =====');
|
|
591
|
+
function openWithRect(rect, viewW, viewH) {
|
|
592
|
+
const h = makeHarness();
|
|
593
|
+
if (typeof viewW === 'number') h.window.innerWidth = viewW;
|
|
594
|
+
if (typeof viewH === 'number') h.window.innerHeight = viewH;
|
|
595
|
+
let tree = openPlatformEdit(h);
|
|
596
|
+
const row = platformRowOf(tree);
|
|
597
|
+
const input = inputOfRow(rowsOf(tree)[0]);
|
|
598
|
+
input.props.onFocus(focusEvent(row, rect));
|
|
599
|
+
tree = h.render();
|
|
600
|
+
const menu = menuOf(tree);
|
|
601
|
+
assert.ok(menu !== undefined, '布局场景:菜单应打开');
|
|
602
|
+
return menu.props.style;
|
|
603
|
+
}
|
|
604
|
+
{
|
|
605
|
+
/* 无 react-dom 时 fixed 的包含块是最近 .dsb-edit-pop:坐标换算后仍向下且按视口底部限高。 */
|
|
606
|
+
const fallbackHarness = makeHarness();
|
|
607
|
+
fallbackHarness.window.innerHeight = 450;
|
|
608
|
+
fallbackHarness.dom.settingsPop.rect = { left: 20, top: 300 };
|
|
609
|
+
let fallbackTree = openPlatformEdit(fallbackHarness);
|
|
610
|
+
const fallbackRow = platformRowOf(fallbackTree);
|
|
611
|
+
inputOfRow(rowsOf(fallbackTree)[0]).props.onFocus(focusEvent(fallbackRow, { left: 100, top: 350, right: 300, bottom: 380, width: 200, height: 30 }));
|
|
612
|
+
fallbackTree = fallbackHarness.render();
|
|
613
|
+
const fallbackMenu = menuOf(fallbackTree);
|
|
614
|
+
assert.ok(fallbackMenu !== undefined, 'fallback 路径菜单应打开');
|
|
615
|
+
assert.strictEqual(fallbackMenu.props.style.left, '80px', 'fallback left 应减去 .dsb-edit-pop 的视口 left');
|
|
616
|
+
assert.strictEqual(fallbackMenu.props.style.top, '84px', 'fallback top 应减去 .dsb-edit-pop 的视口 top');
|
|
617
|
+
assert.strictEqual(fallbackMenu.props.style.bottom, 'auto', 'fallback 不得向上展开');
|
|
618
|
+
assert.strictEqual(fallbackMenu.props.style.maxHeight, '62px', 'fallback 仍按视口底部剩余空间限高');
|
|
619
|
+
assert.strictEqual(fallbackHarness.portalCalls.length, 0, '无 react-dom 时必须走 fallback');
|
|
620
|
+
|
|
621
|
+
/* react-dom 可用时 portal 到 document.body,保留视口 fixed 坐标与同一限高。 */
|
|
622
|
+
const portalHarness = makeHarness({ portal: true });
|
|
623
|
+
portalHarness.window.innerHeight = 450;
|
|
624
|
+
portalHarness.dom.settingsPop.rect = { left: 20, top: 300 };
|
|
625
|
+
let portalTree = openPlatformEdit(portalHarness);
|
|
626
|
+
const portalRow = platformRowOf(portalTree);
|
|
627
|
+
inputOfRow(rowsOf(portalTree)[0]).props.onFocus(focusEvent(portalRow, { left: 100, top: 350, right: 300, bottom: 380, width: 200, height: 30 }));
|
|
628
|
+
portalTree = portalHarness.render();
|
|
629
|
+
const portalMenu = menuOf(portalTree);
|
|
630
|
+
assert.ok(portalMenu !== undefined, 'portal 路径菜单应打开');
|
|
631
|
+
assert.strictEqual(portalMenu.props.style.left, '100px', 'portal left 应使用视口坐标');
|
|
632
|
+
assert.strictEqual(portalMenu.props.style.top, '384px', 'portal top 应使用视口坐标并向下展开');
|
|
633
|
+
assert.strictEqual(portalMenu.props.style.bottom, 'auto', 'portal 不得向上展开');
|
|
634
|
+
assert.strictEqual(portalMenu.props.style.maxHeight, '62px', 'portal 仍按视口底部剩余空间限高');
|
|
635
|
+
const menuPortalCall = portalHarness.portalCalls.filter((call) => call.node !== null && call.node !== undefined && call.node.props !== undefined && typeof call.node.props.className === 'string' && call.node.props.className.indexOf('dsb-modelrow-menu') !== -1)[0];
|
|
636
|
+
assert.ok(menuPortalCall !== undefined, '模型菜单应调用 createPortal');
|
|
637
|
+
assert.strictEqual(menuPortalCall.target, portalHarness.document.body, '模型菜单 portal 目标必须是 document.body');
|
|
638
|
+
|
|
639
|
+
/* 默认下方够放:3 项完整高度 = 8 + 3*30 = 98;fixed 贴输入框 */
|
|
640
|
+
const a = openWithRect({ left: 0, top: 0, right: 200, bottom: 100, width: 200, height: 100 }, 1200, 900);
|
|
641
|
+
assert.strictEqual(a.position, 'fixed', '菜单应为 fixed 定位(脱离设置容器 overflow 裁切)');
|
|
642
|
+
assert.strictEqual(a.maxHeight, '98px', '最多 3 项完整高度(8 + 3*30)');
|
|
643
|
+
assert.strictEqual(a.overflowY, 'auto', '放不下时菜单内部滚动');
|
|
644
|
+
assert.strictEqual(a.left, '0px', '向下贴输入框左边');
|
|
645
|
+
assert.strictEqual(a.width, '200px', '宽度贴合输入框');
|
|
646
|
+
assert.strictEqual(a.top, '104px', '向下贴输入框底边 + 4px');
|
|
647
|
+
assert.strictEqual(a.bottom, 'auto', '向下时不用 bottom');
|
|
648
|
+
|
|
649
|
+
/* 底部空间不足仍向下锚定,按下方实际剩余空间限高。 */
|
|
650
|
+
const b = openWithRect({ left: 0, top: 450, right: 200, bottom: 480, width: 200, height: 30 }, 1200, 500);
|
|
651
|
+
assert.strictEqual(b.position, 'fixed', '底部空间不足时仍 fixed');
|
|
652
|
+
assert.strictEqual(b.top, '484px', '底部不足时 top 仍为输入框底边 + 4px');
|
|
653
|
+
assert.strictEqual(b.bottom, 'auto', '向下定位不使用 bottom');
|
|
654
|
+
assert.strictEqual(b.maxHeight, '12px', '下方仅余 12px 时按实际空间限高');
|
|
655
|
+
|
|
656
|
+
/* 右侧越界 → 左移夹紧在视口内 */
|
|
657
|
+
const c = openWithRect({ left: 1100, top: 0, right: 1300, bottom: 100, width: 200, height: 100 }, 1200, 900);
|
|
658
|
+
assert.strictEqual(c.left, '996px', '右侧越界时夹在视口内(1200 - 4 - 200)');
|
|
659
|
+
|
|
660
|
+
/* 上下都不够 → 按可视空间限高(内部滚动),不超出视口 */
|
|
661
|
+
const d = openWithRect({ left: 0, top: 40, right: 200, bottom: 70, width: 200, height: 30 }, 1200, 120);
|
|
662
|
+
assert.strictEqual(d.maxHeight, '42px', '上下都不够时按可视空间限高(120 - 70 - 4 - 4)');
|
|
663
|
+
assert.strictEqual(d.top, '74px', '限高时仍向下贴底边 + 4px');
|
|
664
|
+
assert.strictEqual(d.overflowY, 'auto', '限高靠菜单内部滚动');
|
|
665
|
+
|
|
666
|
+
console.log(' fixed 定位 / 3 项高度 98px / 底部不足仍向下并限高 / 右越界夹紧 / 菜单内部滚动');
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
console.log('\n全部通过');
|