@@ -3,8 +3,9 @@ import { render } from "@testing-library/react";
33import "@testing-library/jest-dom/extend-expect" ;
44import { ViewPort } from "../ViewPort" ;
55import { drag } from "./TestUtils" ;
6+ import { ResizeType } from "../../core-types" ;
67
7- const mutateComponent = ( component : React . ReactNode , newProps : Object ) => {
8+ export const mutateComponent = ( component : React . ReactNode , newProps : Object ) => {
89 return React . cloneElement ( component as React . DetailedReactHTMLElement < any , HTMLElement > , newProps ) ;
910} ;
1011
@@ -287,3 +288,73 @@ export const commonResizableTests = (
287288 expect ( size ( style ) ) . toBe ( "150px" ) ;
288289 } ) ;
289290} ;
291+
292+ export const commonPositionedTests = (
293+ name : string ,
294+ component : React . ReactNode ,
295+ size : ( style : CSSStyleDeclaration ) => string | null ,
296+ edge : ( style : CSSStyleDeclaration ) => string | null ,
297+ oppositeEdge : ( style : CSSStyleDeclaration ) => string | null ,
298+ handle : string ,
299+ horizontal : boolean ,
300+ negate : boolean ,
301+ ) => {
302+ test ( `${ name } after resize has correct styles` , async ( ) => {
303+ // arrange
304+ const { container } = render (
305+ < ViewPort >
306+ { mutateComponent ( component , { id : "test" , resizable : [ ResizeType . Left , ResizeType . Top , ResizeType . Bottom , ResizeType . Right ] } ) }
307+ </ ViewPort > ,
308+ ) ;
309+
310+ const resizeHandle = container . querySelector ( `#test-${ handle } ` ) ! ;
311+ const sut = container . querySelector ( "#test" ) ! ;
312+
313+ // act
314+ drag (
315+ resizeHandle ,
316+ sut ,
317+ { width : horizontal ? 50 : 0 , height : horizontal ? 0 : 50 } ,
318+ { width : horizontal ? 150 : 0 , height : horizontal ? 0 : 150 } ,
319+ horizontal ? ( negate ? - 100 : 100 ) : 0 ,
320+ horizontal ? 0 : negate ? - 100 : 100 ,
321+ ) ;
322+
323+ // assert
324+ const style = window . getComputedStyle ( sut ) ;
325+ expect ( size ( style ) ) . toBe ( "calc(100px + -100px)" ) ;
326+ } ) ;
327+
328+ test ( `${ name } subsequent resize has correct styles` , async ( ) => {
329+ // arrange
330+ const { container } = render (
331+ < ViewPort >
332+ { mutateComponent ( component , { id : "test" , resizable : [ ResizeType . Left , ResizeType . Top , ResizeType . Bottom , ResizeType . Right ] } ) }
333+ </ ViewPort > ,
334+ ) ;
335+ const resizeHandle = container . querySelector ( `#test-${ handle } ` ) ! ;
336+ const sut = container . querySelector ( "#test" ) ! ;
337+
338+ // act
339+ drag (
340+ resizeHandle ,
341+ sut ,
342+ { width : horizontal ? 50 : 0 , height : horizontal ? 0 : 50 } ,
343+ { width : horizontal ? 150 : 0 , height : horizontal ? 0 : 150 } ,
344+ horizontal ? ( negate ? - 100 : 100 ) : 0 ,
345+ horizontal ? 0 : negate ? - 100 : 100 ,
346+ ) ;
347+ drag (
348+ resizeHandle ,
349+ sut ,
350+ { width : horizontal ? 150 : 0 , height : horizontal ? 0 : 150 } ,
351+ { width : horizontal ? 50 : 0 , height : horizontal ? 0 : 50 } ,
352+ horizontal ? ( negate ? 100 : - 100 ) : 0 ,
353+ horizontal ? 0 : negate ? 100 : - 100 ,
354+ ) ;
355+
356+ // assert
357+ const style = window . getComputedStyle ( sut ) ;
358+ expect ( size ( style ) ) . toBe ( "100px" ) ;
359+ } ) ;
360+ } ;
0 commit comments