✨ feat(core): 实现详情面板动画逻辑并完善相关测试
* 新增 detailMotion 工具类以支持更精细的动画控制 * 优化 FileManageView 面板渲染逻辑,改用 v-show 提升交互性能 * 调整 Transition 组件为手动控制模式以适配自定义动画 * 在 package.json 中配置自动化测试脚本 * 补充 detailMotion 相关的单元测试与测试说明文档
This commit is contained in:
1 parent
9bac0c0040
commit
af009cf3c5
6 files changed
+307
-138
No files matched your search
@@ -0,0 +1,26 @@
|
||||
# Detail motion regression checks
|
||||
|
||||
Requires Node 22.6+ for the TypeScript unit tests (no extra test dependencies).
|
||||
|
||||
- `npm run test:motion`: animation completion, cancellation, reversal and reduced motion.
|
||||
- `npm run test:motion:coverage`: coverage of `src/utils/detailMotion.ts` only.
|
||||
|
||||
Browser integration uses the actual Vue file-detail view and backend data. Start
|
||||
Vite with the desired test backend, sign in, and open a file with more than three
|
||||
lifecycle rows and at least one retrieval event. In that page's DevTools console:
|
||||
|
||||
```js
|
||||
await (await import('/theme-assets/tests/detailMotion.browser.mjs')).runDetailMotionChecks()
|
||||
```
|
||||
|
||||
Run again at 390px width, then with `prefers-reduced-motion: reduce` emulated:
|
||||
|
||||
```js
|
||||
await (await import('/theme-assets/tests/detailMotion.browser.mjs')).runDetailMotionChecks({ reducedMotion: true })
|
||||
```
|
||||
|
||||
Checks three expand/collapse cycles, nonidentical height endpoints, return to
|
||||
natural height, visible retrieval records, no vertical record transform, rapid
|
||||
reversals and final collapsed layout. It only toggles presentation and never
|
||||
uploads, deletes, restores or changes file data. These checks do not measure
|
||||
whole-project coverage or validate the storage implementation.
|
||||
@@ -0,0 +1,77 @@
|
||||
// Run in the local app with a file detail dialog open (more than 3 lifecycle rows
|
||||
// and retrieval events). Reads real data and toggles presentation only.
|
||||
export async function runDetailMotionChecks({ reducedMotion = false } = {}) {
|
||||
const results = []
|
||||
const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
const assert = (condition, message) => { if (!condition) throw new Error(message) }
|
||||
const lifecycle = () => document.querySelector('.fcb-lifecycle-viewport')
|
||||
const toggle = (kind, expanded) => {
|
||||
const label = kind === 'lifecycle'
|
||||
? (expanded ? '展开全部生命周期记录' : '收起生命周期记录')
|
||||
: (expanded ? '展开全部取件记录' : '收起取件记录')
|
||||
const button = [...document.querySelectorAll('button')].find(b => b.textContent.includes(label))
|
||||
if (button) button.click()
|
||||
}
|
||||
const assertNaturalHeight = label => {
|
||||
const v = lifecycle()
|
||||
const actual = v.getBoundingClientRect().height
|
||||
const expected = v.firstElementChild.getBoundingClientRect().height
|
||||
assert(Math.abs(actual - expected) < 1, `${label}: viewport ${actual}, content ${expected}`)
|
||||
assert(!v.style.height && v.getAnimations().length === 0, `${label}: retained height effect`)
|
||||
results.push({ label, height: actual, contentHeight: expected })
|
||||
}
|
||||
assert(lifecycle(), 'Open a file detail dialog first')
|
||||
toggle('lifecycle', false)
|
||||
await wait(500)
|
||||
const initial = lifecycle().getBoundingClientRect().height
|
||||
for (let cycle = 0; cycle < 3; cycle++) {
|
||||
toggle('lifecycle', true)
|
||||
await wait(30)
|
||||
if (!reducedMotion) {
|
||||
const animation = lifecycle().getAnimations()[0]
|
||||
assert(animation, 'Missing outer height animation')
|
||||
const frames = animation.effect.getKeyframes()
|
||||
assert(frames[0].height !== frames[1].height, 'Identical start and end heights')
|
||||
assert(animation.effect.getTiming().duration === 420, 'Unexpected height duration')
|
||||
}
|
||||
await wait(500)
|
||||
assertNaturalHeight(`expanded-${cycle}`)
|
||||
toggle('lifecycle', false)
|
||||
await wait(500)
|
||||
assertNaturalHeight(`collapsed-${cycle}`)
|
||||
assert(Math.abs(lifecycle().getBoundingClientRect().height - initial) < 1, 'Collapsed height drift')
|
||||
assert(lifecycle().querySelectorAll('.fcb-lifecycle-row').length === 3, 'Unexpected collapsed rows')
|
||||
}
|
||||
toggle('lifecycle', true)
|
||||
await wait(500)
|
||||
toggle('retrieval', true)
|
||||
await wait(500)
|
||||
const panel = document.querySelector('.fcb-retrieval-panel')
|
||||
assert(panel && panel.getBoundingClientRect().height > 0, 'Retrieval panel is hidden')
|
||||
assert(panel.querySelectorAll('.font-medium').length > 0, 'Missing retrieval records')
|
||||
assert(getComputedStyle(panel).transform === 'none', 'Retrieval records translate vertically')
|
||||
assertNaturalHeight('retrieval-expanded')
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const before = panel.getBoundingClientRect().height
|
||||
toggle('retrieval', i % 2 !== 0)
|
||||
await wait(60)
|
||||
const after = panel.getBoundingClientRect().height
|
||||
assert(i % 2 === 0 ? after <= before : after >= before, 'Reversal jumps in the wrong direction')
|
||||
}
|
||||
await wait(500)
|
||||
assertNaturalHeight('rapid-retrieval-reversal')
|
||||
for (let i = 0; i < 6; i++) {
|
||||
toggle('lifecycle', i % 2 !== 0)
|
||||
await wait(60)
|
||||
}
|
||||
await wait(500)
|
||||
assertNaturalHeight('rapid-lifecycle-reversal')
|
||||
toggle('retrieval', false)
|
||||
await wait(500)
|
||||
assert(getComputedStyle(document.querySelector('.fcb-retrieval-panel')).display === 'none', 'Retrieval panel remains visible')
|
||||
assertNaturalHeight('retrieval-collapsed')
|
||||
toggle('lifecycle', false)
|
||||
await wait(500)
|
||||
assertNaturalHeight('final-collapsed')
|
||||
return results
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { createDetailMotion } from '../src/utils/detailMotion.ts'
|
||||
|
||||
class FakeAnimation extends EventTarget {
|
||||
cancelled = false
|
||||
cancel() { this.cancelled = true; this.dispatchEvent(new Event('cancel')) }
|
||||
finish() { this.dispatchEvent(new Event('finish')) }
|
||||
}
|
||||
class FakeElement {
|
||||
animations = []
|
||||
animate(frames, options) {
|
||||
const animation = new FakeAnimation()
|
||||
Object.assign(animation, { frames, options })
|
||||
this.animations.push(animation)
|
||||
return animation
|
||||
}
|
||||
getAnimations() { return this.animations.filter(a => !a.cancelled) }
|
||||
}
|
||||
const frames = [{ height: '186px' }, { height: '429px' }]
|
||||
|
||||
test('completed height effects are removed so content can shrink and nested records can grow', () => {
|
||||
const motion = createDetailMotion(() => false)
|
||||
const element = new FakeElement()
|
||||
let done = 0
|
||||
motion.play(element, frames, { duration: 420 }, () => done++)
|
||||
element.animations[0].finish()
|
||||
assert.equal(done, 1)
|
||||
assert.equal(element.getAnimations().length, 0)
|
||||
})
|
||||
test('rapid reversal finishes the previous transition once and ignores its stale finish event', () => {
|
||||
const motion = createDetailMotion(() => false)
|
||||
const element = new FakeElement()
|
||||
let first = 0, second = 0
|
||||
motion.play(element, frames, {}, () => first++)
|
||||
const old = element.animations[0]
|
||||
motion.play(element, frames.toReversed(), {}, () => second++)
|
||||
old.finish()
|
||||
assert.equal(first, 1)
|
||||
assert.equal(second, 0)
|
||||
assert.equal(element.getAnimations().length, 1)
|
||||
element.animations[1].finish()
|
||||
assert.equal(second, 1)
|
||||
assert.equal(element.getAnimations().length, 0)
|
||||
})
|
||||
test('explicit cancellation removes effects and calls completion only once', () => {
|
||||
const motion = createDetailMotion(() => false)
|
||||
const element = new FakeElement()
|
||||
let done = 0
|
||||
motion.play(element, frames, {}, () => done++)
|
||||
motion.cancel(element)
|
||||
motion.cancel(element)
|
||||
element.animations[0].finish()
|
||||
assert.equal(done, 1)
|
||||
assert.equal(element.getAnimations().length, 0)
|
||||
})
|
||||
test('reduced motion skips animations and still completes', () => {
|
||||
const motion = createDetailMotion(() => true)
|
||||
const element = new FakeElement()
|
||||
let done = 0
|
||||
motion.play(element, frames, {}, () => done++)
|
||||
assert.equal(done, 1)
|
||||
assert.equal(element.animations.length, 0)
|
||||
})
|
||||
test('external cancellation and disposal release all owned animations', () => {
|
||||
const motion = createDetailMotion(() => false)
|
||||
const a = new FakeElement(), b = new FakeElement()
|
||||
let done = 0
|
||||
motion.play(a, frames, {}, () => done++)
|
||||
a.animations[0].cancel()
|
||||
motion.play(a, frames, {}, () => done++)
|
||||
motion.play(b, frames, {}, () => done++)
|
||||
motion.dispose()
|
||||
assert.equal(done, 3)
|
||||
assert.equal(a.getAnimations().length + b.getAnimations().length, 0)
|
||||
})
|
||||
Reference in new issue
Block a user