11import { useState } from 'react' ;
22import type { SplitterLayoutPropTypes } from '../..' ;
3- import { Button , Label , SplitterElement , SplitterLayout } from '../..' ;
3+ import { FlexBox , Text , Button , Label , SplitterElement , SplitterLayout } from '../..' ;
44import { cypressPassThroughTestsFactory } from '@/cypress/support/utils' ;
55
66function TestComp ( { vertical, dir } : { vertical : SplitterLayoutPropTypes [ 'vertical' ] ; dir : string } ) {
@@ -107,7 +107,7 @@ describe('SplitterLayout', () => {
107107 ) ;
108108 cy . findByTestId ( 'btn' ) . click ( ) ;
109109 cy . get ( '[role="separator"]' ) . first ( ) . click ( ) ;
110- // fallback click to prevent fuzzyness
110+ // fallback click to prevent flakyness
111111 cy . get ( '[role="separator"]' )
112112 . first ( )
113113 . click ( )
@@ -129,5 +129,133 @@ describe('SplitterLayout', () => {
129129 cy . findByTestId ( 'sl' ) . should ( 'not.be.visible' ) . should ( 'exist' ) ;
130130 } ) ;
131131
132+ [ true , false ] . forEach ( ( vertical ) => {
133+ it ( `controlled width (${ vertical ? 'vertical' : 'horizontal' } )` , ( ) => {
134+ function getMouseMoveArgs ( amount : number ) : [ number , number ] {
135+ return vertical ? [ 0 , amount ] : [ amount , 0 ] ;
136+ }
137+ const resize = cy . spy ( ) . as ( 'resize' ) ;
138+ const TestComp = ( ) => {
139+ const [ size0 , setSize0 ] = useState ( '200px' ) ;
140+ const [ size1 , setSize1 ] = useState ( 200 ) ;
141+ const [ size2 , setSize2 ] = useState ( 'auto' ) ;
142+ const [ size3 , setSize3 ] = useState ( '200px' ) ;
143+ const setter = [ setSize0 , setSize1 , setSize2 , setSize3 ] ;
144+ return (
145+ < >
146+ < SplitterLayout
147+ vertical = { vertical }
148+ style = { { height : '900px' , width : '900px' , backgroundColor : 'black' } }
149+ onResize = { ( e ) => {
150+ resize ( e ) ;
151+ e . areas . forEach ( ( item ) => {
152+ if ( item . area . dataset . index === '1' ) {
153+ setter [ Number ( item . area . dataset . index ) ] ( item . size ) ;
154+ } else {
155+ //@ts -expect-error: supported
156+ setter [ Number ( item . area . dataset . index ) ] ( item . size + 'px' ) ;
157+ }
158+ } ) ;
159+ } }
160+ >
161+ < SplitterElement size = { size0 } data-index = { 0 } style = { { backgroundColor : 'lightcoral' } } >
162+ < FlexBox style = { { height : '100%' , width : '100%' } } alignItems = "Center" justifyContent = "Center" >
163+ < Text > Content 1</ Text >
164+ </ FlexBox >
165+ </ SplitterElement >
166+ < SplitterElement size = { size1 } data-index = { 1 } style = { { backgroundColor : 'lightblue' } } >
167+ < FlexBox style = { { height : '100%' , width : '100%' } } alignItems = "Center" justifyContent = "Center" >
168+ < Text style = { { whiteSpace : 'pre-line' } } > { `Content 2
169+ with
170+ multi
171+ lines` } </ Text >
172+ </ FlexBox >
173+ </ SplitterElement >
174+ < SplitterElement size = { 'auto' } data-index = { 2 } style = { { backgroundColor : 'lightgreen' } } >
175+ < FlexBox style = { { height : '100%' , width : '100%' } } alignItems = "Center" justifyContent = "Center" >
176+ < Text >
177+ Content 3 with long text: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
178+ eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et
179+ accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est
180+ Lorem ipsum dolor sit amet.
181+ </ Text >
182+ </ FlexBox >
183+ </ SplitterElement >
184+ < SplitterElement size = { size3 } data-index = { 3 } style = { { backgroundColor : 'lightgoldenrodyellow' } } >
185+ < FlexBox style = { { height : '100%' , width : '100%' } } alignItems = "Center" justifyContent = "Center" >
186+ < Text > Content 4</ Text >
187+ </ FlexBox >
188+ </ SplitterElement >
189+ </ SplitterLayout >
190+ < span data-testid = "0" > { size0 } </ span >
191+ < br />
192+ < span data-testid = "1" > { size1 } </ span >
193+ < br />
194+ < span data-testid = "2" > { size2 } </ span >
195+ < br />
196+ < span data-testid = "3" > { size3 } </ span >
197+ </ >
198+ ) ;
199+ } ;
200+
201+ cy . mount ( < TestComp /> ) ;
202+
203+ cy . get ( '@resize' ) . should ( 'not.have.been.called' ) ;
204+ cy . findAllByRole ( 'separator' )
205+ . eq ( 0 )
206+ . realMouseDown ( { position : 'center' } )
207+ . realMouseMove ( ...getMouseMoveArgs ( - 100 ) , {
208+ position : 'center' ,
209+ scrollBehavior : false ,
210+ } )
211+ . realMouseUp ( { position : 'center' } ) ;
212+
213+ cy . findByTestId ( '0' )
214+ . invoke ( 'text' )
215+ . then ( ( txt ) => parseInt ( txt , 10 ) )
216+ . should ( 'be.within' , 99 , 101 ) ;
217+ cy . findByTestId ( '1' )
218+ . invoke ( 'text' )
219+ . then ( ( txt ) => parseInt ( txt , 10 ) )
220+ . should ( 'be.within' , 299 , 301 ) ;
221+ cy . findByTestId ( '2' ) . should ( 'have.text' , 'auto' ) ;
222+ cy . findByTestId ( '3' ) . invoke ( 'text' ) . should ( 'equal' , '200px' ) ;
223+
224+ cy . findAllByRole ( 'separator' ) . eq ( 0 ) . realMouseDown ( { position : 'center' } ) ;
225+ // drag across bounding box
226+ cy . get ( 'body' )
227+ . realMouseMove ( ...getMouseMoveArgs ( 300 ) , {
228+ position : 'center' ,
229+ scrollBehavior : false ,
230+ } )
231+ . realMouseUp ( { position : 'center' } ) ;
232+
233+ cy . wait ( 50 ) ;
234+ cy . findByTestId ( '0' )
235+ . invoke ( 'text' )
236+ . then ( ( txt ) => parseInt ( txt , 10 ) )
237+ . should ( 'be.within' , 383 , 385 ) ;
238+ cy . findByTestId ( '1' )
239+ . invoke ( 'text' )
240+ . then ( ( txt ) => parseInt ( txt , 10 ) )
241+ . should ( 'be.within' , 15 , 17 ) ;
242+ cy . findByTestId ( '2' ) . should ( 'have.text' , 'auto' ) ;
243+ cy . findByTestId ( '3' ) . invoke ( 'text' ) . should ( 'equal' , '200px' ) ;
244+
245+ cy . findAllByRole ( 'separator' ) . eq ( 2 ) . click ( ) . realPress ( 'ArrowDown' ) . realPress ( 'ArrowDown' ) . realPress ( 'ArrowDown' ) ;
246+
247+ cy . findByTestId ( '0' )
248+ . invoke ( 'text' )
249+ . then ( ( txt ) => parseInt ( txt , 10 ) )
250+ . should ( 'be.within' , 383 , 385 ) ;
251+ cy . findByTestId ( '1' )
252+ . invoke ( 'text' )
253+ . then ( ( txt ) => parseInt ( txt , 10 ) )
254+ . should ( 'be.within' , 15 , 17 ) ;
255+ cy . findByTestId ( '2' ) . should ( 'have.text' , '360px' ) ;
256+ cy . findByTestId ( '3' ) . should ( 'have.text' , '140px' ) ;
257+ } ) ;
258+ } ) ;
259+
132260 cypressPassThroughTestsFactory ( SplitterLayout , { children : < SplitterElement > Content</ SplitterElement > } ) ;
133261} ) ;
0 commit comments