@@ -9,7 +9,8 @@ describe("Pinch [Base]", () => {
99 expect ( content . style . transform ) . toBe ( "translate(0px, 0px) scale(1)" ) ;
1010 pinch ( { value : 1.5 } ) ;
1111 await waitFor ( ( ) => {
12- expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 1.5 , 1 ) ;
12+ expect ( content . style . transform ) . toBe ( "translate(0px, 0px) scale(1.5)" ) ;
13+ expect ( ref . current ?. instance . state . scale ) . toBe ( 1.5 ) ;
1314 } ) ;
1415 } ) ;
1516 it ( "should zoom to the position of midpoint" , async ( ) => {
@@ -22,55 +23,41 @@ describe("Pinch [Base]", () => {
2223 expect ( ref . current ?. instance . state . positionX ) . toBeLessThan ( 0 ) ;
2324 expect ( ref . current ?. instance . state . positionY ) . toBeLessThan ( 0 ) ;
2425 } ) ;
25- it ( "should not exceed maxScale" , async ( ) => {
26- const { ref, pinch } = renderApp ( { maxScale : 3 } ) ;
27-
28- pinch ( { value : 5 } ) ;
29- await waitFor ( ( ) => {
30- expect ( ref . current ?. instance . state . scale ) . toBeLessThanOrEqual ( 3 ) ;
31- } ) ;
32- } ) ;
33- it ( "should zoom out via setTransform after pinch in" , async ( ) => {
26+ it ( "should zoom out from position of midpoint" , async ( ) => {
3427 const { ref, pinch } = renderApp ( ) ;
3528
3629 pinch ( { value : 2 } ) ;
3730 await waitFor ( ( ) => {
3831 expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 2 , 0 ) ;
3932 } ) ;
4033
41- ref . current ! . setTransform ( 0 , 0 , 1 , 0 ) ;
42- expect ( ref . current ?. instance . state . scale ) . toBe ( 1 ) ;
34+ pinch ( { value : 1 , center : [ 100 , 100 ] } ) ;
35+ await waitFor ( ( ) => {
36+ expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 1 , 0 ) ;
37+ } ) ;
4338 } ) ;
44- it ( "should keep position within bounds after zooming" , async ( ) => {
39+ it ( "should return to bounds after zooming out " , async ( ) => {
4540 const { ref, pinch } = renderApp ( {
4641 limitToBounds : true ,
4742 disablePadding : true ,
43+ minScale : 0.5 ,
4844 } ) ;
4945
50- pinch ( { value : 2 , center : [ 250 , 250 ] } ) ;
46+ pinch ( { value : 0.5 } ) ;
5147 await waitFor ( ( ) => {
52- expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 2 , 0 ) ;
48+ expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 0.5 , 0 ) ;
5349 } ) ;
54- expect ( ref . current ?. instance . state . positionX ) . toBeGreaterThanOrEqual (
55- - 500 ,
56- ) ;
57- expect ( ref . current ?. instance . state . positionY ) . toBeGreaterThanOrEqual (
58- - 500 ,
59- ) ;
50+ expect ( ref . current ?. instance . state . positionX ) . toBeGreaterThanOrEqual ( 0 ) ;
51+ expect ( ref . current ?. instance . state . positionY ) . toBeGreaterThanOrEqual ( 0 ) ;
6052 } ) ;
6153 } ) ;
62-
6354 describe ( "When content bigger than wrapper" , ( ) => {
64- const bigContent = {
65- wrapperWidth : "200px" ,
66- wrapperHeight : "200px" ,
67- contentWidth : "400px" ,
68- contentHeight : "400px" ,
69- } as const ;
70-
71- it ( "should center the content with centerOnInit" , async ( ) => {
55+ it ( "should center the content" , async ( ) => {
7256 const { ref } = renderApp ( {
73- ...bigContent ,
57+ wrapperWidth : "200px" ,
58+ wrapperHeight : "200px" ,
59+ contentWidth : "400px" ,
60+ contentHeight : "400px" ,
7461 centerOnInit : true ,
7562 } ) ;
7663
@@ -80,15 +67,26 @@ describe("Pinch [Base]", () => {
8067 } ) ;
8168 } ) ;
8269 it ( "should change transform scale" , async ( ) => {
83- const { ref, content, pinch } = renderApp ( bigContent ) ;
70+ const { ref, content, pinch } = renderApp ( {
71+ wrapperWidth : "200px" ,
72+ wrapperHeight : "200px" ,
73+ contentWidth : "400px" ,
74+ contentHeight : "400px" ,
75+ } ) ;
76+
8477 expect ( content . style . transform ) . toBe ( "translate(0px, 0px) scale(1)" ) ;
8578 pinch ( { value : 1.5 } ) ;
8679 await waitFor ( ( ) => {
87- expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 1.5 , 1 ) ;
80+ expect ( ref . current ?. instance . state . scale ) . toBe ( 1.5 ) ;
8881 } ) ;
8982 } ) ;
9083 it ( "should zoom to the position of midpoint" , async ( ) => {
91- const { ref, pinch } = renderApp ( bigContent ) ;
84+ const { ref, pinch } = renderApp ( {
85+ wrapperWidth : "200px" ,
86+ wrapperHeight : "200px" ,
87+ contentWidth : "400px" ,
88+ contentHeight : "400px" ,
89+ } ) ;
9290
9391 pinch ( { value : 2 , center : [ 100 , 100 ] } ) ;
9492 await waitFor ( ( ) => {
@@ -97,67 +95,41 @@ describe("Pinch [Base]", () => {
9795 expect ( ref . current ?. instance . state . positionX ) . toBeLessThan ( 0 ) ;
9896 expect ( ref . current ?. instance . state . positionY ) . toBeLessThan ( 0 ) ;
9997 } ) ;
100- it ( "should clamp to maxScale on big content " , async ( ) => {
101- const { ref, pinch } = renderApp ( { ... bigContent , maxScale : 3 } ) ;
102-
103- pinch ( { value : 10 , center : [ 100 , 100 ] } ) ;
104- await waitFor ( ( ) => {
105- expect ( ref . current ?. instance . state . scale ) . toBeLessThanOrEqual ( 3 ) ;
98+ it ( "should zoom out from position of midpoint " , async ( ) => {
99+ const { ref, pinch } = renderApp ( {
100+ wrapperWidth : "200px" ,
101+ wrapperHeight : "200px" ,
102+ contentWidth : "400px" ,
103+ contentHeight : "400px" ,
106104 } ) ;
107- } ) ;
108- it ( "should zoom out via setTransform after pinch in on big content" , async ( ) => {
109- const { ref, pinch } = renderApp ( bigContent ) ;
110105
111106 pinch ( { value : 2 } ) ;
112107 await waitFor ( ( ) => {
113108 expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 2 , 0 ) ;
114109 } ) ;
115110
116- ref . current ! . setTransform ( 0 , 0 , 1 , 0 ) ;
117- expect ( ref . current ?. instance . state . scale ) . toBe ( 1 ) ;
111+ pinch ( { value : 1 , center : [ 100 , 100 ] } ) ;
112+ await waitFor ( ( ) => {
113+ expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 1 , 0 ) ;
114+ } ) ;
118115 } ) ;
119- it ( "should keep position within bounds after zooming" , async ( ) => {
116+ it ( "should return to bounds after zooming out " , async ( ) => {
120117 const { ref, pinch } = renderApp ( {
121- ...bigContent ,
118+ wrapperWidth : "200px" ,
119+ wrapperHeight : "200px" ,
120+ contentWidth : "400px" ,
121+ contentHeight : "400px" ,
122122 limitToBounds : true ,
123123 disablePadding : true ,
124+ minScale : 0.5 ,
124125 } ) ;
125126
126- pinch ( { value : 2 , center : [ 100 , 100 ] } ) ;
127+ pinch ( { value : 0.5 } ) ;
127128 await waitFor ( ( ) => {
128- expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 2 , 0 ) ;
129- } ) ;
130- expect ( ref . current ?. instance . state . positionX ) . toBeGreaterThanOrEqual (
131- - 600 ,
132- ) ;
133- expect ( ref . current ?. instance . state . positionY ) . toBeGreaterThanOrEqual (
134- - 600 ,
135- ) ;
136- } ) ;
137- } ) ;
138-
139- describe ( "When pinch is disabled" , ( ) => {
140- it ( "should not change scale" , async ( ) => {
141- const { ref, content } = renderApp ( {
142- pinch : { disabled : true } ,
143- } ) ;
144- expect ( content . style . transform ) . toBe ( "translate(0px, 0px) scale(1)" ) ;
145- expect ( ref . current ?. instance . state . scale ) . toBe ( 1 ) ;
146- } ) ;
147- } ) ;
148-
149- describe ( "When pinch callbacks are provided" , ( ) => {
150- it ( "should trigger onPinchStart and onPinchStop" , async ( ) => {
151- const onPinchStart = jest . fn ( ) ;
152- const onPinchStop = jest . fn ( ) ;
153- const { pinch } = renderApp ( {
154- onPinchStart,
155- onPinchStop,
129+ expect ( ref . current ?. instance . state . scale ) . toBeCloseTo ( 0.5 , 0 ) ;
156130 } ) ;
157-
158- pinch ( { value : 1.5 } ) ;
159- expect ( onPinchStart ) . toHaveBeenCalled ( ) ;
160- expect ( onPinchStop ) . toHaveBeenCalled ( ) ;
131+ expect ( ref . current ?. instance . state . positionX ) . toBeGreaterThanOrEqual ( 0 ) ;
132+ expect ( ref . current ?. instance . state . positionY ) . toBeGreaterThanOrEqual ( 0 ) ;
161133 } ) ;
162134 } ) ;
163135} ) ;
0 commit comments