Skip to content

Commit ed9de47

Browse files
committed
test: add progress & rate & slider & spin & table test
1 parent c2c9841 commit ed9de47

File tree

12 files changed

+243
-103
lines changed

12 files changed

+243
-103
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { mount } from '@vue/test-utils'
2+
import { asyncExpect } from '@/tests/utils'
3+
import Progress from '..'
4+
5+
describe('Progress', () => {
6+
it('successPercent should decide the progress status when it exists', async () => {
7+
const wrapper = mount(Progress, {
8+
propsData: {
9+
percent: 100,
10+
successPercent: 50,
11+
},
12+
sync: false,
13+
})
14+
await asyncExpect(() => {
15+
expect(wrapper.findAll('.ant-progress-status-success')).toHaveLength(0)
16+
})
17+
18+
wrapper.setProps({ percent: 50, successPercent: 100 })
19+
await asyncExpect(() => {
20+
expect(wrapper.findAll('.ant-progress-status-success')).toHaveLength(1)
21+
})
22+
})
23+
})
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Rate from '..'
2+
import focusTest from '../../../tests/shared/focusTest'
3+
4+
describe('Rate', () => {
5+
focusTest(Rate)
6+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Slider should show tooltip when hovering slider handler 1`] = `
4+
<div>
5+
<div class="ant-tooltip ant-tooltip-placement-top" style="left: -999px; top: -1003px;">
6+
<div class="ant-tooltip-content">
7+
<div class="ant-tooltip-arrow"></div>
8+
<div class="ant-tooltip-inner">30</div>
9+
</div>
10+
</div>
11+
</div>
12+
`;
13+
14+
exports[`Slider should show tooltip when hovering slider handler 2`] = `
15+
<div>
16+
<div class="ant-tooltip ant-tooltip-placement-top" style="display: none; left: -999px; top: -1003px;">
17+
<div class="ant-tooltip-content">
18+
<div class="ant-tooltip-arrow"></div>
19+
<div class="ant-tooltip-inner">30</div>
20+
</div>
21+
</div>
22+
</div>
23+
`;
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { mount } from '@vue/test-utils'
2+
import { asyncExpect } from '@/tests/utils'
3+
import Slider from '..'
4+
5+
describe('Slider', () => {
6+
it('should show tooltip when hovering slider handler', async () => {
7+
const wrapper = mount(Slider, {
8+
propsData: {
9+
defaultValue: 30,
10+
},
11+
sync: false,
12+
})
13+
await asyncExpect(() => {
14+
wrapper.findAll('.ant-slider-handle').at(0).trigger('mouseenter')
15+
})
16+
let dropdownWrapper = null
17+
await asyncExpect(() => {
18+
dropdownWrapper = mount({
19+
render () {
20+
return wrapper.find({ name: 'Trigger' }).vm.getComponent()
21+
},
22+
}, { sync: false })
23+
})
24+
await asyncExpect(() => {
25+
expect(dropdownWrapper.html()).toMatchSnapshot()
26+
wrapper.findAll('.ant-slider-handle').at(0).trigger('mouseleave')
27+
})
28+
await asyncExpect(() => {
29+
dropdownWrapper = mount({
30+
render () {
31+
return wrapper.find({ name: 'Trigger' }).vm.getComponent()
32+
},
33+
}, { sync: false })
34+
})
35+
await asyncExpect(() => {
36+
expect(dropdownWrapper.html()).toMatchSnapshot()
37+
})
38+
})
39+
})

components/spin/Spin.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export default {
9191
[`${prefixCls}-spinning`]: stateSpinning,
9292
[`${prefixCls}-show-text`]: !!tip || notCssAnimationSupported,
9393
}
94-
9594
const spinIndicator = $slots.indicator ? $slots.indicator : (
9695
<span class={`${prefixCls}-dot`}>
9796
<i />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Spin should only affect the spin element when set style to a nested <Spin>xx</Spin> 1`] = `
4+
<span tag="div" class="ant-spin-nested-loading" style="background: red;"><div><div class="ant-spin ant-spin-spinning"><span class="ant-spin-dot"><i></i><i></i><i></i><i></i></span></div>
5+
</div>
6+
<div class="ant-spin-container ant-spin-blur">
7+
<div>content</div>
8+
</div>
9+
</span>
10+
`;
11+
12+
exports[`Spin should render custom indicator when it's set 1`] = `
13+
<div class="ant-spin ant-spin-spinning">
14+
<div class="custom-indicator"></div>
15+
</div>
16+
`;
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { mount } from '@vue/test-utils'
2+
import { asyncExpect } from '@/tests/utils'
3+
import Spin from '..'
4+
5+
describe('Spin', () => {
6+
it('should only affect the spin element when set style to a nested <Spin>xx</Spin>', () => {
7+
const wrapper = mount({
8+
render () {
9+
return (
10+
<Spin style={{ background: 'red' }}>
11+
<div>content</div>
12+
</Spin>
13+
)
14+
},
15+
})
16+
expect(wrapper.html()).toMatchSnapshot()
17+
// expect(wrapper.findAll('.ant-spin-nested-loading').at(0).prop('style')).toBe(null)
18+
// expect(wrapper.findAll('.ant-spin').at(0).prop('style').background).toBe('red')
19+
})
20+
21+
it('should render custom indicator when it\'s set', () => {
22+
// const customIndicator = <div className='custom-indicator' />
23+
const wrapper = mount(
24+
{
25+
render () {
26+
return (
27+
<Spin><div slot='indicator' class='custom-indicator' /></Spin>
28+
)
29+
},
30+
})
31+
expect(wrapper.html()).toMatchSnapshot()
32+
})
33+
})

components/spin/index.en-US.md

+1-1
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 | React node of the spinning indicator | slot | - |
7+
| indicator | vue node of the spinning indicator | 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/table/__tests__/Table.filter.test.js

+17-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Vue from 'vue'
22
import { mount } from '@vue/test-utils'
3+
import { asyncExpect } from '@/tests/utils'
34
import Table from '..'
45

56
function $$ (className) {
@@ -199,27 +200,20 @@ describe('Table.filter', () => {
199200
})
200201
})
201202

202-
it('fires change event', (done) => {
203+
it('fires change event', async () => {
203204
const handleChange = jest.fn()
204205
const wrapper = mount(Table, getTableOptions({}, { change: handleChange }))
205206
const dropdownWrapper = mount({
206207
render () {
207208
return wrapper.find({ name: 'Trigger' }).vm.getComponent()
208209
},
209210
}, { sync: false })
210-
new Promise((reslove) => {
211-
Vue.nextTick(() => {
212-
dropdownWrapper.find({ name: 'MenuItem' }).trigger('click')
213-
dropdownWrapper.find('.confirm').trigger('click')
214-
reslove()
215-
})
216-
}).then(() => {
217-
Vue.nextTick(() => {
218-
expect(handleChange).toBeCalledWith({}, { name: ['boy'] }, {})
219-
Promise.resolve()
220-
})
221-
}).finally(() => {
222-
done()
211+
await asyncExpect(() => {
212+
dropdownWrapper.find({ name: 'MenuItem' }).trigger('click')
213+
dropdownWrapper.find('.confirm').trigger('click')
214+
})
215+
await asyncExpect(() => {
216+
expect(handleChange).toBeCalledWith({}, { name: ['boy'] }, {})
223217
})
224218
})
225219

@@ -266,7 +260,7 @@ describe('Table.filter', () => {
266260
}, 1000)
267261
})
268262

269-
it('works with JSX in controlled mode', (done) => {
263+
it('works with JSX in controlled mode', async () => {
270264
const { Column } = Table
271265

272266
const App = {
@@ -305,23 +299,17 @@ describe('Table.filter', () => {
305299
return wrapper.find({ name: 'Trigger' }).vm.getComponent()
306300
},
307301
}, { sync: false, attachToDocument: true })
308-
309-
new Promise((reslove) => {
310-
Vue.nextTick(() => {
311-
dropdownWrapper.find({ name: 'MenuItem' }).trigger('click')
312-
dropdownWrapper.find('.confirm').trigger('click')
313-
reslove()
314-
})
315-
}).then(() => {
302+
await asyncExpect(() => {
303+
dropdownWrapper.find({ name: 'MenuItem' }).trigger('click')
304+
dropdownWrapper.find('.confirm').trigger('click')
305+
})
306+
await asyncExpect(() => {
316307
expect(renderedNames(wrapper)).toEqual(['Jack'])
317308
dropdownWrapper.find('.clear').trigger('click')
318-
setTimeout(() => {
319-
expect(renderedNames(wrapper)).toEqual(['Jack', 'Lucy', 'Tom', 'Jerry'])
320-
Promise.resolve()
321-
}, 0)
322-
}).finally(() => {
323-
done()
324309
})
310+
await asyncExpect(() => {
311+
expect(renderedNames(wrapper)).toEqual(['Jack', 'Lucy', 'Tom', 'Jerry'])
312+
}, 0)
325313
})
326314

327315
it('works with grouping columns in controlled mode', (done) => {

0 commit comments

Comments
 (0)