Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"react", | ||
], | ||
"plugins": [] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "airbnb", | ||
"rules": { | ||
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], | ||
}, | ||
"env" :{ | ||
"browser": true, | ||
"es6": true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "react-redux-example", | ||
"version": "1.0.0", | ||
"description": "react-redux-example", | ||
"main": "webpack.config.js", | ||
"scripts": { | ||
"start": "webpack-dev-server --colors --inline --content-base .", | ||
"test": "mocha --compilers js:babel-core/register --require ./test/setup.js --recursive" | ||
}, | ||
"author": "kdchang", | ||
"license": "MIT", | ||
"dependencies": { | ||
"react": "^15.3.0", | ||
"react-dom": "^15.3.0" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.13.2", | ||
"babel-eslint": "^6.1.2", | ||
"babel-loader": "^6.2.4", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babel-preset-react": "^6.11.1", | ||
"chai": "^3.5.0", | ||
"enzyme": "^2.4.1", | ||
"eslint": "^3.3.1", | ||
"eslint-config-airbnb": "^10.0.1", | ||
"eslint-loader": "^1.5.0", | ||
"eslint-plugin-import": "^1.13.0", | ||
"eslint-plugin-jsx-a11y": "^2.1.0", | ||
"eslint-plugin-react": "^6.1.1", | ||
"html-webpack-plugin": "^2.22.0", | ||
"jsdom": "^9.5.0", | ||
"mocha": "^3.0.2", | ||
"react-addons-test-utils": "^15.3.1", | ||
"webpack": "^1.13.1", | ||
"webpack-dev-server": "^1.14.1" | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Appendix03/react-addons-test-utils-example/src/components/Main/Main.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import TodoHeader from '../TodoHeader'; | ||
import TodoList from '../TodoList'; | ||
|
||
const Main = () => ( | ||
<div> | ||
<h1>Todos</h1> | ||
<TodoHeader /> | ||
<TodoList /> | ||
</div> | ||
); | ||
|
||
export default Main; |
1 change: 1 addition & 0 deletions
1
Appendix03/react-addons-test-utils-example/src/components/Main/index.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Main'; |
25 changes: 25 additions & 0 deletions
25
Appendix03/react-addons-test-utils-example/src/components/TodoHeader/TodoHeader.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
|
||
class TodoHeader extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.toggleButton = this.toggleButton.bind(this); | ||
this.state = { | ||
isActivated: false, | ||
}; | ||
} | ||
toggleButton() { | ||
this.setState({ | ||
isActivated: !this.state.isActivated, | ||
}) | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<button disabled={this.state.isActivated} onClick={this.toggleButton}>Add</button> | ||
</div> | ||
); | ||
}; | ||
} | ||
|
||
export default TodoHeader; |
1 change: 1 addition & 0 deletions
1
Appendix03/react-addons-test-utils-example/src/components/TodoHeader/index.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './TodoHeader'; |
15 changes: 15 additions & 0 deletions
15
Appendix03/react-addons-test-utils-example/src/components/TodoList/TodoList.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
|
||
const TodoList = (props) => ( | ||
<div> | ||
<ul> | ||
{ | ||
props.todos.map((todo, index) => ( | ||
<li key={index}>{todo.text}</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
); | ||
|
||
export default TodoList; |
1 change: 1 addition & 0 deletions
1
Appendix03/react-addons-test-utils-example/src/components/TodoList/index.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './TodoList'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import Main from './components/Main'; | ||
|
||
ReactDOM.render( | ||
<Main />, | ||
document.getElementById('app') | ||
); |
16 changes: 16 additions & 0 deletions
16
Appendix03/react-addons-test-utils-example/test/renderIntoDocument.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
import { expect } from 'chai'; | ||
import { findDOMNode } from 'react-dom'; | ||
import TodoHeader from '../src/components/TodoHeader'; | ||
|
||
describe('Simulate Event', function () { | ||
it('When click the button, it will be toggle', function () { | ||
const TodoHeaderApp = TestUtils.renderIntoDocument(<TodoHeader />); | ||
const TodoHeaderDOM = findDOMNode(TodoHeaderApp); | ||
const button = TodoHeaderDOM.querySelector('button'); | ||
TestUtils.Simulate.click(button); | ||
let todoHeaderButtonAfterClick = TodoHeaderDOM.querySelector('button').disabled; | ||
expect(todoHeaderButtonAfterClick).to.equal(true); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import jsdom from 'jsdom'; | ||
|
||
if (typeof document === 'undefined') { | ||
global.document = jsdom.jsdom('<!doctype html><html><head></head><body></body></html>'); | ||
global.window = document.defaultView; | ||
global.navigator = global.window.navigator; | ||
} |
18 changes: 18 additions & 0 deletions
18
Appendix03/react-addons-test-utils-example/test/shallowRender.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
import { expect } from 'chai'; | ||
import Main from '../src/components/Main'; | ||
|
||
function shallowRender(Component) { | ||
const renderer = TestUtils.createRenderer(); | ||
renderer.render(<Component/>); | ||
return renderer.getRenderOutput(); | ||
} | ||
|
||
describe('Shallow Rendering', function () { | ||
it('Main title should be h1', function () { | ||
const todoItem = shallowRender(Main); | ||
expect(todoItem.props.children[0].type).to.equal('h1'); | ||
expect(todoItem.props.children[0].props.children).to.equal('Todos'); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
Appendix03/react-addons-test-utils-example/test/shallowRenderProps.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
import { expect } from 'chai'; | ||
import TodoList from '../src/components/TodoList'; | ||
|
||
const shallowRender = (Component, props) => { | ||
const renderer = TestUtils.createRenderer(); | ||
renderer.render(<Component {...props}/>); | ||
return renderer.getRenderOutput(); | ||
} | ||
|
||
describe('Shallow Props Rendering', () => { | ||
it('TodoList props check', () => { | ||
const todos = [{ id: 0, text: 'reading'}, { id: 1, text: 'coding'}]; | ||
const todoList = shallowRender(TodoList, {todos: todos}); | ||
expect(todoList.props.children.type).to.equal('ul'); | ||
expect(todoList.props.children.props.children[0].props.children).to.equal('reading'); | ||
expect(todoList.props.children.props.children[1].props.children).to.equal('coding'); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
Appendix03/react-addons-test-utils-example/webpack.config.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
|
||
const HTMLWebpackPluginConfig = new HtmlWebpackPlugin({ | ||
template: `${__dirname}/src/index.html`, | ||
filename: 'index.html', | ||
inject: 'body', | ||
}); | ||
|
||
module.exports = { | ||
entry: [ | ||
'./src/index.js', | ||
], | ||
output: { | ||
path: `${__dirname}/dist`, | ||
filename: 'index_bundle.js', | ||
}, | ||
module: { | ||
preLoaders: [ | ||
{ | ||
test: /\.jsx$\\.js$/, | ||
loader: 'eslint-loader', | ||
include: `${__dirname}/src`, | ||
exclude: /bundle\.js$/ | ||
} | ||
], | ||
loaders: [{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
loader: 'babel-loader', | ||
query: { | ||
presets: ['es2015', 'react'], | ||
}, | ||
}], | ||
}, | ||
devServer: { | ||
inline: true, | ||
port: 8008, | ||
}, | ||
plugins: [HTMLWebpackPluginConfig], | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"react", | ||
], | ||
"plugins": [] | ||
} |
Empty file.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"react", | ||
], | ||
"plugins": [] | ||
} |