ba718e3d4b
使用独立FLIP快照层和Web Animations统一动画收尾 统一分类导航并保留滚轮节流和各画布视口 修复快照缩放与悬停导致的终点偏移 补充动画回归测试并更新资源画本技术文档
106 lines
2.9 KiB
TypeScript
106 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
initialResourceBookState,
|
|
resourceBookReducer,
|
|
resourceBookSceneCategory,
|
|
resourceBookShowsOverviewCards,
|
|
} from '../src/view/project-development/resourceBookModel';
|
|
|
|
describe('resource book state machine', () => {
|
|
it('keeps overview titles and preview cards visible on the steady main canvas', () => {
|
|
expect(resourceBookShowsOverviewCards(initialResourceBookState)).toBe(true);
|
|
});
|
|
|
|
it('commits the child target immediately and only keeps the motion phase transient', () => {
|
|
const entering = resourceBookReducer(initialResourceBookState, {
|
|
type: 'open-category',
|
|
category: 'document',
|
|
token: 1,
|
|
});
|
|
expect(entering).toMatchObject({
|
|
view: 'child',
|
|
category: 'document',
|
|
phase: 'entering',
|
|
token: 1,
|
|
});
|
|
expect(resourceBookSceneCategory(entering)).toBe('document');
|
|
});
|
|
|
|
it('retargets directly from one child canvas to another', () => {
|
|
const current = resourceBookReducer(initialResourceBookState, {
|
|
type: 'open-category',
|
|
category: 'document',
|
|
token: 1,
|
|
});
|
|
const switching = resourceBookReducer(current, {
|
|
type: 'open-category',
|
|
category: 'art',
|
|
token: 2,
|
|
});
|
|
expect(switching).toMatchObject({
|
|
view: 'child',
|
|
category: 'art',
|
|
phase: 'entering',
|
|
});
|
|
expect(resourceBookSceneCategory(switching)).toBe('art');
|
|
});
|
|
|
|
it('marks a return to the main canvas separately from a child enter transition', () => {
|
|
const entering = resourceBookReducer(initialResourceBookState, {
|
|
type: 'open-category',
|
|
category: 'document',
|
|
token: 1,
|
|
});
|
|
const returning = resourceBookReducer(entering, {
|
|
type: 'return-to-main',
|
|
token: 2,
|
|
});
|
|
expect(returning).toMatchObject({
|
|
view: 'main',
|
|
category: null,
|
|
phase: 'returning-main',
|
|
});
|
|
});
|
|
|
|
it('lets an explicit collapse cancel an in-flight child switch', () => {
|
|
const entering = resourceBookReducer(initialResourceBookState, {
|
|
type: 'open-category',
|
|
category: 'document',
|
|
token: 1,
|
|
});
|
|
const switching = resourceBookReducer(entering, {
|
|
type: 'open-category',
|
|
category: 'art',
|
|
token: 2,
|
|
});
|
|
const main = resourceBookReducer(switching, {
|
|
type: 'return-to-main',
|
|
token: 3,
|
|
});
|
|
|
|
expect(main).toMatchObject({
|
|
view: 'main',
|
|
category: null,
|
|
phase: 'returning-main',
|
|
token: 3,
|
|
});
|
|
});
|
|
|
|
it('ignores stale transition callbacks', () => {
|
|
const entering = resourceBookReducer(initialResourceBookState, {
|
|
type: 'open-category',
|
|
category: 'document',
|
|
token: 1,
|
|
});
|
|
const switched = resourceBookReducer(entering, {
|
|
type: 'open-category',
|
|
category: 'art',
|
|
token: 2,
|
|
});
|
|
expect(
|
|
resourceBookReducer(switched, { type: 'finish-transition', token: 1 }),
|
|
).toEqual(switched);
|
|
});
|
|
});
|