@@ -14,6 +14,7 @@ const appDef = {
1414 controls : false ,
1515 fade : false ,
1616 noAnimation : false ,
17+ noWrap : false ,
1718 value : 0
1819 } ,
1920 render ( h ) {
@@ -26,6 +27,7 @@ const appDef = {
2627 controls : this . controls ,
2728 fade : this . fade ,
2829 noAnimation : this . noAnimation ,
30+ noWrap : this . noWrap ,
2931 value : this . value
3032 }
3133 } ,
@@ -995,4 +997,178 @@ describe('carousel', () => {
995997
996998 wrapper . destroy ( )
997999 } )
1000+
1001+ it ( 'Next/Prev slide wraps to end/start when no-wrap is false' , async ( ) => {
1002+ const wrapper = mount ( localVue . extend ( appDef ) , {
1003+ localVue : localVue ,
1004+ attachToDocument : true ,
1005+ propsData : {
1006+ interval : 0 ,
1007+ fade : false ,
1008+ noAnimation : true ,
1009+ noWrap : false ,
1010+ indicators : true ,
1011+ controls : true ,
1012+ // Start at last slide
1013+ value : 3
1014+ }
1015+ } )
1016+
1017+ expect ( wrapper . isVueInstance ( ) ) . toBe ( true )
1018+ const $carousel = wrapper . find ( BCarousel )
1019+ expect ( $carousel ) . toBeDefined ( )
1020+ expect ( $carousel . isVueInstance ( ) ) . toBe ( true )
1021+
1022+ await waitNT ( wrapper . vm )
1023+ await waitRAF ( )
1024+
1025+ const $indicators = $carousel . findAll ( '.carousel-indicators > li' )
1026+ expect ( $indicators . length ) . toBe ( 4 )
1027+
1028+ expect ( $carousel . emitted ( 'sliding-start' ) ) . not . toBeDefined ( )
1029+ expect ( $carousel . emitted ( 'sliding-end' ) ) . not . toBeDefined ( )
1030+ expect ( $carousel . emitted ( 'input' ) ) . not . toBeDefined ( )
1031+
1032+ expect ( $carousel . vm . index ) . toBe ( 3 )
1033+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1034+
1035+ // Transitions (or fallback timers) are not used when no-animation set
1036+ // Call vm.next()
1037+ $carousel . vm . next ( )
1038+ await waitNT ( wrapper . vm )
1039+
1040+ expect ( $carousel . emitted ( 'sliding-start' ) ) . toBeDefined ( )
1041+ expect ( $carousel . emitted ( 'sliding-end' ) ) . toBeDefined ( )
1042+ expect ( $carousel . emitted ( 'sliding-start' ) . length ) . toBe ( 1 )
1043+ expect ( $carousel . emitted ( 'sliding-end' ) . length ) . toBe ( 1 )
1044+ // Should have index of 0
1045+ expect ( $carousel . emitted ( 'sliding-start' ) [ 0 ] [ 0 ] ) . toEqual ( 0 )
1046+ expect ( $carousel . emitted ( 'sliding-end' ) [ 0 ] [ 0 ] ) . toEqual ( 0 )
1047+ expect ( $carousel . emitted ( 'input' ) ) . toBeDefined ( )
1048+ expect ( $carousel . emitted ( 'input' ) . length ) . toBe ( 1 )
1049+ expect ( $carousel . emitted ( 'input' ) [ 0 ] [ 0 ] ) . toEqual ( 0 )
1050+ expect ( $carousel . vm . index ) . toBe ( 0 )
1051+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1052+
1053+ // Call vm.prev()
1054+ $carousel . vm . prev ( )
1055+ await waitNT ( wrapper . vm )
1056+
1057+ expect ( $carousel . emitted ( 'sliding-start' ) . length ) . toBe ( 2 )
1058+ expect ( $carousel . emitted ( 'sliding-end' ) . length ) . toBe ( 2 )
1059+ // Should have index set to last slide
1060+ expect ( $carousel . emitted ( 'sliding-start' ) [ 1 ] [ 0 ] ) . toEqual ( 3 )
1061+ expect ( $carousel . emitted ( 'sliding-end' ) [ 1 ] [ 0 ] ) . toEqual ( 3 )
1062+ expect ( $carousel . emitted ( 'input' ) . length ) . toBe ( 2 )
1063+ expect ( $carousel . emitted ( 'input' ) [ 1 ] [ 0 ] ) . toEqual ( 3 )
1064+ expect ( $carousel . vm . index ) . toBe ( 3 )
1065+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1066+
1067+ wrapper . destroy ( )
1068+ } )
1069+
1070+ it ( 'Next/Prev slide does not wrap to end/start when no-wrap is true' , async ( ) => {
1071+ const wrapper = mount ( localVue . extend ( appDef ) , {
1072+ localVue : localVue ,
1073+ attachToDocument : true ,
1074+ propsData : {
1075+ interval : 0 ,
1076+ fade : false ,
1077+ // Transitions (or fallback timers) are not used when no-animation set
1078+ noAnimation : true ,
1079+ noWrap : true ,
1080+ indicators : true ,
1081+ controls : true ,
1082+ // Start at last slide
1083+ value : 3
1084+ }
1085+ } )
1086+
1087+ expect ( wrapper . isVueInstance ( ) ) . toBe ( true )
1088+ const $carousel = wrapper . find ( BCarousel )
1089+ expect ( $carousel ) . toBeDefined ( )
1090+ expect ( $carousel . isVueInstance ( ) ) . toBe ( true )
1091+
1092+ await waitNT ( wrapper . vm )
1093+ await waitRAF ( )
1094+
1095+ const $indicators = $carousel . findAll ( '.carousel-indicators > li' )
1096+ expect ( $indicators . length ) . toBe ( 4 )
1097+
1098+ expect ( $carousel . emitted ( 'sliding-start' ) ) . not . toBeDefined ( )
1099+ expect ( $carousel . emitted ( 'sliding-end' ) ) . not . toBeDefined ( )
1100+ expect ( $carousel . emitted ( 'input' ) ) . not . toBeDefined ( )
1101+
1102+ expect ( $carousel . vm . index ) . toBe ( 3 )
1103+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1104+
1105+ // Call vm.next()
1106+ $carousel . vm . next ( )
1107+ await waitNT ( wrapper . vm )
1108+
1109+ // Should not slide to start
1110+ expect ( $carousel . emitted ( 'sliding-start' ) ) . not . toBeDefined ( )
1111+ expect ( $carousel . emitted ( 'sliding-end' ) ) . not . toBeDefined ( )
1112+ // Should have index of 3 (no input event emitted since value set to 3)
1113+ expect ( $carousel . emitted ( 'input' ) ) . not . toBeDefined ( )
1114+ expect ( $carousel . vm . index ) . toBe ( 3 )
1115+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1116+
1117+ // Call vm.prev()
1118+ $carousel . vm . prev ( )
1119+ await waitNT ( wrapper . vm )
1120+
1121+ expect ( $carousel . emitted ( 'sliding-start' ) . length ) . toBe ( 1 )
1122+ expect ( $carousel . emitted ( 'sliding-end' ) . length ) . toBe ( 1 )
1123+ // Should have index set to 2
1124+ expect ( $carousel . emitted ( 'sliding-start' ) [ 0 ] [ 0 ] ) . toEqual ( 2 )
1125+ expect ( $carousel . emitted ( 'sliding-end' ) [ 0 ] [ 0 ] ) . toEqual ( 2 )
1126+ expect ( $carousel . emitted ( 'input' ) ) . toBeDefined ( )
1127+ expect ( $carousel . emitted ( 'input' ) . length ) . toBe ( 1 )
1128+ expect ( $carousel . emitted ( 'input' ) [ 0 ] [ 0 ] ) . toEqual ( 2 )
1129+ expect ( $carousel . vm . index ) . toBe ( 2 )
1130+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1131+
1132+ // Call vm.prev()
1133+ $carousel . vm . prev ( )
1134+ await waitNT ( wrapper . vm )
1135+
1136+ expect ( $carousel . emitted ( 'sliding-start' ) . length ) . toBe ( 2 )
1137+ expect ( $carousel . emitted ( 'sliding-end' ) . length ) . toBe ( 2 )
1138+ // Should have index set to 1
1139+ expect ( $carousel . emitted ( 'sliding-start' ) [ 1 ] [ 0 ] ) . toEqual ( 1 )
1140+ expect ( $carousel . emitted ( 'sliding-end' ) [ 1 ] [ 0 ] ) . toEqual ( 1 )
1141+ expect ( $carousel . emitted ( 'input' ) . length ) . toBe ( 2 )
1142+ expect ( $carousel . emitted ( 'input' ) [ 1 ] [ 0 ] ) . toEqual ( 1 )
1143+ expect ( $carousel . vm . index ) . toBe ( 1 )
1144+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1145+
1146+ // Call vm.prev()
1147+ $carousel . vm . prev ( )
1148+ await waitNT ( wrapper . vm )
1149+
1150+ expect ( $carousel . emitted ( 'sliding-start' ) . length ) . toBe ( 3 )
1151+ expect ( $carousel . emitted ( 'sliding-end' ) . length ) . toBe ( 3 )
1152+ // Should have index set to 0
1153+ expect ( $carousel . emitted ( 'sliding-start' ) [ 2 ] [ 0 ] ) . toEqual ( 0 )
1154+ expect ( $carousel . emitted ( 'sliding-end' ) [ 2 ] [ 0 ] ) . toEqual ( 0 )
1155+ expect ( $carousel . emitted ( 'input' ) . length ) . toBe ( 3 )
1156+ expect ( $carousel . emitted ( 'input' ) [ 2 ] [ 0 ] ) . toEqual ( 0 )
1157+ expect ( $carousel . vm . index ) . toBe ( 0 )
1158+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1159+
1160+ // Call vm.prev() (should not wrap)
1161+ $carousel . vm . prev ( )
1162+ await waitNT ( wrapper . vm )
1163+
1164+ expect ( $carousel . emitted ( 'sliding-start' ) . length ) . toBe ( 3 )
1165+ expect ( $carousel . emitted ( 'sliding-end' ) . length ) . toBe ( 3 )
1166+ // Should have index still set to 0, and emit input to update v-model
1167+ expect ( $carousel . emitted ( 'input' ) . length ) . toBe ( 4 )
1168+ expect ( $carousel . emitted ( 'input' ) [ 3 ] [ 0 ] ) . toEqual ( 0 )
1169+ expect ( $carousel . vm . index ) . toBe ( 0 )
1170+ expect ( $carousel . vm . isSliding ) . toBe ( false )
1171+
1172+ wrapper . destroy ( )
1173+ } )
9981174} )
0 commit comments