Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(MainPage): update cases #49

Merged
merged 2 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 96 additions & 9 deletions src/pages/__tests__/MainPage.test.tsx
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 src/pages/__tests__/__snapshots__/MainPage.test.tsx.snap
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>
`;