Skip to content

Commit 7da455d

Browse files
committed
test: add confirm & layout test
1 parent f639e95 commit 7da455d

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { mount } from '@vue/test-utils'
2+
import Vue from 'vue'
3+
import Layout from '..'
4+
5+
const { Sider, Content } = Layout
6+
7+
describe('Layout', () => {
8+
it('detect the sider as children', (done) => {
9+
const wrapper = mount(
10+
{
11+
render () {
12+
return (
13+
<Layout>
14+
<Sider>Sider</Sider>
15+
<Content>Content</Content>
16+
</Layout>
17+
)
18+
},
19+
},
20+
)
21+
Vue.nextTick(() => {
22+
expect(wrapper.find('.ant-layout').classes()).toContain('ant-layout-has-sider')
23+
done()
24+
})
25+
})
26+
27+
it('detect the sider inside the children', (done) => {
28+
const wrapper = mount(
29+
{
30+
render () {
31+
return (
32+
<Layout>
33+
<div><Sider>Sider</Sider></div>
34+
<Content>Content</Content>
35+
</Layout>
36+
)
37+
},
38+
}
39+
)
40+
Vue.nextTick(() => {
41+
expect(wrapper.find('.ant-layout').classes()).toContain('ant-layout-has-sider')
42+
done()
43+
})
44+
})
45+
46+
it('detect ant-layout-sider-has-trigger class in sider when ant-layout-sider-trigger div tag exists', (done) => {
47+
const wrapper = mount(
48+
{
49+
render () {
50+
return (
51+
<Layout>
52+
<div><Sider collapsible>Sider</Sider></div>
53+
<Content>Content</Content>
54+
</Layout>
55+
)
56+
},
57+
}
58+
)
59+
Vue.nextTick(() => {
60+
expect(wrapper.find('.ant-layout-sider').classes()).toContain('ant-layout-sider-has-trigger')
61+
done()
62+
})
63+
})
64+
})
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import Modal from '..'
2+
3+
const { confirm } = Modal
4+
5+
describe('Modal.confirm triggers callbacks correctly', () => {
6+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
7+
8+
afterEach(() => {
9+
errorSpy.mockReset()
10+
document.body.innerHTML = ''
11+
})
12+
13+
afterAll(() => {
14+
errorSpy.mockRestore()
15+
})
16+
17+
function $$ (className) {
18+
return document.body.querySelectorAll(className)
19+
}
20+
21+
function open (args) {
22+
confirm({
23+
title: 'Want to delete these items?',
24+
content: 'some descriptions',
25+
...args,
26+
})
27+
}
28+
29+
it('trigger onCancel once when click on cancel button', () => {
30+
const onCancel = jest.fn()
31+
const onOk = jest.fn()
32+
open({
33+
onCancel,
34+
onOk,
35+
})
36+
// first Modal
37+
$$('.ant-btn')[0].click()
38+
expect(onCancel.mock.calls.length).toBe(1)
39+
expect(onOk.mock.calls.length).toBe(0)
40+
})
41+
42+
it('trigger onOk once when click on ok button', () => {
43+
const onCancel = jest.fn()
44+
const onOk = jest.fn()
45+
open({
46+
onCancel,
47+
onOk,
48+
})
49+
// second Modal
50+
$$('.ant-btn-primary')[0].click()
51+
expect(onCancel.mock.calls.length).toBe(0)
52+
expect(onOk.mock.calls.length).toBe(1)
53+
})
54+
55+
it('should allow Modal.comfirm without onCancel been set', () => {
56+
open()
57+
// Third Modal
58+
$$('.ant-btn')[0].click()
59+
expect(errorSpy).not.toHaveBeenCalled()
60+
})
61+
62+
it('should allow Modal.comfirm without onOk been set', () => {
63+
open()
64+
// Fourth Modal
65+
$$('.ant-btn-primary')[0].click()
66+
expect(errorSpy).not.toHaveBeenCalled()
67+
})
68+
69+
it('ok only', () => {
70+
open({ okCancel: false })
71+
expect($$('.ant-btn')).toHaveLength(1)
72+
expect($$('.ant-btn')[0].innerHTML).toContain('OK')
73+
})
74+
})

0 commit comments

Comments
 (0)