@@ -19,19 +19,27 @@ describe('InfiniteLoading.vue', () => {
19
19
isLoadedAll : false ,
20
20
isDivScroll : true ,
21
21
isCustomSpinner : false ,
22
+ listContainerHeight : 100 ,
23
+ listItemHeight : 10 ,
24
+ customSpinnerHeight : 10
22
25
} ,
23
26
template : `
24
- <div style="height: 100px ;"
27
+ <div style="margin: 0; padding: 0 ;"
25
28
:style="{
26
- overflow: isDivScroll ? 'auto' : 'visible'
29
+ overflow: isDivScroll ? 'auto' : 'visible',
30
+ height: listContainerHeight + 'px'
27
31
}">
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>
30
36
</ul>
31
37
<infinite-loading :distance="distance"
32
38
:on-infinite="onInfinite"
33
39
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>
35
43
</infinite-loading>
36
44
</div>
37
45
` ,
@@ -103,23 +111,59 @@ describe('InfiniteLoading.vue', () => {
103
111
104
112
it ( 'should display no results prompt' , ( done ) => {
105
113
vm . onInfinite = function test ( ) {
106
- this . $broadcast ( '$InfiniteLoading:complete' ) ;
107
114
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
+ } ) ;
110
120
} ) ;
111
121
} . bind ( vm ) ;
112
122
113
123
vm . $mount ( ) . $appendTo ( 'body' ) ;
114
124
} ) ;
115
125
116
126
it ( 'should display no more data prompt' , ( done ) => {
127
+ let i = 0 ;
117
128
vm . onInfinite = function test ( ) {
118
- this . $broadcast ( '$InfiniteLoading:loaded' ) ;
119
- this . $broadcast ( '$InfiniteLoading:complete' ) ;
129
+ this . list . push ( ++ i ) ;
120
130
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
+ }
123
167
} ) ;
124
168
} . bind ( vm ) ;
125
169
0 commit comments