Move react test into local view

This commit is contained in:
Thomas Walpole 2019-04-04 16:49:47 -07:00
parent d2dc9fa27e
commit 7bbeac5474
2 changed files with 59 additions and 11 deletions

View File

@ -0,0 +1,45 @@
<!doctype html>
<html>
<head>
<script src="https://unpkg.com/react/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>
</head>
<body>
<div id="root"></div>
<script>
// https://codepen.io/gaearon/pen/VmmPgp?editors=0010
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = { value: '' };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({ value: event.target.value });
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}
render() {
return (
React.createElement("form", { onSubmit: this.handleSubmit },
React.createElement("label", null, "Name:",
React.createElement("input", { type: "text", value: this.state.value, onChange: this.handleChange })),
React.createElement("input", { type: "submit", value: "Submit" })));
}}
ReactDOM.render(
React.createElement(NameForm, null),
document.getElementById('root'));
</script>
</body>
</html>

View File

@ -472,18 +472,21 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
describe 'with react' do
context 'controlled components' do
it 'can set and clear a text field' do
session.visit 'https://reactjs.org/docs/forms.html'
session.all(:css, 'h2#controlled-components ~ p a', text: 'Try it on CodePen')[0].click
session.within_frame(:css, 'iframe.result-iframe:not([src=""])', wait: 10) do
session.fill_in('Name:', with: 'abc')
session.accept_prompt 'A name was submitted: abc' do
session.click_button('Submit')
end
session.fill_in('Name:', with: '')
session.accept_prompt(/A name was submitted: $/) do
session.click_button('Submit')
end
# session.visit 'https://reactjs.org/docs/forms.html'
# session.all(:css, 'h2#controlled-components ~ p a', text: 'Try it on CodePen')[0].click
# copied into local view
session.visit 'react'
# Not necessary when accessed locally
# session.within_frame(:css, 'iframe.result-iframe:not([src=""])', wait: 10) do
session.fill_in('Name:', with: 'abc')
session.accept_prompt 'A name was submitted: abc' do
session.click_button('Submit')
end
session.fill_in('Name:', with: '')
session.accept_prompt(/A name was submitted: $/) do
session.click_button('Submit')
end
# end
end
end
end