Files
apes-sidebar/tests/tasks-motion.spec.ts
T
Menghuan1918 e849874673 feat(tasks): 树模式补上单个收起 / 全部收起 / 全部展开
维护者反馈「树目录还缺单个收起/全部收起/全部展开的按钮」。读码确认:树**根本没有
按节点的展开收起**(只有页级的已结算聚合规则,aria-expanded 还是硬编码 true),
所以这三件事在树的语境里确实都不存在。

- 单个收起/展开:有子节点的行右侧一个 16px chevron(收起 →、展开 ⌄),位置与画布
  卡片小条的 chevron 一致;叶子行不画(死控件);点它 stopPropagation,不会顺带
  打开详情窗;行上补 aria-expanded。
- 全部收起/全部展开:控制条里两个**文字**单元格(与其它 28px 控件同形)。用文字而非
  更多 chevron —— 旁边的「折叠已完成的节点」开关已经占了那套图形语汇,两套轴不能共用。
  全部收敛到「有子节点」的节点(只留拓扑根),全部展清空该集合。
- 键盘补标准树绑定:→ 展开(已展开则进入子级)、← 收起(已收起则退回父级)。
- 折叠集存在 SubagentView,图/树切换不丢;与「已结算聚合」是两条互不干扰的轴。

词条 4 个 × 20 词典(tasksTree{Collapse,Expand}{All,Row})。测试 +4 条(单个收放、
叶子无控件、集群全收/全展、方向键收放)。全套 2260 passed / 17 skipped(194 文件)、
tsc 与 eslint 零告警、构建通过;新构建已装进 sidebar-test,:3080 挂载 0 pageerror。
2026-10-12 00:03:20 +08:00

103 lines
4.9 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.
/**
* The Tasks page's motion contract, pinned where a refactor would break it
* silently:
*
* - the CANVAS must not run a FLIP library. Its card layer carries the fit's
* `transform: scale(k)`, and `@formkit/auto-animate` pins a leaving card with
* absolute `left/top` from `getBoundingClientRect()` (a box a scaled layer
* cannot express — the card jumps) and translates movers in unscaled units
* (k× the true distance). Attached there, it was reported as "折叠展开的动效
* 都特别怪"; the canvas uses the CSS entrance on `.node` instead.
* - the FLOW surfaces (tree rows, jobs rows) are where FLIP belongs, and they
* keep it.
*/
import { describe, expect, it } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
const ROOT = resolve(import.meta.dirname, '..')
/** One source file of the client half. */
function source(relative: string): string {
return readFileSync(resolve(ROOT, relative), 'utf8')
}
/**
* A source file with its comments removed. The NEGATIVE assertions below are
* about what the code does, and these files deliberately DOCUMENT the library
* they avoid ("measures `getBoundingClientRect()`…"), so matching raw text
* would fail on the very explanation we want to keep.
*/
function code(relative: string): string {
return source(relative)
.replace(/\/\*[\s\S]*?\*\//g, '')
.replace(/^\s*\/\/.*$/gm, '')
}
describe('Tasks page motion', () => {
it('keeps the FLIP library off the scaled canvas, and on the flow surfaces', () => {
expect(code('src/client/TasksGraph.tsx')).not.toContain('use-auto-animate')
expect(source('src/client/TasksTree.tsx')).toContain('useAutoAnimateRef')
expect(source('src/client/JobsDrawer.tsx')).toContain('useAutoAnimateRef')
})
it('gives canvas cards a mount-only CSS entrance that respects reduced motion', () => {
const styles = source('src/client/tasks-graph.module.css')
const node = /\.node \{([\s\S]*?)\n\}/.exec(styles)?.[1]
if (node === undefined) throw new Error('the .node rule must exist')
expect(node).toContain('animation: dsh-card-in')
const frames = /@keyframes dsh-card-in \{([\s\S]*?)\n\}/.exec(styles)?.[1]
if (frames === undefined) throw new Error('the card entrance keyframes must exist')
expect(frames).toContain('opacity: 0')
// Every reduced-motion block in the sheet is a candidate — the sweep has
// its own — and the card entrance must be switched off in one of them.
const reduced = [...styles.matchAll(/@media \(prefers-reduced-motion: reduce\) \{([\s\S]*?)\n\}/g)]
.map(match => match[1])
.join('\n')
expect(reduced).toContain('.node')
})
it('animates the canvas in LAYOUT coordinates, never with screen-space transforms', () => {
// The canvas's own tween: `left`/`top` are canvas units, so the fit's scale
// applies to the tween exactly as it applies to the final positions — and
// the connectors (pure functions of the boxes) travel with the cards.
expect(source('src/client/TasksGraph.tsx')).toContain('useTweenedLayout')
const tween = code('src/client/tasks-layout-tween.ts')
expect(tween).toContain('requestAnimationFrame')
// No rect measuring in the CODE: that is exactly what makes a scaled layer
// unrepresentable for a FLIP library.
expect(tween).not.toContain('getBoundingClientRect')
// The card entrance is staggered, so a revealed group cascades.
expect(source('src/client/TasksGraph.tsx')).toContain('animationDelay')
})
it('keeps the frame auto-fitted across a fold, by GLIDING rather than jumping', () => {
const graph = code('src/client/TasksGraph.tsx')
// Folding must not claim the view: while the reader has not taken over, a
// layout change glides the frame to the new fit, so an expanded group stays
// centred and inside the panel without yanking the view.
expect(graph).not.toContain('markTouched')
// The untouched-view path GLIDES to the new framing; a fresh session snaps
// (the content changes wholesale), and the reader's own gestures cancel a
// glide in flight.
expect(graph).toContain('if (!touchedRef.current) fitRef.current(true)')
expect(graph).toContain('fitRef.current(false)')
expect(graph).toContain('stopGlide()')
})
it('gives every NESTED tree level its own FLIP host', () => {
// The library watches a container's direct children only: one host on the
// scroll container would animate the top level and let every nested fold
// blink. TreeLevel exists to own one per level.
const tree = code('src/client/TasksTree.tsx')
expect(tree).toContain('function TreeLevel')
expect(tree).toContain('useAutoAnimateRef')
expect(tree).toContain('<TreeLevel')
})
it('parks the motion host behind a WAAPI guard so tests and old hosts stay inert', () => {
const hook = source('src/client/use-auto-animate.ts')
expect(hook).toContain("typeof Element.prototype.animate === 'function'")
})
})