@@ -209,6 +209,29 @@ describe('Splitter', () => {
209209
210210 expect ( style . cursor ) . to . equal ( 'row-resize' ) ;
211211 } ) ;
212+
213+ //TODO: this is the behavior in Angular - to discuss
214+ it ( 'should reset sizes when pane is initially collapsed.' , async ( ) => {
215+ splitter = await fixture < IgcSplitterComponent > (
216+ createSplitterWithCollapsedPane ( )
217+ ) ;
218+ await elementUpdated ( splitter ) ;
219+
220+ expect ( splitter . startSize ) . to . equal ( 'auto' ) ;
221+ expect ( splitter . endSize ) . to . equal ( 'auto' ) ;
222+ } ) ;
223+
224+ it ( 'should reset sizes when pane is runtime collapsed.' , async ( ) => {
225+ splitter . startSize = '200px' ;
226+ splitter . endSize = '30%' ;
227+ await elementUpdated ( splitter ) ;
228+
229+ splitter . toggle ( 'start' ) ;
230+ await elementUpdated ( splitter ) ;
231+
232+ expect ( splitter . startSize ) . to . equal ( 'auto' ) ;
233+ expect ( splitter . endSize ) . to . equal ( 'auto' ) ;
234+ } ) ;
212235 } ) ;
213236
214237 describe ( 'Properties' , ( ) => {
@@ -307,26 +330,6 @@ describe('Splitter', () => {
307330
308331 // TODO: test with drag; add constraints to second pane
309332 } ) ;
310-
311- it ( 'should handle mixed px and % constraints' , async ( ) => {
312- const mixedConstraintSplitter = await fixture < IgcSplitterComponent > (
313- createTwoPanesWithSizesAndConstraints ( {
314- startMinSize : '100px' ,
315- startMaxSize : '50%' ,
316- } )
317- ) ;
318- await elementUpdated ( mixedConstraintSplitter ) ;
319-
320- const startPane = getSplitterPart ( mixedConstraintSplitter , 'start-pane' ) ;
321- const style = getComputedStyle ( startPane ) ;
322-
323- expect ( mixedConstraintSplitter . startMinSize ) . to . equal ( '100px' ) ;
324- expect ( mixedConstraintSplitter . startMaxSize ) . to . equal ( '50%' ) ;
325- expect ( style . minWidth ) . to . equal ( '100px' ) ;
326- expect ( style . maxWidth ) . to . equal ( '50%' ) ;
327-
328- // TODO: test with drag
329- } ) ;
330333 } ) ;
331334
332335 describe ( 'Methods, Events & Interactions' , ( ) => {
@@ -786,10 +789,218 @@ describe('Splitter', () => {
786789 expect ( splitter . startCollapsed ) . to . be . false ;
787790 expect ( splitter . endCollapsed ) . to . be . false ;
788791 } ) ;
792+
793+ it ( 'should not be able to resize a pane when it is collapsed' , async ( ) => {
794+ splitter . toggle ( 'start' ) ;
795+ await elementUpdated ( splitter ) ;
796+ const previousSizes = getPanesSizes ( splitter , 'width' ) ;
797+
798+ await resize ( splitter , 100 , 0 ) ;
799+ const currentSizes = getPanesSizes ( splitter , 'width' ) ;
800+ expect ( currentSizes ) . to . deep . equal ( previousSizes ) ;
801+ } ) ;
789802 } ) ;
790803
791804 // TODO: test when the slots have assigned sizes/min sizes + edge cases
792805 describe ( 'Resizing with constraints and edge cases' , ( ) => {
806+ describe ( 'Horizontal orientation' , ( ) => {
807+ it ( 'should honor minSize and maxSize constraints when resizing, constraints in px' , async ( ) => {
808+ const mixedConstraintSplitter = await fixture < IgcSplitterComponent > (
809+ createTwoPanesWithSizesAndConstraints ( {
810+ startSize : '200px' ,
811+ startMinSize : '100px' ,
812+ startMaxSize : '300px' ,
813+ endSize : '200px' ,
814+ endMinSize : '100px' ,
815+ endMaxSize : '300px' ,
816+ } )
817+ ) ;
818+ await elementUpdated ( mixedConstraintSplitter ) ;
819+
820+ let deltaX = 1000 ;
821+ await resize ( mixedConstraintSplitter , deltaX , 0 ) ;
822+
823+ let sizes = getPanesSizes ( mixedConstraintSplitter , 'width' ) ;
824+ expect ( sizes . startSize ) . to . equal ( 300 ) ;
825+
826+ deltaX = - 1000 ;
827+ await resize ( mixedConstraintSplitter , deltaX , 0 ) ;
828+
829+ sizes = getPanesSizes ( mixedConstraintSplitter , 'width' ) ;
830+ expect ( sizes . startSize ) . to . equal ( 100 ) ;
831+
832+ deltaX = 1000 ;
833+ await resize ( mixedConstraintSplitter , deltaX , 0 ) ;
834+
835+ sizes = getPanesSizes ( mixedConstraintSplitter , 'width' ) ;
836+ expect ( sizes . endSize ) . to . equal ( 100 ) ;
837+
838+ deltaX = - 1000 ;
839+ await resize ( mixedConstraintSplitter , deltaX , 0 ) ;
840+
841+ sizes = getPanesSizes ( mixedConstraintSplitter , 'width' ) ;
842+ expect ( sizes . endSize ) . to . equal ( 300 ) ;
843+ } ) ;
844+
845+ it ( 'should respect both panes constraints when they conflict during resize in px' , async ( ) => {
846+ const constraintSplitter = await fixture < IgcSplitterComponent > (
847+ createTwoPanesWithSizesAndConstraints ( {
848+ startSize : '200px' ,
849+ startMinSize : '100px' ,
850+ startMaxSize : '400px' ,
851+ endSize : '200px' ,
852+ endMinSize : '150px' ,
853+ endMaxSize : '350px' ,
854+ } )
855+ ) ;
856+ await elementUpdated ( constraintSplitter ) ;
857+
858+ const bar = getSplitterPart ( constraintSplitter , 'bar' ) ;
859+ const barSize = bar . getBoundingClientRect ( ) . width ;
860+ const totalAvailable = 500 - barSize ;
861+ expect ( totalAvailable ) . to . equal ( 495 ) ;
862+
863+ const initialSizes = getPanesSizes ( constraintSplitter , 'width' ) ;
864+ const initialCombinedSize =
865+ initialSizes . startSize + initialSizes . endSize ;
866+
867+ // Try to grow start pane to max, but end pane has min (150px)
868+ // Result: Start pane can only grow as much as end pane allows
869+ const deltaX = 1000 ;
870+ await resize ( constraintSplitter , deltaX , 0 ) ;
871+
872+ const sizes = getPanesSizes ( constraintSplitter , 'width' ) ;
873+
874+ // Start pane can only grow until end pane hits its minSize
875+ // Within the initial combined size of 400px - because of flex basis
876+ expect ( sizes . startSize ) . to . equal ( 250 ) ;
877+ expect ( sizes . endSize ) . to . equal ( 150 ) ;
878+
879+ expect ( sizes . startSize + sizes . endSize ) . to . equal ( initialCombinedSize ) ;
880+ expect ( sizes . startSize + sizes . endSize ) . to . be . at . most ( totalAvailable ) ;
881+ } ) ;
882+
883+ // TODO: very broken scenario (same in Angular)
884+ xit ( 'should honor minSize and maxSize constraints when resizing, constraints in %' , async ( ) => {
885+ const constraintSplitter = await fixture < IgcSplitterComponent > (
886+ createTwoPanesWithSizesAndConstraints ( {
887+ startSize : '30%' ,
888+ startMinSize : '10%' ,
889+ startMaxSize : '80%' ,
890+ endSize : '70%' ,
891+ endMinSize : '20%' ,
892+ endMaxSize : '90%' ,
893+ } )
894+ ) ;
895+ await elementUpdated ( constraintSplitter ) ;
896+
897+ const bar = getSplitterPart ( constraintSplitter , 'bar' ) ;
898+ const barSize = bar . getBoundingClientRect ( ) . width ;
899+ const totalAvailable = 500 - barSize ;
900+ expect ( totalAvailable ) . to . equal ( 495 ) ;
901+
902+ let deltaX = 1000 ;
903+ await resize ( constraintSplitter , deltaX , 0 ) ;
904+
905+ let sizes = getPanesSizes ( constraintSplitter , 'width' ) ;
906+ const expectedStartMax = Math . round ( ( totalAvailable * 80 ) / 100 ) ;
907+ expect ( sizes . startSize ) . to . be . closeTo ( expectedStartMax , 2 ) ;
908+
909+ deltaX = - 1000 ;
910+ await resize ( constraintSplitter , deltaX , 0 ) ;
911+
912+ sizes = getPanesSizes ( constraintSplitter , 'width' ) ;
913+ const expectedStartMin = Math . round ( ( totalAvailable * 10 ) / 100 ) ;
914+ expect ( sizes . startSize ) . to . be . closeTo ( expectedStartMin , 2 ) ;
915+
916+ deltaX = 1000 ;
917+ await resize ( constraintSplitter , deltaX , 0 ) ;
918+
919+ sizes = getPanesSizes ( constraintSplitter , 'width' ) ;
920+ const expectedEndMin = Math . round ( ( totalAvailable * 20 ) / 100 ) ;
921+ expect ( sizes . endSize ) . to . be . closeTo ( expectedEndMin , 2 ) ;
922+
923+ deltaX = - 1000 ;
924+ await resize ( constraintSplitter , deltaX , 0 ) ;
925+
926+ sizes = getPanesSizes ( constraintSplitter , 'width' ) ;
927+ const expectedEndMax = Math . round ( ( totalAvailable * 90 ) / 100 ) ;
928+ expect ( sizes . endSize ) . to . be . closeTo ( expectedEndMax , 2 ) ;
929+ } ) ;
930+ } ) ;
931+
932+ describe ( 'Vertical orientation' , ( ) => {
933+ it ( 'should honor minSize and maxSize constraints when resizing - constraints in px' , async ( ) => {
934+ const mixedConstraintSplitter = await fixture < IgcSplitterComponent > (
935+ createTwoPanesWithSizesAndConstraints ( {
936+ orientation : 'vertical' ,
937+ startSize : '200px' ,
938+ startMinSize : '100px' ,
939+ startMaxSize : '300px' ,
940+ endSize : '200px' ,
941+ endMinSize : '100px' ,
942+ endMaxSize : '300px' ,
943+ } )
944+ ) ;
945+ await elementUpdated ( mixedConstraintSplitter ) ;
946+
947+ let deltaY = 1000 ;
948+ await resize ( mixedConstraintSplitter , 0 , deltaY ) ;
949+
950+ let sizes = getPanesSizes ( mixedConstraintSplitter , 'height' ) ;
951+ expect ( sizes . startSize ) . to . equal ( 300 ) ;
952+
953+ deltaY = - 1000 ;
954+ await resize ( mixedConstraintSplitter , 0 , deltaY ) ;
955+
956+ sizes = getPanesSizes ( mixedConstraintSplitter , 'height' ) ;
957+ expect ( sizes . startSize ) . to . equal ( 100 ) ;
958+
959+ deltaY = 1000 ;
960+ await resize ( mixedConstraintSplitter , 0 , deltaY ) ;
961+ sizes = getPanesSizes ( mixedConstraintSplitter , 'height' ) ;
962+ expect ( sizes . endSize ) . to . equal ( 100 ) ;
963+
964+ deltaY = - 1000 ;
965+ await resize ( mixedConstraintSplitter , 0 , deltaY ) ;
966+
967+ sizes = getPanesSizes ( mixedConstraintSplitter , 'height' ) ;
968+ expect ( sizes . endSize ) . to . equal ( 300 ) ;
969+ } ) ;
970+ } ) ;
971+
972+ it ( 'should result in % sizes after resize when the panes size is auto' , ( ) => {
973+ //TODO
974+ } ) ;
975+
976+ it ( 'should handle mixed px and % constraints - start in px; end in %' , async ( ) => {
977+ const mixedConstraintSplitter = await fixture < IgcSplitterComponent > (
978+ createTwoPanesWithSizesAndConstraints ( {
979+ startMinSize : '100px' ,
980+ startMaxSize : '50%' ,
981+ } )
982+ ) ;
983+ await elementUpdated ( mixedConstraintSplitter ) ;
984+
985+ const startPane = getSplitterPart ( mixedConstraintSplitter , 'start-pane' ) ;
986+ const style = getComputedStyle ( startPane ) ;
987+
988+ expect ( mixedConstraintSplitter . startMinSize ) . to . equal ( '100px' ) ;
989+ expect ( mixedConstraintSplitter . startMaxSize ) . to . equal ( '50%' ) ;
990+ expect ( style . minWidth ) . to . equal ( '100px' ) ;
991+ expect ( style . maxWidth ) . to . equal ( '50%' ) ;
992+
993+ // TODO: test with drag
994+ } ) ;
995+
996+ it ( 'should handle mixed % and auto size' , async ( ) => {
997+ // TODO
998+ } ) ;
999+
1000+ it ( 'should handle mixed px and auto size' , async ( ) => {
1001+ // TODO
1002+ } ) ;
1003+
7931004 it ( 'panes should not exceed splitter size when set in px and horizontally resizing to end' , async ( ) => {
7941005 splitter = await fixture < IgcSplitterComponent > (
7951006 createTwoPanesWithSizesAndConstraints ( {
@@ -855,6 +1066,18 @@ describe('Splitter', () => {
8551066 ) ;
8561067 } ) ;
8571068 } ) ;
1069+
1070+ describe ( 'Behavior on window resize' , ( ) => {
1071+ it ( 'should maintain panes sizes in px on window resize' , async ( ) => {
1072+ //TODO
1073+ } ) ;
1074+
1075+ it ( 'should maintain panes sizes in % on window resize' , async ( ) => {
1076+ //TODO
1077+ } ) ;
1078+
1079+ //TODO: others
1080+ } ) ;
8581081} ) ;
8591082
8601083function createSplitter ( ) {
@@ -896,6 +1119,7 @@ function createTwoPanesWithSizesAndConstraints(
8961119) {
8971120 return html `
8981121 < igc-splitter
1122+ style ="width: 500px; height: 500px; "
8991123 .orientation =${ config . orientation ?? 'horizontal' }
9001124 .startSize =${ config . startSize }
9011125 .endSize=${ config . endSize }
@@ -910,6 +1134,20 @@ function createTwoPanesWithSizesAndConstraints(
9101134 ` ;
9111135}
9121136
1137+ function createSplitterWithCollapsedPane ( ) {
1138+ return html `
1139+ < igc-splitter
1140+ start-collapsed
1141+ start-size ="100px "
1142+ end-size ="100px "
1143+ style ="width: 500px; height: 500px; "
1144+ >
1145+ < div slot ="start "> Pane 1</ div >
1146+ < div slot ="end "> Pane 2</ div >
1147+ </ igc-splitter >
1148+ ` ;
1149+ }
1150+
9131151function getSplitterSlot (
9141152 splitter : IgcSplitterComponent ,
9151153 which : 'start' | 'end'
0 commit comments