Files
Jyotisha/frontend/tests/motion-shell-2331.test.ts
ClaudeandClaude Opus 5.5 7cced78e28 fix(motion): the sidebar toggle settles its contents with transform/opacity and takes its width in one layout; width var and flag live on the slot (BUG-2332)
Animating flex-basis/width (BUG-2331) re-laid-out and re-styled the whole page every
frame on long reports; the custom property on .shell-frame re-styled every element.
Measured 1440x900, 400-section page, 4 toggles: frames >20ms 5-12 -> 0, layout
0.42s -> 0.04s, style recalc 0.15s -> 0.01s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-24 20:42:51 +08:00

69 lines
3.5 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
// BUG-2331: the app shell (sidebar, login, onboarding, account dialogs, points, admin) moves
// on the BUG-2327 tokens only, never with a raw duration, never with overshoot.
const css = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8");
const read = (path: string) => readFileSync(new URL(`../src/${path}`, import.meta.url), "utf8");
const marker = "/* BUG-2331 motion — shell.";
const block = css.slice(css.indexOf(marker));
test("the shell block exists and uses only motion tokens", () => {
assert.ok(css.includes(marker), "the BUG-2331 block is appended to globals.css");
const durations = block.match(/\b\d+(?:\.\d+)?m?s\b/g) ?? [];
assert.deepEqual(durations, [], `no raw durations in the shell block: ${durations.join(", ")}`);
assert.doesNotMatch(block, /cubic-bezier\(/, "curves come from the --ease-* tokens");
});
test("the shell block animates only opacity and transform", () => {
const props = [...block.matchAll(/transition(?:-property)?:\s*([^;]+);/g)].map((m) => m[1]);
for (const value of props) {
const named = value.split(",").map((part) => part.trim().split(/\s+/)[0]);
for (const name of named) {
assert.ok(
["opacity", "transform", "background-color", "box-shadow", "color"].includes(name),
`unexpected transition property ${name}`,
);
}
}
// 原值:允许侧栏列 flex-basis/width 过渡;新值:不允许;原因:BUG-2332 长页面整页重算样式。
assert.doesNotMatch(block, /transition[^;]*\b(width|flex-basis)\b/);
assert.match(block, /\.shell-sidebar-slot\[data-shell-gliding="open"\] > :not\(\.shell-resize-handle\) \{ animation: shell-sidebar-open var\(--motion-standard\)/);
assert.match(block, /@keyframes shell-sidebar-open \{ from \{ opacity: 0; transform: translateX\(-12px\); \}/);
});
test("the sidebar column glides only on toggle, never while the edge is dragged", () => {
const frame = read("components/shell-frame.tsx");
assert.match(frame, /className="shell-sidebar-slot"\s*data-shell-gliding=\{gliding \?\? undefined\}/);
assert.match(frame, /if \(!desktop \|\| dragging\.current\) return undefined;/);
assert.match(frame, /MOTION_MS\.standard/);
});
test("a dragged conversation row keeps no transform transition", () => {
const rule = block.match(/\.sidebar-session \{ transition-property: ([^;]+);/);
assert.ok(rule);
assert.doesNotMatch(rule[1], /transform/);
});
test("redeem success settles without overshoot", () => {
assert.match(block, /\.redeem-success-dialog \{ animation: redeem-success-pop var\(--motion-emphasis\) var\(--ease-out\) both; \}/);
});
test("a changed points number ticks from the side it moved; the first render does not", () => {
const source = read("components/credits-value.tsx");
assert.match(source, /if \(previous\.current === value\) return;/);
assert.match(source, /data-credits-tick=\{tick \? tick\.direction : undefined\}/);
assert.match(read("components/app-sidebar.tsx"), /<CreditsValue value=\{account\.credits\}/);
assert.match(read("components/billing-balance.tsx"), /<CreditsValue value=\{credits\}/);
});
test("admin antd motion uses the same tokens", () => {
const admin = read("components/admin/admin-app.tsx");
for (const token of ["motionDurationFast", "motionDurationMid", "motionDurationSlow", "motionEaseOut", "motionEaseOutBack"]) {
assert.match(admin, new RegExp(`${token}: `), token);
}
assert.match(admin, /motionEaseOutBack: `cubic-bezier\(\$\{MOTION_EASE\.out\.join/);
});