Avoid task page hidden animation on tab navigation

This commit is contained in:
Codex Agent
2026-01-14 11:25:43 +01:00
parent 6f49564e1b
commit 99a02b991c
3 changed files with 37 additions and 38 deletions

View File

@@ -1,41 +1,25 @@
import { describe, expect, it, vi } from 'vitest';
import { FADE_SCALE, FADE_UP, STAGGER_FAST, getMotionContainerProps, getMotionItemProps, prefersReducedMotion } from '../motion';
import { getMotionContainerPropsForNavigation, STAGGER_FAST } from '../motion';
describe('motion helpers', () => {
it('returns disabled props when motion is off', () => {
const props = getMotionContainerProps(false, STAGGER_FAST);
expect(props.initial).toBe(false);
});
it('returns variants when motion is on', () => {
const containerProps = getMotionContainerProps(true, STAGGER_FAST);
const itemProps = getMotionItemProps(true, FADE_UP);
expect(containerProps.initial).toBe('hidden');
expect(containerProps.animate).toBe('show');
expect(itemProps.variants).toBe(FADE_UP);
});
it('detects reduced motion preference safely', () => {
const original = window.matchMedia;
Object.defineProperty(window, 'matchMedia', {
configurable: true,
value: undefined,
});
expect(prefersReducedMotion()).toBe(false);
Object.defineProperty(window, 'matchMedia', {
configurable: true,
value: vi.fn().mockReturnValue({ matches: true }),
});
expect(prefersReducedMotion()).toBe(true);
Object.defineProperty(window, 'matchMedia', {
configurable: true,
value: original,
describe('getMotionContainerPropsForNavigation', () => {
it('returns initial hidden for POP navigation', () => {
expect(getMotionContainerPropsForNavigation(true, STAGGER_FAST, 'POP')).toEqual({
variants: STAGGER_FAST,
initial: 'hidden',
animate: 'show',
});
});
it('exposes distinct base variants', () => {
expect(FADE_UP).not.toBe(FADE_SCALE);
it('skips initial animation for PUSH navigation', () => {
expect(getMotionContainerPropsForNavigation(true, STAGGER_FAST, 'PUSH')).toEqual({
variants: STAGGER_FAST,
initial: false,
animate: 'show',
});
});
it('disables motion when not enabled', () => {
expect(getMotionContainerPropsForNavigation(false, STAGGER_FAST, 'POP')).toEqual({
initial: false,
});
});
});