Skip to content

Commit

Permalink
Finish porting examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 2, 2016
1 parent 110bf30 commit f53b786
Show file tree
Hide file tree
Showing 49 changed files with 72 additions and 85 deletions.
Binary file removed examples/async/favicon.ico
Binary file not shown.
5 changes: 2 additions & 3 deletions examples/async/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"devDependencies": {
"react-scripts": "0.4.0",
"react-scripts": "^0.4.0",
"redux-logger": "^2.6.1"
},
"dependencies": {
Expand All @@ -16,8 +16,7 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"test": "react-scripts test"
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "./node_modules/react-scripts/config/eslint.js"
Expand Down
35 changes: 21 additions & 14 deletions examples/buildAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@ var exampleDirs = fs.readdirSync(__dirname).filter((file) => {
return fs.statSync(path.join(__dirname, file)).isDirectory()
})

for (const dir of exampleDirs) {
// declare opts in this scope to avoid https://github.com/joyent/node/issues/9158
const opts = {
cwd: path.join(__dirname, dir),
stdio: 'inherit'
}
// Ordering is important here. `npm install` must come first.
var cmdArgs = [
{ cmd: 'npm', args: [ 'install' ] },
{ cmd: 'webpack', args: [ 'index.js' ] }
]

let result = {}
if (process.platform === 'win32') {
result = spawnSync('npm.cmd', [ 'install' ], opts)
} else {
result = spawnSync('npm', [ 'install' ], opts)
}
if (result.status !== 0) {
throw new Error('Building examples exited with non-zero')
for (const dir of exampleDirs) {
for (const cmdArg of cmdArgs) {
// declare opts in this scope to avoid https://github.com/joyent/node/issues/9158
const opts = {
cwd: path.join(__dirname, dir),
stdio: 'inherit'
}
let result = {}
if (process.platform === 'win32') {
result = spawnSync(cmdArg.cmd + '.cmd', cmdArg.args, opts)
} else {
result = spawnSync(cmdArg.cmd, cmdArg.args, opts)
}
if (result.status !== 0) {
throw new Error('Building examples exited with non-zero')
}
}
}
Binary file removed examples/counter/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"devDependencies": {
"enzyme": "^2.4.1",
"react-addons-test-utils": "^15.3.0",
"react-scripts": "0.4.0"
"react-scripts": "^0.4.0"
},
"dependencies": {
"react": "^15.3.0",
Expand Down
7 changes: 3 additions & 4 deletions examples/counter/src/components/Counter.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import expect from 'expect'
import React from 'react'
import { shallow } from 'enzyme'
import Counter from './Counter'

function setup(value = 0) {
const actions = {
onIncrement: expect.createSpy(),
onDecrement: expect.createSpy()
onIncrement: jest.fn(),
onDecrement: jest.fn()
}
const component = shallow(
<Counter value={value} {...actions} />
Expand Down Expand Up @@ -41,7 +40,7 @@ describe('Counter component', () => {
it('third button should not call onIncrement if the counter is even', () => {
const { buttons, actions } = setup(42)
buttons.at(2).simulate('click')
expect(actions.onIncrement).toNotHaveBeenCalled()
expect(actions.onIncrement).not.toHaveBeenCalled()
})

it('third button should call onIncrement if the counter is odd', () => {
Expand Down
1 change: 0 additions & 1 deletion examples/counter/src/reducers/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import counter from './index'

describe('reducers', () => {
Expand Down
Binary file removed examples/real-world/favicon.ico
Binary file not shown.
5 changes: 2 additions & 3 deletions examples/real-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"devDependencies": {
"react-scripts": "0.4.0",
"react-scripts": "^0.4.0",
"redux-devtools": "^3.3.1",
"redux-devtools-dock-monitor": "^1.1.1",
"redux-devtools-log-monitor": "^1.0.11",
Expand All @@ -23,8 +23,7 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"test": "react-scripts test"
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "./node_modules/react-scripts/config/eslint.js"
Expand Down
Binary file removed examples/shopping-cart/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/shopping-cart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"devDependencies": {
"enzyme": "^2.4.1",
"react-addons-test-utils": "^15.3.0",
"react-scripts": "0.4.0"
"react-scripts": "^0.4.0"
},
"dependencies": {
"react": "^15.3.0",
Expand Down
3 changes: 1 addition & 2 deletions examples/shopping-cart/src/components/Cart.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import expect from 'expect'
import React from 'react'
import { shallow } from 'enzyme'
import Cart from './Cart'
import Product from './Product'

function setup(total, products = []) {
const actions = {
onCheckoutClicked: expect.createSpy()
onCheckoutClicked: jest.fn()
}

const component = shallow(
Expand Down
1 change: 0 additions & 1 deletion examples/shopping-cart/src/components/Product.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import React from 'react'
import { shallow } from 'enzyme'
import Product from './Product'
Expand Down
3 changes: 1 addition & 2 deletions examples/shopping-cart/src/components/ProductItem.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import expect from 'expect'
import React from 'react'
import { shallow } from 'enzyme'
import Product from './Product'
import ProductItem from './ProductItem'

function setup(product) {
const actions = {
onAddToCartClicked: expect.createSpy()
onAddToCartClicked: jest.fn()
}

const component = shallow(
Expand Down
1 change: 0 additions & 1 deletion examples/shopping-cart/src/components/ProductsList.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import React from 'react'
import { shallow } from 'enzyme'
import ProductsList from './ProductsList'
Expand Down
1 change: 0 additions & 1 deletion examples/shopping-cart/src/reducers/cart.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import cart from './cart'

describe('reducers', () => {
Expand Down
1 change: 0 additions & 1 deletion examples/shopping-cart/src/reducers/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import { getTotal, getCartProducts } from './index'

describe('selectors', () => {
Expand Down
1 change: 0 additions & 1 deletion examples/shopping-cart/src/reducers/products.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import products from './products'

describe('reducers', () => {
Expand Down
Binary file removed examples/todomvc/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/todomvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"devDependencies": {
"enzyme": "^2.4.1",
"react-addons-test-utils": "^15.3.0",
"react-scripts": "0.4.0"
"react-scripts": "^0.4.0"
},
"dependencies": {
"classnames": "^2.2.5",
Expand Down
1 change: 0 additions & 1 deletion examples/todomvc/src/actions/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import * as types from '../constants/ActionTypes'
import * as actions from './index'

Expand Down
7 changes: 3 additions & 4 deletions examples/todomvc/src/components/Footer.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import Footer from './Footer'
Expand All @@ -9,8 +8,8 @@ function setup(propOverrides) {
completedCount: 0,
activeCount: 0,
filter: SHOW_ALL,
onClearCompleted: expect.createSpy(),
onShow: expect.createSpy()
onClearCompleted: jest.fn(),
onShow: jest.fn()
}, propOverrides)

const renderer = TestUtils.createRenderer()
Expand Down Expand Up @@ -76,7 +75,7 @@ describe('components', () => {
const [ , filters ] = output.props.children
const filterLink = filters.props.children[1].props.children
filterLink.props.onClick({})
expect(props.onShow).toHaveBeenCalledWith(SHOW_ACTIVE)
expect(props.onShow).toBeCalledWith(SHOW_ACTIVE)
})

it('shouldnt show clear button when no completed todos', () => {
Expand Down
7 changes: 3 additions & 4 deletions examples/todomvc/src/components/Header.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import Header from './Header'
import TodoTextInput from './TodoTextInput'

function setup() {
const props = {
addTodo: expect.createSpy()
addTodo: jest.fn()
}

const renderer = TestUtils.createRenderer()
Expand Down Expand Up @@ -42,9 +41,9 @@ describe('components', () => {
const { output, props } = setup()
const input = output.props.children[1]
input.props.onSave('')
expect(props.addTodo.calls.length).toBe(0)
expect(props.addTodo).not.toBeCalled()
input.props.onSave('Use Redux')
expect(props.addTodo.calls.length).toBe(1)
expect(props.addTodo).toBeCalled()
})
})
})
15 changes: 7 additions & 8 deletions examples/todomvc/src/components/MainSection.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import MainSection from './MainSection'
Expand All @@ -20,11 +19,11 @@ function setup(propOverrides) {
}
],
actions: {
editTodo: expect.createSpy(),
deleteTodo: expect.createSpy(),
completeTodo: expect.createSpy(),
completeAll: expect.createSpy(),
clearCompleted: expect.createSpy()
editTodo: jest.fn(),
deleteTodo: jest.fn(),
completeTodo: jest.fn(),
completeAll: jest.fn(),
clearCompleted: jest.fn()
}
}, propOverrides)

Expand Down Expand Up @@ -73,7 +72,7 @@ describe('components', () => {
const { output, props } = setup()
const [ toggle ] = output.props.children
toggle.props.onChange({})
expect(props.actions.completeAll).toHaveBeenCalled()
expect(props.actions.completeAll).toBeCalled()
})
})

Expand All @@ -100,7 +99,7 @@ describe('components', () => {
const { output, props } = setup()
const [ , , footer ] = output.props.children
footer.props.onClearCompleted()
expect(props.actions.clearCompleted).toHaveBeenCalled()
expect(props.actions.clearCompleted).toBeCalled()
})
})

Expand Down
15 changes: 7 additions & 8 deletions examples/todomvc/src/components/TodoItem.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import TodoItem from './TodoItem'
Expand All @@ -11,9 +10,9 @@ function setup( editing = false ) {
text: 'Use Redux',
completed: false
},
editTodo: expect.createSpy(),
deleteTodo: expect.createSpy(),
completeTodo: expect.createSpy()
editTodo: jest.fn(),
deleteTodo: jest.fn(),
completeTodo: jest.fn()
}

const renderer = TestUtils.createRenderer()
Expand Down Expand Up @@ -66,14 +65,14 @@ describe('components', () => {
const { output, props } = setup()
const input = output.props.children.props.children[0]
input.props.onChange({})
expect(props.completeTodo).toHaveBeenCalledWith(0)
expect(props.completeTodo).toBeCalledWith(0)
})

it('button onClick should call deleteTodo', () => {
const { output, props } = setup()
const button = output.props.children.props.children[2]
button.props.onClick({})
expect(props.deleteTodo).toHaveBeenCalledWith(0)
expect(props.deleteTodo).toBeCalledWith(0)
})

it('label onDoubleClick should put component in edit state', () => {
Expand All @@ -100,13 +99,13 @@ describe('components', () => {
it('TodoTextInput onSave should call editTodo', () => {
const { output, props } = setup(true)
output.props.children.props.onSave('Use Redux')
expect(props.editTodo).toHaveBeenCalledWith(0, 'Use Redux')
expect(props.editTodo).toBeCalledWith(0, 'Use Redux')
})

it('TodoTextInput onSave should call deleteTodo if text is empty', () => {
const { output, props } = setup(true)
output.props.children.props.onSave('')
expect(props.deleteTodo).toHaveBeenCalledWith(0)
expect(props.deleteTodo).toBeCalledWith(0)
})

it('TodoTextInput onSave should exit component from edit state', () => {
Expand Down
9 changes: 4 additions & 5 deletions examples/todomvc/src/components/TodoTextInput.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import TodoTextInput from './TodoTextInput'

function setup(propOverrides) {
const props = Object.assign({
onSave: expect.createSpy(),
onSave: jest.fn(),
text: 'Use Redux',
placeholder: 'What needs to be done?',
editing: false,
Expand Down Expand Up @@ -56,7 +55,7 @@ describe('components', () => {
it('should call onSave on return key press', () => {
const { output, props } = setup()
output.props.onKeyDown({ which: 13, target: { value: 'Use Redux' } })
expect(props.onSave).toHaveBeenCalledWith('Use Redux')
expect(props.onSave).toBeCalledWith('Use Redux')
})

it('should reset state on return key press if newTodo', () => {
Expand All @@ -69,13 +68,13 @@ describe('components', () => {
it('should call onSave on blur', () => {
const { output, props } = setup()
output.props.onBlur({ target: { value: 'Use Redux' } })
expect(props.onSave).toHaveBeenCalledWith('Use Redux')
expect(props.onSave).toBeCalledWith('Use Redux')
})

it('shouldnt call onSave on blur if newTodo', () => {
const { output, props } = setup({ newTodo: true })
output.props.onBlur({ target: { value: 'Use Redux' } })
expect(props.onSave.calls.length).toBe(0)
expect(props.onSave).not.toBeCalled()
})
})
})
1 change: 0 additions & 1 deletion examples/todomvc/src/reducers/todos.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import todos from './todos'
import * as types from '../constants/ActionTypes'

Expand Down
Binary file removed examples/todos-with-undo/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/todos-with-undo/src/containers/VisibleTodoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const getVisibleTodos = (todos, filter) => {
return todos.filter(t => t.completed)
case 'SHOW_ACTIVE':
return todos.filter(t => !t.completed)
default:
throw new Error('Unknown filter: ' + filter)
}
}

Expand Down
Binary file removed examples/todos/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion examples/todos/src/actions/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import * as actions from './index'

describe('todo actions', () => {
Expand Down
1 change: 0 additions & 1 deletion examples/todos/src/reducers/todos.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect'
import todos from './todos'

describe('todos reducer', () => {
Expand Down
Binary file removed examples/tree-view/favicon.ico
Binary file not shown.
Loading

0 comments on commit f53b786

Please sign in to comment.