Add popup node snapshot test for Cascader

This commit is contained in:
afc163 2017-02-26 16:48:42 +08:00
parent 05b20c6a9f
commit 30f2a1ed94
2 changed files with 252 additions and 0 deletions

View File

@ -0,0 +1,181 @@
exports[`Cascader can be selected 1`] = `
<div>
<div
class="ant-cascader-menus ant-cascader-menus-placement-bottomLeft ">
<div>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand ant-cascader-menu-item-active"
title="Zhejiang">
Zhejiang
</li>
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand"
title="Jiangsu">
Jiangsu
</li>
</ul>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand"
title="Hangzhou">
Hangzhou
</li>
</ul>
</div>
</div>
</div>
`;
exports[`Cascader can be selected 2`] = `
<div>
<div
class="ant-cascader-menus ant-cascader-menus-placement-bottomLeft ">
<div>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand ant-cascader-menu-item-active"
title="Zhejiang">
Zhejiang
</li>
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand"
title="Jiangsu">
Jiangsu
</li>
</ul>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand ant-cascader-menu-item-active"
title="Hangzhou">
Hangzhou
</li>
</ul>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item"
title="West Lake">
West Lake
</li>
</ul>
</div>
</div>
</div>
`;
exports[`Cascader can be selected 3`] = `
<div>
<div
class="ant-cascader-menus ant-cascader-menus-placement-bottomLeft ant-cascader-menus-hidden">
<div>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand ant-cascader-menu-item-active"
title="Zhejiang">
Zhejiang
</li>
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand"
title="Jiangsu">
Jiangsu
</li>
</ul>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand ant-cascader-menu-item-active"
title="Hangzhou">
Hangzhou
</li>
</ul>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-active"
title="West Lake">
West Lake
</li>
</ul>
</div>
</div>
</div>
`;
exports[`Cascader can be selected 4`] = `null`;
exports[`Cascader popup correctly when panel is hidden 1`] = `
<div>
<div
class="ant-cascader-menus ant-cascader-menus-empty ant-cascader-menus-placement-bottomLeft ant-cascader-menus-hidden">
<div />
</div>
</div>
`;
exports[`Cascader popup correctly when panel is open 1`] = `
<div>
<div
class="ant-cascader-menus ant-cascader-menus-placement-bottomLeft ">
<div>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand"
title="Zhejiang">
Zhejiang
</li>
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand"
title="Jiangsu">
Jiangsu
</li>
</ul>
</div>
</div>
</div>
`;
exports[`Cascader popup correctly with defaultValue 1`] = `
<div>
<div
class="ant-cascader-menus ant-cascader-menus-placement-bottomLeft ">
<div>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand ant-cascader-menu-item-active"
title="Zhejiang">
Zhejiang
</li>
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand"
title="Jiangsu">
Jiangsu
</li>
</ul>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item ant-cascader-menu-item-expand ant-cascader-menu-item-active"
title="Hangzhou">
Hangzhou
</li>
</ul>
<ul
class="ant-cascader-menu">
<li
class="ant-cascader-menu-item"
title="West Lake">
West Lake
</li>
</ul>
</div>
</div>
</div>
`;

View File

@ -0,0 +1,71 @@
import React from 'react';
import { render, mount } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import Cascader from '..';
const options = [{
value: 'zhejiang',
label: 'Zhejiang',
children: [{
value: 'hangzhou',
label: 'Hangzhou',
children: [{
value: 'xihu',
label: 'West Lake',
}],
}],
}, {
value: 'jiangsu',
label: 'Jiangsu',
children: [{
value: 'nanjing',
label: 'Nanjing',
children: [{
value: 'zhonghuamen',
label: 'Zhong Hua Men',
}],
}],
}];
describe('Cascader', () => {
it('popup correctly when panel is hidden', () => {
const wrapper = mount(
<Cascader options={options} />
);
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
});
it('popup correctly when panel is open', () => {
const wrapper = mount(
<Cascader options={options} />
);
wrapper.find('input').simulate('click');
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
});
it('popup correctly with defaultValue', () => {
const wrapper = mount(
<Cascader options={options} defaultValue={['zhejiang', 'hangzhou']} />
);
wrapper.find('input').simulate('click');
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
});
it('can be selected', () => {
const wrapper = mount(<Cascader options={options} />);
wrapper.find('input').simulate('click');
let popupWrapper = mount(wrapper.find('Trigger').node.getComponent());
popupWrapper.find('.ant-cascader-menu').at(0).find('.ant-cascader-menu-item').at(0)
.simulate('click');
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
popupWrapper = mount(wrapper.find('Trigger').node.getComponent());
popupWrapper.find('.ant-cascader-menu').at(1).find('.ant-cascader-menu-item').at(0)
.simulate('click');
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
popupWrapper = mount(wrapper.find('Trigger').node.getComponent());
popupWrapper.find('.ant-cascader-menu').at(2).find('.ant-cascader-menu-item').at(0)
.simulate('click');
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
});
});