From 23de053e129247f9babffa0ca30769c5de0e409b Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:26:15 +0800 Subject: [PATCH] Import apps/android/tests/sheet-transition.test.ts --- apps/android/tests/sheet-transition.test.ts | 55 +++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 apps/android/tests/sheet-transition.test.ts diff --git a/apps/android/tests/sheet-transition.test.ts b/apps/android/tests/sheet-transition.test.ts new file mode 100644 index 0000000..766617c --- /dev/null +++ b/apps/android/tests/sheet-transition.test.ts @@ -0,0 +1,55 @@ +import { describe, expect, it } from 'vitest' +import { + motionTokens, + nextSheetPhase, + sheetPhaseDuration, + type SheetPhase, +} from '../src/ui/motion' + +const PHASES: SheetPhase[] = ['unmounted', 'opening', 'open', 'closing'] + +describe('sheet visibility state machine', () => { + it('enters from settled states and never skips the closing phase', () => { + expect(nextSheetPhase('unmounted', true)).toBe('opening') + expect(nextSheetPhase('closing', true)).toBe('opening') + expect(nextSheetPhase('opening', false)).toBe('closing') + expect(nextSheetPhase('open', false)).toBe('closing') + expect(nextSheetPhase('closing', false)).toBe('closing') + expect(nextSheetPhase('unmounted', false)).toBe('unmounted') + }) + + it('keeps in-flight phases stable while the target state is unchanged', () => { + expect(nextSheetPhase('opening', true)).toBe('opening') + expect(nextSheetPhase('open', true)).toBe('open') + }) + + it('settles every phase into a terminal state under repeated toggles', () => { + const run = (sequence: boolean[]): SheetPhase => { + let phase: SheetPhase = 'unmounted' + for (const visible of sequence) { + phase = nextSheetPhase(phase, visible) + // Model the animation callback that settles in-flight phases. + if (phase === 'opening' && !visible) phase = 'closing' + } + return phase + } + // Rapid open/close bursts always end in a state the sheet can render. + expect(run([true, false, true, false, true])).toBe('opening') + expect(run([true, true, false, false])).toBe('closing') + expect(run([])).toBe('unmounted') + // Every phase in the matrix has a defined successor. + for (const phase of PHASES) { + for (const visible of [true, false]) { + expect(PHASES).toContain(nextSheetPhase(phase, visible)) + } + } + }) + + it('uses a slower entry than exit, and the same 150ms cap for reduced motion', () => { + expect(sheetPhaseDuration('opening', false)).toBe(motionTokens.duration.sheet) + expect(sheetPhaseDuration('closing', false)).toBe(motionTokens.duration.sheetExit) + expect(sheetPhaseDuration('opening', false)).toBeGreaterThan(sheetPhaseDuration('closing', false)) + expect(sheetPhaseDuration('opening', true)).toBe(motionTokens.duration.reduced) + expect(sheetPhaseDuration('closing', true)).toBe(motionTokens.duration.reduced) + }) +})