Skip to content

Commit 5a15725

Browse files
committed
More coverage
1 parent c823d06 commit 5a15725

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

test/pagemode.test.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ import { getIndexList } from './util'
66
const theme = 'pagemode-test'
77

88
describe(theme, () => {
9+
const initSize = 40
10+
const initRemian = 6
11+
const initStart = 100
912
const listCount = 1000
1013
const wrapper = mount({
1114
template: `
1215
<div id="app" style="width: 300px;">
1316
<virtual-list class="list"
14-
:size="40"
15-
:remain="6"
1617
ref="vlist"
18+
:size="size"
19+
:remain="remian"
20+
:start="start"
1721
:pagemode="true"
1822
>
1923
<div class="for-item"
@@ -35,6 +39,9 @@ describe(theme, () => {
3539

3640
data () {
3741
return {
42+
size: initSize,
43+
remian: initRemian,
44+
start: initStart,
3845
items: getIndexList(listCount)
3946
}
4047
}
@@ -45,10 +52,10 @@ describe(theme, () => {
4552
expect(wrapper.find('.for-item-text').exists()).toBe(true)
4653

4754
// list wraper height is remain * size.
48-
const expectOutsideHeight = 40 * 6
4955
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`)
5259
expect(listEl.style['padding-bottom']).toBe(`${expectPaddingBottom}px`)
5360
})
5461

@@ -61,8 +68,49 @@ describe(theme, () => {
6168
// check every item render content.
6269
for (let i = 0; i < itemFrags.length; i++) {
6370
const item = itemFrags.at(i)
64-
expect(item.text()).toBe('#' + i)
71+
expect(item.text()).toBe('#' + (initStart + i))
6572
expect(item.classes('for-item')).toBe(true)
6673
}
6774
})
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+
})
68116
})

0 commit comments

Comments
 (0)