@@ -19,19 +19,27 @@ describe('InfiniteLoading.vue', () => {
1919 isLoadedAll : false ,
2020 isDivScroll : true ,
2121 isCustomSpinner : false ,
22+ listContainerHeight : 100 ,
23+ listItemHeight : 10 ,
24+ customSpinnerHeight : 10
2225 } ,
2326 template : `
24- <div style="height: 100px ;"
27+ <div style="margin: 0; padding: 0 ;"
2528 :style="{
26- overflow: isDivScroll ? 'auto' : 'visible'
29+ overflow: isDivScroll ? 'auto' : 'visible',
30+ height: listContainerHeight + 'px'
2731 }">
28- <ul>
29- <li v-for="item in list" v-text="item"></li>
32+ <ul style="margin: 0; padding: 0; font-size: 5px;">
33+ <li v-for="item in list" v-text="item" style="height: 10px; margin: 0; padding: 0;" :style="{
34+ height: listItemHeight + 'px'
35+ }"></li>
3036 </ul>
3137 <infinite-loading :distance="distance"
3238 :on-infinite="onInfinite"
3339 v-if="!isLoadedAll">
34- <span slot="spinner" v-if="isCustomSpinner"><i class="custom-spinner"></i></span>
40+ <span slot="spinner" v-if="isCustomSpinner"><i class="custom-spinner" style="display: inline-block; width: 10px;" :style="{
41+ height: customSpinnerHeight + 'px'
42+ }"></i></span>
3543 </infinite-loading>
3644 </div>
3745 ` ,
@@ -103,23 +111,59 @@ describe('InfiniteLoading.vue', () => {
103111
104112 it ( 'should display no results prompt' , ( done ) => {
105113 vm . onInfinite = function test ( ) {
106- this . $broadcast ( '$InfiniteLoading:complete' ) ;
107114 Vue . nextTick ( ( ) => {
108- expect ( isShow ( vm . $el . querySelectorAll ( '.infinite-status-prompt' ) [ 0 ] ) ) . to . be . true ;
109- done ( ) ;
115+ this . $broadcast ( '$InfiniteLoading:complete' ) ;
116+ Vue . nextTick ( ( ) => {
117+ expect ( isShow ( vm . $el . querySelectorAll ( '.infinite-status-prompt' ) [ 0 ] ) ) . to . be . true ;
118+ done ( ) ;
119+ } ) ;
110120 } ) ;
111121 } . bind ( vm ) ;
112122
113123 vm . $mount ( ) . $appendTo ( 'body' ) ;
114124 } ) ;
115125
116126 it ( 'should display no more data prompt' , ( done ) => {
127+ let i = 0 ;
117128 vm . onInfinite = function test ( ) {
118- this . $broadcast ( '$InfiniteLoading:loaded' ) ;
119- this . $broadcast ( '$InfiniteLoading:complete' ) ;
129+ this . list . push ( ++ i ) ;
120130 Vue . nextTick ( ( ) => {
121- expect ( isShow ( vm . $el . querySelectorAll ( '.infinite-status-prompt' ) [ 1 ] ) ) . to . be . true ;
122- done ( ) ;
131+ this . $broadcast ( '$InfiniteLoading:loaded' ) ;
132+ this . $broadcast ( '$InfiniteLoading:complete' ) ;
133+ Vue . nextTick ( ( ) => {
134+ expect ( isShow ( vm . $el . querySelectorAll ( '.infinite-status-prompt' ) [ 1 ] ) ) . to . be . true ;
135+ done ( ) ;
136+ } ) ;
137+ } ) ;
138+ } . bind ( vm ) ;
139+
140+ vm . $mount ( ) . $appendTo ( 'body' ) ;
141+ } ) ;
142+
143+ it ( 'should load results to fill up the container' , function ( done ) {
144+ const TEST_TIMEOUT = 2000 ;
145+ let mocha = this ;
146+ let i = 0 ;
147+ vm . listContainerHeight = 100 ;
148+ vm . listItemHeight = 10 ;
149+ vm . distance = 10 ;
150+ vm . isCustomSpinner = true ;
151+ vm . customSpinnerHeight = 10 ;
152+ let expectedCount = Math . floor ( vm . listContainerHeight / vm . listItemHeight ) ;
153+ vm . onInfinite = function test ( ) {
154+ this . list . push ( ++ i ) ;
155+ Vue . nextTick ( ( ) => {
156+ this . $broadcast ( '$InfiniteLoading:loaded' ) ;
157+ if ( i == expectedCount ) {
158+ mocha . timeout ( TEST_TIMEOUT + 100 ) ;
159+ setTimeout ( function ( ) {
160+ if ( i == expectedCount ) {
161+ done ( ) ;
162+ } else {
163+ done ( new Error ( 'Unexpected number of items added' ) ) ;
164+ }
165+ } , TEST_TIMEOUT ) ;
166+ }
123167 } ) ;
124168 } . bind ( vm ) ;
125169
0 commit comments