-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(MainPage): update cases * test(MainPage): update cases
- Loading branch information
Showing
2 changed files
with
242 additions
and
9 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 |
---|---|---|
@@ -1,14 +1,101 @@ | ||
// import React from 'react'; | ||
// import { mount } from 'enzyme'; | ||
// import MainPage from '../MainPage'; | ||
// import menuData from '../../assets/sider.json'; | ||
// import 'nino-cli/scripts/setup'; | ||
import React from 'react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import MainPage from '../MainPage'; | ||
import 'nino-cli/scripts/setup'; | ||
import { MappingProps } from '../../../server/controller/save'; | ||
const menuData = [ | ||
{ | ||
key: 'all', | ||
title: 'all', | ||
}, | ||
{ | ||
key: '读书', | ||
title: '读书', | ||
children: [ | ||
{ | ||
key: '摘抄', | ||
value: '摘抄', | ||
}, | ||
{ | ||
key: '思路', | ||
value: '思路', | ||
}, | ||
], | ||
}, | ||
]; | ||
const dataSource = [ | ||
{ | ||
id: '32e89f38116080d6b7608cf2137f3c96', | ||
title: '音程表', | ||
url: './assets/mapping/32e89f38116080d6b7608cf2137f3c96.json', | ||
createTime: 1559522075108, | ||
modifyTime: 1559523700429, | ||
type: '音乐', | ||
subType: '乐理', | ||
category: 'markdown', | ||
}, | ||
{ | ||
id: '7a73d21c13f1eb55053d4af66e0d057b', | ||
title: 'windows 下安装 rust', | ||
url: './assets/mapping/7a73d21c13f1eb55053d4af66e0d057b.json', | ||
createTime: 1559617097664, | ||
modifyTime: 1559633639037, | ||
type: 'Rust', | ||
subType: '安装', | ||
category: 'markdown', | ||
}, | ||
]; | ||
|
||
describe('MainPage', () => { | ||
it('render correctly', () => { | ||
// const wrapper = mount( | ||
// <MainPage dataSource={dataSource} menuData={menuData} />, | ||
// ); | ||
expect(1).toBe(1); | ||
const wrapper = shallow( | ||
<MainPage | ||
dataSource={dataSource as MappingProps[]} | ||
menuData={menuData} | ||
onEdit={null} | ||
/>, | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('onEdit of init button works correctly', () => { | ||
const onEdit = jest.fn(); | ||
const wrapper = mount( | ||
<MainPage dataSource={[]} menuData={[]} onEdit={onEdit} />, | ||
); | ||
wrapper | ||
.find('Button') | ||
.props() | ||
.onClick(); | ||
expect(onEdit).toHaveBeenCalled(); | ||
}); | ||
|
||
it('onEdit and onDelete in Dropdown works correctly', () => { | ||
const onEdit = jest.fn(); | ||
const onDelete = jest.fn(); | ||
const wrapper = mount( | ||
<MainPage | ||
dataSource={dataSource as MappingProps[]} | ||
menuData={menuData} | ||
onEdit={onEdit} | ||
onDelete={onDelete} | ||
/>, | ||
); | ||
wrapper | ||
.find('Item') | ||
.first() | ||
.simulate('contextmenu'); | ||
wrapper | ||
.find('.ant-dropdown-menu-item') | ||
.first() | ||
.props() | ||
.onClick(); | ||
expect(onEdit).toHaveBeenCalled(); | ||
wrapper | ||
.find('.ant-dropdown-menu-item') | ||
.last() | ||
.props() | ||
.onClick(); | ||
expect(onDelete).toHaveBeenCalled(); | ||
}); | ||
}); |
146 changes: 146 additions & 0 deletions
146
src/pages/__tests__/__snapshots__/MainPage.test.tsx.snap
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,146 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`MainPage render correctly 1`] = ` | ||
<Adapter | ||
className="MainPage" | ||
> | ||
<Sider | ||
collapsible={true} | ||
theme="light" | ||
> | ||
<Menu | ||
mode="inline" | ||
onClick={[Function]} | ||
selectedKeys={ | ||
Array [ | ||
"all", | ||
] | ||
} | ||
> | ||
<MenuItem | ||
key="all" | ||
> | ||
all | ||
</MenuItem> | ||
<SubMenu | ||
key="读书" | ||
title="读书" | ||
> | ||
<MenuItem | ||
key="摘抄" | ||
> | ||
摘抄 | ||
</MenuItem> | ||
<MenuItem | ||
key="思路" | ||
> | ||
思路 | ||
</MenuItem> | ||
</SubMenu> | ||
</Menu> | ||
</Sider> | ||
<Adapter> | ||
<Adapter | ||
style={ | ||
Object { | ||
"margin": "0 16px", | ||
} | ||
} | ||
> | ||
<Breadcrumb | ||
separator="/" | ||
style={ | ||
Object { | ||
"margin": "16px 0", | ||
} | ||
} | ||
> | ||
<BreadcrumbItem | ||
separator="/" | ||
> | ||
all | ||
</BreadcrumbItem> | ||
<BreadcrumbItem | ||
separator="/" | ||
> | ||
all | ||
</BreadcrumbItem> | ||
</Breadcrumb> | ||
<Button | ||
block={false} | ||
ghost={false} | ||
htmlType="button" | ||
loading={false} | ||
onClick={[Function]} | ||
style={ | ||
Object { | ||
"position": "absolute", | ||
"right": 24, | ||
"top": 10, | ||
} | ||
} | ||
> | ||
<Icon | ||
type="plus" | ||
/> | ||
</Button> | ||
<div | ||
style={ | ||
Object { | ||
"background": "#fff", | ||
"minHeight": "100%", | ||
"padding": 24, | ||
} | ||
} | ||
> | ||
<List | ||
bordered={false} | ||
dataSource={ | ||
Array [ | ||
Object { | ||
"category": "markdown", | ||
"createTime": 1559522075108, | ||
"id": "32e89f38116080d6b7608cf2137f3c96", | ||
"modifyTime": 1559523700429, | ||
"subType": "乐理", | ||
"title": "音程表", | ||
"type": "音乐", | ||
"url": "./assets/mapping/32e89f38116080d6b7608cf2137f3c96.json", | ||
}, | ||
Object { | ||
"category": "markdown", | ||
"createTime": 1559617097664, | ||
"id": "7a73d21c13f1eb55053d4af66e0d057b", | ||
"modifyTime": 1559633639037, | ||
"subType": "安装", | ||
"title": "windows 下安装 rust", | ||
"type": "Rust", | ||
"url": "./assets/mapping/7a73d21c13f1eb55053d4af66e0d057b.json", | ||
}, | ||
] | ||
} | ||
loading={false} | ||
pagination={false} | ||
renderItem={[Function]} | ||
size="large" | ||
split={true} | ||
/> | ||
</div> | ||
</Adapter> | ||
<Adapter | ||
style={ | ||
Object { | ||
"textAlign": "center", | ||
} | ||
} | ||
> | ||
<div> | ||
你睡了一下午,醒的时候屋子里黑漆漆,一点声音都没有。抬头望了望窗外,天还没完全黑。四处摸了摸,在枕头下找到手机,打开后屏幕亮起,干净,没有一条信息 | ||
</div> | ||
<div> | ||
打开电脑,打开 github。pull request 写得很菜,collaborators 都在喷你,但忽然就不孤独了 | ||
</div> | ||
</Adapter> | ||
</Adapter> | ||
</Adapter> | ||
`; |