@@ -3,7 +3,7 @@ import { render } from '@testing-library/react';
33
44import type { PresenceMotionFn } from '../types' ;
55import { createPresenceComponent } from './createPresenceComponent' ;
6- import { overridePresenceMotion , createPresenceComponentVariant } from './createPresenceComponentVariant' ;
6+ import { createPresenceComponentVariant } from './createPresenceComponentVariant' ;
77
88jest . mock ( './createPresenceComponent' , ( ) => {
99 const module = jest . requireActual ( './createPresenceComponent' ) ;
@@ -14,79 +14,36 @@ jest.mock('./createPresenceComponent', () => {
1414 } ;
1515} ) ;
1616
17- const PRESENCE_MOTION : PresenceMotionFn < { direction : 'start' | 'end' } > = ( ) => ( {
18- enter : { keyframes : [ ] , duration : 1000 , easing : 'linear' } ,
19- exit : { keyframes : [ ] , duration : 1000 , easing : 'linear' } ,
17+ const PRESENCE_MOTION : PresenceMotionFn < { outOpacity ?: number ; duration ?: number ; easing ?: string } > = ( {
18+ outOpacity = 0 ,
19+ duration = 1000 ,
20+ easing = 'linear' ,
21+ } ) => ( {
22+ enter : [ { keyframes : [ { opacity : outOpacity } , { opacity : 1 } ] , duration, easing } ] ,
23+ exit : [ { keyframes : [ { opacity : 1 } , { opacity : outOpacity } ] , duration, easing } ] ,
2024} ) ;
21- const PRESENCE_COMPONENT = createPresenceComponent < { direction : 'start' | 'end' } > ( PRESENCE_MOTION ) ;
25+ const PRESENCE_COMPONENT = createPresenceComponent ( PRESENCE_MOTION ) ;
2226
2327const MOTION_PARAMS = {
2428 element : document . createElement ( 'div' ) ,
25- direction : 'start' as const ,
2629} ;
2730
28- describe ( 'overridePresenceMotion' , ( ) => {
29- it ( 'overrides "all"' , ( ) => {
30- expect (
31- overridePresenceMotion ( PRESENCE_MOTION , { all : { duration : 500 , easing : 'ease-in-out' } } ) ( MOTION_PARAMS ) ,
32- ) . toEqual ( {
33- enter : {
34- duration : 500 ,
35- easing : 'ease-in-out' ,
36- keyframes : [ ] ,
37- } ,
38- exit : {
39- duration : 500 ,
40- easing : 'ease-in-out' ,
41- keyframes : [ ] ,
42- } ,
43- } ) ;
44- } ) ;
45-
46- it ( 'overrides "enter"' , ( ) => {
47- expect (
48- overridePresenceMotion ( PRESENCE_MOTION , { enter : { duration : 500 , easing : 'ease-in-out' } } ) ( MOTION_PARAMS ) ,
49- ) . toEqual ( {
50- enter : {
51- duration : 500 ,
52- easing : 'ease-in-out' ,
53- keyframes : [ ] ,
54- } ,
55- exit : {
56- keyframes : [ ] ,
57- duration : 1000 ,
58- easing : 'linear' ,
59- } ,
60- } ) ;
61- } ) ;
62-
63- it ( 'overrides "exit"' , ( ) => {
64- expect (
65- overridePresenceMotion ( PRESENCE_MOTION , { exit : { duration : 500 , easing : 'ease-in-out' } } ) ( MOTION_PARAMS ) ,
66- ) . toEqual ( {
67- enter : {
68- keyframes : [ ] ,
69- duration : 1000 ,
70- easing : 'linear' ,
71- } ,
72- exit : {
73- duration : 500 ,
74- easing : 'ease-in-out' ,
75- keyframes : [ ] ,
76- } ,
77- } ) ;
78- } ) ;
79- } ) ;
80-
8131describe ( 'createPresenceComponentVariant' , ( ) => {
82- it ( 'appends override to the original motion' , ( ) => {
32+ it ( 'overrides motion parameters used within motion atom arrays' , ( ) => {
33+ // variant params overriding the default motion params
34+ const outOpacity = 0.3 ;
35+ const duration = 500 ;
36+ const easing = 'ease-in-out' ;
37+
8338 const PresenceVariant = createPresenceComponentVariant ( PRESENCE_COMPONENT , {
84- all : { duration : 500 , easing : 'ease-in-out' } ,
39+ outOpacity,
40+ duration,
41+ easing,
8542 } ) ;
8643 const overrideFn = ( createPresenceComponent as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
8744
8845 const { getByText } = render (
89- < PresenceVariant direction = "start" visible >
46+ < PresenceVariant visible >
9047 < div > Hello world!</ div >
9148 </ PresenceVariant > ,
9249 ) ;
@@ -99,16 +56,20 @@ describe('createPresenceComponentVariant', () => {
9956
10057 expect ( overrideFn ) . toBeInstanceOf ( Function ) ;
10158 expect ( overrideFn ( MOTION_PARAMS ) ) . toEqual ( {
102- enter : {
103- duration : 500 ,
104- easing : 'ease-in-out' ,
105- keyframes : [ ] ,
106- } ,
107- exit : {
108- duration : 500 ,
109- easing : 'ease-in-out' ,
110- keyframes : [ ] ,
111- } ,
59+ enter : [
60+ {
61+ duration,
62+ easing,
63+ keyframes : [ { opacity : outOpacity } , { opacity : 1 } ] ,
64+ } ,
65+ ] ,
66+ exit : [
67+ {
68+ duration,
69+ easing,
70+ keyframes : [ { opacity : 1 } , { opacity : outOpacity } ] ,
71+ } ,
72+ ] ,
11273 } ) ;
11374 } ) ;
11475} ) ;
0 commit comments