Skip to content

Commit 6aa8d3e

Browse files
committed
test: add list test & update spin
1 parent e7ab83c commit 6aa8d3e

File tree

11 files changed

+101
-11
lines changed

11 files changed

+101
-11
lines changed

components/_util/props-util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export function isEmptyElement (ele) {
196196
}
197197

198198
export function filterEmpty (children = []) {
199-
return children.filter(c => c.tag || c.text.trim() !== '')
199+
return children.filter(c => c.tag || (c.text && c.text.trim() !== ''))
200200
}
201201
const initDefaultProps = (propTypes, defaultProps) => {
202202
Object.keys(defaultProps).forEach(k => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`List renders empty list 1`] = `<div class="ant-list ant-list-split"><span tag="div" class="ant-spin-nested-loading"><div class="ant-spin-container"><div class="ant-list-empty-text">No data</div></div></span></div>`;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { mount } from '@vue/test-utils'
2+
import List from '..'
3+
4+
describe('List', () => {
5+
it('renders empty list', () => {
6+
const wrapper = mount({
7+
render () {
8+
return <List dataSource={[]} renderItem={() => <List.Item />} />
9+
},
10+
})
11+
expect(wrapper.html()).toMatchSnapshot()
12+
})
13+
})
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { mount } from '@vue/test-utils'
2+
import { asyncExpect } from '@/tests/utils'
3+
import List from '..'
4+
import Icon from '../../icon'
5+
6+
describe('List', () => {
7+
it('renders empty loading', () => {
8+
const loading = {
9+
spinning: true,
10+
}
11+
const wrapper = mount(
12+
{
13+
render () {
14+
return <List loading={loading} dataSource={[]} renderItem={() => <List.Item />} />
15+
},
16+
})
17+
expect(wrapper.findAll('.ant-list-empty-text')).toHaveLength(0)
18+
})
19+
20+
it('renders object loading', () => {
21+
const loading = {
22+
spinning: true,
23+
}
24+
const wrapper = mount(
25+
{
26+
render () {
27+
return <List
28+
loading={loading}
29+
dataSource={[1]}
30+
renderItem={() => <List.Item />}
31+
/>
32+
},
33+
})
34+
expect(wrapper.findAll('.ant-spin-spinning')).toHaveLength(1)
35+
})
36+
37+
it('renders object loading with indicator', () => {
38+
const wrapper = mount(
39+
{
40+
render () {
41+
return <List
42+
loading={{
43+
spinning: true,
44+
indicator: <Icon type='loading' style={{ fontSize: '24px' }} spin />,
45+
}}
46+
dataSource={[1]}
47+
renderItem={() => <List.Item />}
48+
/>
49+
},
50+
}
51+
52+
)
53+
expect(wrapper.findAll('.anticon-loading')).toHaveLength(1)
54+
})
55+
})

components/list/demo/test.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import List from '..'
3+
export default {
4+
render () {
5+
return <List dataSource={[]} renderItem={() => <List.Item />} />
6+
},
7+
}
8+
</script>

components/list/index.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Pagination from '../pagination'
1010
import { Row } from '../grid'
1111

1212
import Item from './Item'
13-
import { initDefaultProps, getComponentFromProp } from '../_util/props-util'
13+
import { initDefaultProps, getComponentFromProp, filterEmpty } from '../_util/props-util'
1414
import { cloneElement } from '../_util/vnode'
1515

1616
export { ListItemProps, ListItemMetaProps } from './Item'
@@ -38,7 +38,7 @@ export const ListProps = () => ({
3838
extra: PropTypes.any,
3939
grid: PropTypes.shape(ListGridType).loose,
4040
itemLayout: PropTypes.string,
41-
loading: PropTypes.oneOfType([PropTypes.bool, SpinProps()]),
41+
loading: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
4242
loadMore: PropTypes.any,
4343
pagination: PropTypes.any,
4444
prefixCls: PropTypes.string,
@@ -139,7 +139,7 @@ export default {
139139
const loadMore = getComponentFromProp(this, 'loadMore')
140140
const footer = getComponentFromProp(this, 'footer')
141141
const header = getComponentFromProp(this, 'header')
142-
const children = $slots.default || []
142+
const children = filterEmpty($slots.default || [])
143143
let loadingProp = loading
144144
if (typeof loadingProp === 'boolean') {
145145
loadingProp = {
@@ -220,7 +220,7 @@ export default {
220220
childrenContent = grid ? (
221221
<Row gutter={grid.gutter}>{childrenList}</Row>
222222
) : childrenList
223-
} else if (!children && !isLoading) {
223+
} else if (!children.length && !isLoading) {
224224
childrenContent = (
225225
<LocaleReceiver
226226
componentName='Table'

components/spin/Spin.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import PropTypes from '../_util/vue-types'
33
import BaseMixin from '../_util/BaseMixin'
44
import isCssAnimationSupported from '../_util/isCssAnimationSupported'
5-
import { filterEmpty, initDefaultProps } from '../_util/props-util'
5+
import { filterEmpty, initDefaultProps, isValidElement, getComponentFromProp } from '../_util/props-util'
66
import getTransitionProps from '../_util/getTransitionProps'
7+
import { cloneElement } from '../_util/vnode'
78

89
export const SpinProps = () => ({
910
prefixCls: PropTypes.string,
@@ -12,6 +13,7 @@ export const SpinProps = () => ({
1213
wrapperClassName: PropTypes.string,
1314
tip: PropTypes.string,
1415
delay: PropTypes.number,
16+
indicator: PropTypes.any,
1517
})
1618

1719
export default {
@@ -91,7 +93,16 @@ export default {
9193
[`${prefixCls}-spinning`]: stateSpinning,
9294
[`${prefixCls}-show-text`]: !!tip || notCssAnimationSupported,
9395
}
94-
const spinIndicator = $slots.indicator ? $slots.indicator : (
96+
let indicator = getComponentFromProp(this, 'indicator')
97+
if (Array.isArray(indicator)) {
98+
indicator = filterEmpty(indicator)
99+
indicator = indicator.length === 1 ? indicator[0] : indicator
100+
}
101+
let spinIndicator = null
102+
if (isValidElement(indicator)) {
103+
spinIndicator = cloneElement(indicator, { class: `${prefixCls}-dot` })
104+
}
105+
spinIndicator = spinIndicator || (
95106
<span class={`${prefixCls}-dot`}>
96107
<i />
97108
<i />

components/spin/__tests__/__snapshots__/index.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ exports[`Spin should only affect the spin element when set style to a nested <Sp
1111

1212
exports[`Spin should render custom indicator when it's set 1`] = `
1313
<div class="ant-spin ant-spin-spinning">
14-
<div class="custom-indicator"></div>
14+
<div class="custom-indicator ant-spin-dot"></div>
1515
</div>
1616
`;

components/spin/index.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| Property | Description | Type | Default Value |
55
| -------- | ----------- | ---- | ------------- |
66
| delay | specifies a delay in milliseconds for loading state (prevent flush) | number (milliseconds) | - |
7-
| indicator | vue node of the spinning indicator | slot | - |
7+
| indicator | vue node of the spinning indicator | vNode \|slot | - |
88
| size | size of Spin, options: `small`, `default` and `large` | string | `default` |
99
| spinning | whether Spin is spinning | boolean | true |
1010
| tip | customize description content when Spin has children | string | - |

components/spin/index.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| 参数 | 说明 | 类型 | 默认值 |
55
| --- | --- | --- | --- |
66
| delay | 延迟显示加载效果的时间(防止闪烁) | number (毫秒) | - |
7-
| indicator | 加载指示符 | slot方式 | - |
7+
| indicator | 加载指示符 | vNode \| slot | - |
88
| size | 组件大小,可选值为 `small` `default` `large` | string | 'default' |
99
| spinning | 是否旋转 | boolean | true |
1010
| tip | 当作为包裹元素时,可以自定义描述文案 | string | - |

0 commit comments

Comments
 (0)