@@ -6,14 +6,18 @@ import { getIndexList } from './util'
6
6
const theme = 'pagemode-test'
7
7
8
8
describe ( theme , ( ) => {
9
+ const initSize = 40
10
+ const initRemian = 6
11
+ const initStart = 100
9
12
const listCount = 1000
10
13
const wrapper = mount ( {
11
14
template : `
12
15
<div id="app" style="width: 300px;">
13
16
<virtual-list class="list"
14
- :size="40"
15
- :remain="6"
16
17
ref="vlist"
18
+ :size="size"
19
+ :remain="remian"
20
+ :start="start"
17
21
:pagemode="true"
18
22
>
19
23
<div class="for-item"
@@ -35,6 +39,9 @@ describe(theme, () => {
35
39
36
40
data ( ) {
37
41
return {
42
+ size : initSize ,
43
+ remian : initRemian ,
44
+ start : initStart ,
38
45
items : getIndexList ( listCount )
39
46
}
40
47
}
@@ -45,10 +52,10 @@ describe(theme, () => {
45
52
expect ( wrapper . find ( '.for-item-text' ) . exists ( ) ) . toBe ( true )
46
53
47
54
// list wraper height is remain * size.
48
- const expectOutsideHeight = 40 * 6
49
55
const listEl = wrapper . find ( '.list' ) . vm . $el
50
- const expectPaddingBottom = listCount * 40 - expectOutsideHeight * 2
51
- expect ( listEl . style [ 'padding-top' ] ) . toBe ( `0px` )
56
+ const expectPaddingTop = initStart * initSize
57
+ const expectPaddingBottom = ( listCount - initRemian - initRemian - initStart ) * initSize
58
+ expect ( listEl . style [ 'padding-top' ] ) . toBe ( `${ expectPaddingTop } px` )
52
59
expect ( listEl . style [ 'padding-bottom' ] ) . toBe ( `${ expectPaddingBottom } px` )
53
60
} )
54
61
@@ -61,8 +68,49 @@ describe(theme, () => {
61
68
// check every item render content.
62
69
for ( let i = 0 ; i < itemFrags . length ; i ++ ) {
63
70
const item = itemFrags . at ( i )
64
- expect ( item . text ( ) ) . toBe ( '#' + i )
71
+ expect ( item . text ( ) ) . toBe ( '#' + ( initStart + i ) )
65
72
expect ( item . classes ( 'for-item' ) ) . toBe ( true )
66
73
}
67
74
} )
75
+
76
+ it ( `[${ theme } ] check update correct.` , ( ) => {
77
+ const vmData = wrapper . vm . $data
78
+ const listEl = wrapper . find ( '.list' ) . vm . $el
79
+
80
+ let expectPaddingTop
81
+ let expectPaddingBottom
82
+
83
+ vmData . start = 200
84
+ expectPaddingTop = 200 * initSize
85
+ expectPaddingBottom = ( listCount - initRemian - initRemian - 200 ) * initSize
86
+ expect ( listEl . style [ 'padding-top' ] ) . toBe ( `${ expectPaddingTop } px` )
87
+ expect ( listEl . style [ 'padding-bottom' ] ) . toBe ( `${ expectPaddingBottom } px` )
88
+
89
+ vmData . start = 0
90
+ expectPaddingTop = 0
91
+ expectPaddingBottom = ( listCount - initRemian - initRemian ) * initSize
92
+ expect ( listEl . style [ 'padding-top' ] ) . toBe ( `${ expectPaddingTop } px` )
93
+ expect ( listEl . style [ 'padding-bottom' ] ) . toBe ( `${ expectPaddingBottom } px` )
94
+
95
+ // start on last zone.
96
+ vmData . start = listCount - initRemian - 3
97
+ expectPaddingTop = ( listCount - initRemian - initRemian ) * initSize
98
+ expectPaddingBottom = 0
99
+ expect ( listEl . style [ 'padding-top' ] ) . toBe ( `${ expectPaddingTop } px` )
100
+ expect ( listEl . style [ 'padding-bottom' ] ) . toBe ( `${ expectPaddingBottom } px` )
101
+
102
+ // start on last zone edge.
103
+ vmData . start = listCount - initRemian - initRemian - 1
104
+ expectPaddingTop = ( listCount - initRemian - initRemian - 1 ) * initSize
105
+ expectPaddingBottom = 1 * initSize
106
+ expect ( listEl . style [ 'padding-top' ] ) . toBe ( `${ expectPaddingTop } px` )
107
+ expect ( listEl . style [ 'padding-bottom' ] ) . toBe ( `${ expectPaddingBottom } px` )
108
+
109
+ // start overflow.
110
+ vmData . start = listCount + 10
111
+ expectPaddingTop = ( listCount - initRemian - initRemian ) * initSize
112
+ expectPaddingBottom = 0
113
+ expect ( listEl . style [ 'padding-top' ] ) . toBe ( `${ expectPaddingTop } px` )
114
+ expect ( listEl . style [ 'padding-bottom' ] ) . toBe ( `${ expectPaddingBottom } px` )
115
+ } )
68
116
} )
0 commit comments