-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
141bff7
commit 098e7ea
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { mount } from '@vue/test-utils' | ||
import Vue from 'vue' | ||
import Layout from '..' | ||
|
||
const { Sider, Content } = Layout | ||
|
||
describe('Layout', () => { | ||
it('detect the sider as children', (done) => { | ||
const wrapper = mount( | ||
{ | ||
render () { | ||
return ( | ||
<Layout> | ||
<Sider>Sider</Sider> | ||
<Content>Content</Content> | ||
</Layout> | ||
) | ||
}, | ||
}, | ||
) | ||
Vue.nextTick(() => { | ||
expect(wrapper.find('.ant-layout').classes()).toContain('ant-layout-has-sider') | ||
done() | ||
}) | ||
}) | ||
|
||
it('detect the sider inside the children', (done) => { | ||
const wrapper = mount( | ||
{ | ||
render () { | ||
return ( | ||
<Layout> | ||
<div><Sider>Sider</Sider></div> | ||
<Content>Content</Content> | ||
</Layout> | ||
) | ||
}, | ||
} | ||
) | ||
Vue.nextTick(() => { | ||
expect(wrapper.find('.ant-layout').classes()).toContain('ant-layout-has-sider') | ||
done() | ||
}) | ||
}) | ||
|
||
it('detect ant-layout-sider-has-trigger class in sider when ant-layout-sider-trigger div tag exists', (done) => { | ||
const wrapper = mount( | ||
{ | ||
render () { | ||
return ( | ||
<Layout> | ||
<div><Sider collapsible>Sider</Sider></div> | ||
<Content>Content</Content> | ||
</Layout> | ||
) | ||
}, | ||
} | ||
) | ||
Vue.nextTick(() => { | ||
expect(wrapper.find('.ant-layout-sider').classes()).toContain('ant-layout-sider-has-trigger') | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Modal from '..' | ||
|
||
const { confirm } = Modal | ||
|
||
describe('Modal.confirm triggers callbacks correctly', () => { | ||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}) | ||
|
||
afterEach(() => { | ||
errorSpy.mockReset() | ||
document.body.innerHTML = '' | ||
}) | ||
|
||
afterAll(() => { | ||
errorSpy.mockRestore() | ||
}) | ||
|
||
function $$ (className) { | ||
return document.body.querySelectorAll(className) | ||
} | ||
|
||
function open (args) { | ||
confirm({ | ||
title: 'Want to delete these items?', | ||
content: 'some descriptions', | ||
...args, | ||
}) | ||
} | ||
|
||
it('trigger onCancel once when click on cancel button', () => { | ||
const onCancel = jest.fn() | ||
const onOk = jest.fn() | ||
open({ | ||
onCancel, | ||
onOk, | ||
}) | ||
// first Modal | ||
$$('.ant-btn')[0].click() | ||
expect(onCancel.mock.calls.length).toBe(1) | ||
expect(onOk.mock.calls.length).toBe(0) | ||
}) | ||
|
||
it('trigger onOk once when click on ok button', () => { | ||
const onCancel = jest.fn() | ||
const onOk = jest.fn() | ||
open({ | ||
onCancel, | ||
onOk, | ||
}) | ||
// second Modal | ||
$$('.ant-btn-primary')[0].click() | ||
expect(onCancel.mock.calls.length).toBe(0) | ||
expect(onOk.mock.calls.length).toBe(1) | ||
}) | ||
|
||
it('should allow Modal.comfirm without onCancel been set', () => { | ||
open() | ||
// Third Modal | ||
$$('.ant-btn')[0].click() | ||
expect(errorSpy).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('should allow Modal.comfirm without onOk been set', () => { | ||
open() | ||
// Fourth Modal | ||
$$('.ant-btn-primary')[0].click() | ||
expect(errorSpy).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('ok only', () => { | ||
open({ okCancel: false }) | ||
expect($$('.ant-btn')).toHaveLength(1) | ||
expect($$('.ant-btn')[0].innerHTML).toContain('OK') | ||
}) | ||
}) |