-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbootstrap-unexpected-markdown.js
148 lines (123 loc) · 3.58 KB
/
bootstrap-unexpected-markdown.js
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
146
147
148
/*global unexpected:true, TestUtils:true, React:true, sinon:true*/
require( './src/tests/helpers/emulateDom');
global.unexpected = require('unexpected')
.clone()
.use(require('./src/unexpected-react'));
unexpected.output.preferredWidth = 80;
global.TestUtils = require('react-dom/test-utils');
global.React = require('react');
global.PropTypes = require('prop-types');
global.createRenderer = require('react-test-renderer/shallow').createRenderer;
global.createClass = require('create-react-class');
const TodoItem = createClass({
displayName: 'TodoItem',
propTypes: {
id: PropTypes.number,
label: PropTypes.string
},
getInitialState() {
return {
completed: false
};
},
onClick() {
this.setState({
completed: true
});
},
render() {
return (
<div
id={'todo-' + this.props.id}
className={`item ${ this.state.completed ? 'completed' : 'incomplete'}`}
onClick={this.onClick}
>
<span className="id">{this.props.id}</span>
<span className="label">{this.props.label}</span>
<span>{this.state.completed ? 'Completed!' : 'Todo'}</span>
</div>
);
}
});
const TodoList = createClass({
displayName: 'TodoList',
propTypes: {
children: PropTypes.node
},
getInitialState() {
return { clicked: {} };
},
onClick(index) {
// State mutation, this is not recommended, but saves us rebuilding each time
this.state.clicked[index] = true;
this.setState({
clicked: this.state.clicked
});
},
noop() {},
render() {
const children = this.props.children.map(child => {
return React.cloneElement(child, {
key: child.props.id,
onClick: this.onClick.bind(this, child.props.id),
clicked: !!this.state.clicked[child.props.id],
onMouseDown: this.noop
});
});
return (
<div>
<div className="items">
{ children }
</div>
<div className="add-new-item">
<input placeholder="Enter something to do" />
</div>
</div>
);
}
});
const App = createClass({
displayName: 'App',
getInitialState() {
return { clickTestClicked: false };
},
onClickTest() {
this.setState({ clickTestClicked: true });
},
render() {
return (
<div>
<div className="other-button"><button>Not clicked</button></div>
<div className="click-test">
<button className="click-test" onClick={this.onClickTest}>
{this.state.clickTestClicked ? 'Button was clicked' : 'Not clicked'}
</button>
</div>
</div>
);
}
});
global.TodoItem = TodoItem;
global.TodoList = TodoList;
global.App = App;
const MyButton = createClass({
displayName: 'MyButton',
getInitialState () {
return {
count: 0
};
},
onClick () {
const { count } = this.state;
this.setState({ count: count + 1 });
},
render() {
const { count } = this.state;
return (
<button onClick={ this.onClick }>
Button was clicked { count } times
</button>
);
}
});
global.MyButton = MyButton;