-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathbutton-spec.js
More file actions
145 lines (121 loc) · 4.52 KB
/
button-spec.js
File metadata and controls
145 lines (121 loc) · 4.52 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React from 'react';
import { shallow } from 'enzyme';
import Button, { ButtonIcon } from '../src/scripts/Button';
import Icon from '../src/scripts/Icon';
describe('Button', () => {
it('should render button with className', () => {
const wrapper = shallow(<Button />);
expect(wrapper.prop('className')).toEqual('slds-button');
});
it('should render button with children', () => {
const children = <span>Test</span>;
const wrapper = shallow(<Button>{ children }</Button>);
expect(wrapper.contains(children)).toBe(true);
});
it('should render button with specific className', () => {
const className = 'test';
const wrapper = shallow(<Button className={ className } />);
expect(wrapper.hasClass(className)).toBe(true);
});
it('should render button with label', () => {
const label = 'Label';
const wrapper = shallow(<Button label={ label } />);
expect(wrapper.text()).toEqual(label);
});
it('should render button with alt', () => {
const alt = 'alt';
const wrapper = shallow(<Button alt={ alt } />);
expect(wrapper.find('.slds-assistive-text').text()).toEqual(alt);
});
it('should render button based on a type', () => {
const type = 'brand';
const wrapper = shallow(<Button type={ type } />);
expect(wrapper.hasClass(`slds-button--${type}`)).toBe(true);
});
it('should render button based on a size', () => {
const size = 'small';
const wrapper = shallow(<Button size={ size } />);
expect(wrapper.hasClass(`slds-button--${size}`)).toBe(true);
});
it('should render button based on htmlType', () => {
const htmlType = 'button';
const wrapper = shallow(<Button htmlType={ htmlType } />);
expect(wrapper.prop('type')).toEqual(htmlType);
});
it('should render disabled button', () => {
const wrapper = shallow(<Button disabled />);
expect(wrapper.prop('disabled')).toBe(true);
});
it('should render selected button', () => {
const wrapper = shallow(<Button selected />);
expect(wrapper.hasClass('slds-is-selected')).toBe(true);
});
it('should render button with icon based on size and align', () => {
const props = {
icon: 'download',
iconAlign: 'left',
iconSize: 'small',
};
const expectedProps = {
icon: props.icon,
align: props.iconAlign,
size: props.iconSize,
iconStyle: undefined,
};
const label = 'Label';
const wrapper = shallow(<Button { ...props } label={ label } />);
expect(wrapper.contains(<ButtonIcon { ...expectedProps } inverse={ false } />)).toBe(true);
expect(wrapper.html().indexOf(`${label}</`)).not.toEqual(-1);
});
it('should render button with icon more', () => {
const iconMore = 'down';
const wrapper = shallow(<Button iconMore={ iconMore } />);
expect(wrapper.contains(
<ButtonIcon icon={ iconMore } align='right' size='small' iconStyle={undefined} />
)).toBe(true);
});
it('should render button with props', () => {
const wrapper = shallow(<Button onClick={ () => {} } />);
expect(wrapper.prop('onClick')).toBeInstanceOf(Function);
});
});
describe('ButtonIcon', () => {
it('should render button icon with className', () => {
const wrapper = shallow(<ButtonIcon />);
expect(wrapper.prop('className')).toEqual('slds-button__icon');
});
it('should render button icon with specific className', () => {
const className = 'test';
const wrapper = shallow(<ButtonIcon className={ className } />);
expect(wrapper.hasClass(className)).toBe(true);
});
it('should render button icon based on align', () => {
const align = 'right';
const wrapper = shallow(<ButtonIcon align={ align } />);
expect(wrapper.hasClass(`slds-button__icon--${align}`)).toBe(true);
});
it('should render button icon based on size', () => {
const size = 'medium';
const wrapper = shallow(<ButtonIcon size={ size } />);
expect(wrapper.hasClass(`slds-button__icon--${size}`)).toBe(true);
});
it('should render button icon inversed', () => {
const wrapper = shallow(<ButtonIcon inverse />);
expect(wrapper.hasClass('slds-button--icon-inverse')).toBe(true);
});
it('should call Icon component with props', () => {
const props = {
icon: 'test',
test: 'test',
};
const expectedProps = {
icon: 'test',
test: 'test',
textColor: null,
className: 'slds-button__icon',
style: undefined,
};
const wrapper = shallow(<ButtonIcon { ...props } />);
expect(wrapper.equals(<Icon { ...expectedProps } />)).toBe(true);
});
});