Created
August 31, 2016 16:24
-
-
Save davidguttman/2736bd0548200750cee534b8a14f8f12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From b449231011d1400ea8fd18b881c53289e501feeb Mon Sep 17 00:00:00 2001 | |
From: David Guttman <david@davidguttman.com> | |
Date: Wed, 31 Aug 2016 09:17:46 -0700 | |
Subject: [PATCH] forms: ensure fields clear on submit + tests | |
--- | |
manuscript/code/forms/06-state-input-multi.jsx | 4 ++-- | |
manuscript/code/forms/07-basic-validation.jsx | 4 ++-- | |
manuscript/code/forms/08-field-component-field.jsx | 2 +- | |
manuscript/code/forms/package.json | 3 ++- | |
manuscript/code/forms/tests/e2e/e2e.test.js | 9 ++++----- | |
5 files changed, 11 insertions(+), 11 deletions(-) | |
diff --git a/manuscript/code/forms/06-state-input-multi.jsx b/manuscript/code/forms/06-state-input-multi.jsx | |
index 9383347..1d10bed 100644 | |
--- a/manuscript/code/forms/06-state-input-multi.jsx | |
+++ b/manuscript/code/forms/06-state-input-multi.jsx | |
@@ -37,14 +37,14 @@ module.exports = React.createClass({ | |
<input | |
placeholder='Name' | |
name='name' | |
- value={this.state.fields.name} | |
+ value={this.state.fields.name || ''} | |
onChange={this.onInputChange} | |
/> | |
<input | |
placeholder='Email' | |
name='email' | |
- value={this.state.fields.email} | |
+ value={this.state.fields.email || ''} | |
onChange={this.onInputChange} | |
/> | |
diff --git a/manuscript/code/forms/07-basic-validation.jsx b/manuscript/code/forms/07-basic-validation.jsx | |
index 19ac5da..1c30820 100644 | |
--- a/manuscript/code/forms/07-basic-validation.jsx | |
+++ b/manuscript/code/forms/07-basic-validation.jsx | |
@@ -52,7 +52,7 @@ module.exports = React.createClass({ | |
<input | |
placeholder='Name' | |
name='name' | |
- value={this.state.fields.name} | |
+ value={this.state.fields.name || ''} | |
onChange={this.onInputChange} | |
/> | |
@@ -63,7 +63,7 @@ module.exports = React.createClass({ | |
<input | |
placeholder='Email' | |
name='email' | |
- value={this.state.fields.email} | |
+ value={this.state.fields.email || ''} | |
onChange={this.onInputChange} | |
/> | |
diff --git a/manuscript/code/forms/08-field-component-field.jsx b/manuscript/code/forms/08-field-component-field.jsx | |
index 14faf13..7829068 100644 | |
--- a/manuscript/code/forms/08-field-component-field.jsx | |
+++ b/manuscript/code/forms/08-field-component-field.jsx | |
@@ -35,7 +35,7 @@ module.exports = React.createClass({ | |
<div> | |
<input | |
placeholder={this.props.placeholder} | |
- value={this.state.value} | |
+ value={this.state.value || ''} | |
onChange={this.onChange} | |
/> | |
<span style={{ color: 'red' }}>{ this.state.error }</span> | |
diff --git a/manuscript/code/forms/package.json b/manuscript/code/forms/package.json | |
index ac95907..a29c756 100644 | |
--- a/manuscript/code/forms/package.json | |
+++ b/manuscript/code/forms/package.json | |
@@ -26,6 +26,7 @@ | |
"validator": "5.1.0" | |
}, | |
"devDependencies": { | |
- "concurrently": "^2.2.0" | |
+ "concurrently": "^2.2.0", | |
+ "nightwatch": "^0.9.8" | |
} | |
} | |
diff --git a/manuscript/code/forms/tests/e2e/e2e.test.js b/manuscript/code/forms/tests/e2e/e2e.test.js | |
index a6e11c6..c0c26cc 100644 | |
--- a/manuscript/code/forms/tests/e2e/e2e.test.js | |
+++ b/manuscript/code/forms/tests/e2e/e2e.test.js | |
@@ -1,13 +1,9 @@ | |
-/*==============================================================================*/ | |
-/* Nightwatch Recorder generated Thu Aug 25 2016 10:49:53 GMT-0700 (PDT) */ | |
-/*==============================================================================*/ | |
- | |
module.exports = { | |
'forms test case': function(client) { | |
return client | |
.pause(3000) | |
.resizeWindow(1024, 636) | |
- .url('http://192.168.2.13:9966/') | |
+ .url('http://127.0.0.1:9966/') | |
.waitForElementVisible('body', 10000) | |
.useXpath() | |
@@ -111,6 +107,7 @@ module.exports = { | |
.clearValue("input[name='email']") | |
.setValue("input[name='email']", "baz") | |
.click("input[type='submit']") | |
+ .assert.value("input[name='email']", "") | |
/* submit form */ | |
.useXpath() | |
.waitForElementPresent("//a[normalize-space(text())='TOC']") | |
@@ -146,6 +143,7 @@ module.exports = { | |
.clearValue("input[name='email']") | |
.setValue("input[name='email']", "david@js.la") | |
.click("input[type='submit']") | |
+ .assert.value("input[name='email']", "") | |
/* submit form */ | |
.useXpath() | |
.waitForElementPresent("//a[normalize-space(text())='TOC']") | |
@@ -165,6 +163,7 @@ module.exports = { | |
.setValue("div:nth-child(13) form div:nth-child(3) input", "acco@mazzo.com") | |
.waitForElementPresent("input[type='submit']") | |
.click("input[type='submit']") | |
+ .assert.value("div:nth-child(13) form div:nth-child(3) input", "") | |
/* submit form */ | |
.click("input[Placeholder='Name']") | |
.waitForElementPresent("div:nth-child(13) form div:nth-child(1) input") | |
-- | |
1.7.7+GitX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment