Skip to content

Commit c823d06

Browse files
committed
Added coverage but not sure how to test window scrolling
1 parent be8a085 commit c823d06

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed

demos/page-mode/App.vue

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<template>
2+
<div class="app">
3+
<GithubCorner path="/item-mode" />
4+
<div class="container">
5+
<Header title="item-mode"
6+
:desciption="'Build ' + itemCount.toLocaleString() + ' items.'"
7+
:start-index="start"
8+
:on-data-change="onHeaderDataChange"
9+
/>
10+
<div class="main">
11+
<virtual-list class="list"
12+
:size="size"
13+
:remain="remain"
14+
:bench="30"
15+
:start="start"
16+
:pagemode="true"
17+
:item="item"
18+
:itemcount="itemCount"
19+
:itemprops="getItemProps"
20+
/>
21+
</div>
22+
</div>
23+
</div>
24+
</template>
25+
26+
<script>
27+
import Item from '../common/Item.vue'
28+
import VirtualList from 'vue-virtual-scroll-list'
29+
import { countStorage, getRandomUser } from '../common/util'
30+
31+
const remain = 6
32+
const itemSize = 80
33+
const itemCount = countStorage.get()
34+
35+
let userInfoList = []
36+
for (let i = 0; i < itemCount; i++) {
37+
userInfoList.push(getRandomUser())
38+
}
39+
40+
export default {
41+
name: 'App',
42+
43+
components: {
44+
'virtual-list': VirtualList
45+
},
46+
47+
data () {
48+
return {
49+
remain,
50+
start: 0,
51+
size: itemSize,
52+
item: Item,
53+
itemCount: itemCount
54+
}
55+
},
56+
57+
methods: {
58+
getItemProps (itemIndex) {
59+
return {
60+
key: itemIndex,
61+
props: {
62+
height: itemSize,
63+
index: itemIndex,
64+
info: userInfoList[itemIndex] || {}
65+
}
66+
}
67+
},
68+
69+
onHeaderDataChange (type, value) {
70+
if (type === 'start') {
71+
this.start = value
72+
}
73+
}
74+
}
75+
}
76+
</script>
77+
78+
<style lang="less">
79+
@import '../common/app.less';
80+
</style>

demos/page-mode/build.js

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demos/page-mode/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>item-mode demo of vue-virtual-scroll-list</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0"/>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script src="build.js"></script>
11+
</body>
12+
</html>

demos/page-mode/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import App from './App.vue'
2+
import createApp from '../common/createApp'
3+
4+
createApp(App)

test/pagemode.test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import VirtualList from '../src/index'
2+
import { mount } from '@vue/test-utils'
3+
import { getIndexList } from './util'
4+
5+
// for testing pagemode build.
6+
const theme = 'pagemode-test'
7+
8+
describe(theme, () => {
9+
const listCount = 1000
10+
const wrapper = mount({
11+
template: `
12+
<div id="app" style="width: 300px;">
13+
<virtual-list class="list"
14+
:size="40"
15+
:remain="6"
16+
ref="vlist"
17+
:pagemode="true"
18+
>
19+
<div class="for-item"
20+
v-for="(item, index) in items"
21+
:key="index"
22+
style="height: 40px; line-height: 40px;"
23+
>
24+
<span class="for-item-text">{{ item }}</span>
25+
</div>
26+
</virtual-list>
27+
</div>
28+
`,
29+
30+
name: 'test',
31+
32+
components: {
33+
'virtual-list': VirtualList
34+
},
35+
36+
data () {
37+
return {
38+
items: getIndexList(listCount)
39+
}
40+
}
41+
})
42+
43+
it(`[${theme}] check list build success.`, () => {
44+
expect(wrapper.find('.for-item').exists()).toBe(true)
45+
expect(wrapper.find('.for-item-text').exists()).toBe(true)
46+
47+
// list wraper height is remain * size.
48+
const expectOutsideHeight = 40 * 6
49+
const listEl = wrapper.find('.list').vm.$el
50+
const expectPaddingBottom = listCount * 40 - expectOutsideHeight * 2
51+
expect(listEl.style['padding-top']).toBe(`0px`)
52+
expect(listEl.style['padding-bottom']).toBe(`${expectPaddingBottom}px`)
53+
})
54+
55+
it(`[${theme}] check build item count correct.`, () => {
56+
const itemFrags = wrapper.findAll('.for-item')
57+
58+
// default real dom count is remain + default bench.
59+
expect(itemFrags.length).toBe(6 + 6)
60+
61+
// check every item render content.
62+
for (let i = 0; i < itemFrags.length; i++) {
63+
const item = itemFrags.at(i)
64+
expect(item.text()).toBe('#' + i)
65+
expect(item.classes('for-item')).toBe(true)
66+
}
67+
})
68+
})

0 commit comments

Comments
 (0)