forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-spec.js
More file actions
65 lines (54 loc) · 2.67 KB
/
Copy pathindex-spec.js
File metadata and controls
65 lines (54 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from 'react';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import assert from 'power-assert';
import SplitButton from '../../src/split-button/index';
import '../../src/split-button/style.js';
Enzyme.configure({ adapter: new Adapter() });
/* eslint-disable no-undef,react/jsx-filename-extension */
describe('SplitButton', () => {
const menu = ['a', 'b'].map(item => <SplitButton.Item key={item}>{item}</SplitButton.Item>);
let wrapper;
afterEach(() => {
if (wrapper) {
wrapper.unmount();
wrapper = null;
}
});
describe('render', () => {
it('should render', () => {
const wrapper = mount(<SplitButton label="hello world">{menu}</SplitButton>);
assert(wrapper.find('div.next-split-btn').length === 1);
});
it('should controlled selectedkeys', () => {
const wrapper = mount(<SplitButton label="hello world" visible selectedKeys={['a']} selectMode="single">{menu}</SplitButton>);
wrapper.setProps({ selectedKeys: ['b'] });
assert(wrapper.find('li[title="b"][role="menuitem"]').hasClass('next-selected'));
});
it('should controlled popup visible', () => {
const wrapper = mount(<SplitButton label="hello world">{menu}</SplitButton>);
assert(wrapper.find('.next-menu').length === 0);
wrapper.setProps({ visible: true });
assert(wrapper.find('.next-menu').length === 1);
});
});
describe('action', () => {
it('should click trigger to open the popup', () => {
let visible;
const wrapper = mount(<SplitButton label="hello world" onVisibleChange={vis => visible = vis}>{menu}</SplitButton>);
wrapper.find('button.next-split-btn-trigger').simulate('click');
assert(wrapper.find('.next-menu').length === 1);
assert(visible);
});
it('should select in uncontrolled mode', () => {
const wrapper = mount(<SplitButton label="hello world" visible selectMode="single">{menu}</SplitButton>);
wrapper.find('li[title="b"][role="menuitem"]').simulate('click');
assert(wrapper.find('li[title="b"][role="menuitem"]').hasClass('next-selected'));
});
it('should select in controlled mode', () => {
const wrapper = mount(<SplitButton label="hello world" visible selectedKeys={['a']} selectMode="single">{menu}</SplitButton>);
wrapper.find('li[title="b"][role="menuitem"]').simulate('click');
assert(wrapper.find('li[title="a"][role="menuitem"]').hasClass('next-selected'));
});
});
});