Avoid task page hidden animation on tab navigation
This commit is contained in:
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user