-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix package name move todomvc-app-css to dep add missing dep fix description and move dep add enzyme tests
- Loading branch information
Showing
6 changed files
with
360 additions
and
11 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
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,90 @@ | ||
import expect from 'expect' | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import Footer from '../../components/Footer' | ||
import * as TodoFilters from '../../constants/TodoFilters' | ||
|
||
function setup(activeCount, completedCount, visibilityFilter) { | ||
const actions = { | ||
onClearCompleted: expect.createSpy(), | ||
onShow: expect.createSpy() | ||
} | ||
|
||
const component = shallow( | ||
<Footer activeCount={activeCount} | ||
completedCount={completedCount} | ||
visibilityFilter={visibilityFilter} | ||
{...actions} /> | ||
) | ||
|
||
return { | ||
component: component, | ||
actions: actions, | ||
todoCount: component.find('.todo-count'), | ||
filters: component.find('.filters'), | ||
clearCompleted: component.find('.clear-completed') | ||
} | ||
} | ||
|
||
describe('<Footer />', () => { | ||
it('should render a todo count for items not done', () => { | ||
const { todoCount } = setup(2, 0, TodoFilters.SHOW_ALL) | ||
expect(todoCount.text()).toMatch(/^2 items left/) | ||
}) | ||
|
||
it('should render a todo count for items done', () => { | ||
const { todoCount } = setup(0, 2, TodoFilters.SHOW_ALL) | ||
expect(todoCount.text()).toMatch(/^No items left/) | ||
}) | ||
|
||
it('should render three Link components', () => { | ||
const { filters } = setup(2, 0, TodoFilters.SHOW_ALL) | ||
expect(filters.find('Link').length).toEqual(3) | ||
}) | ||
|
||
it('should render an all Link', () => { | ||
const { filters } = setup(2, 0, TodoFilters.SHOW_ALL) | ||
const Link = filters.find('Link').at(0).render() | ||
expect(Link.text()).toMatch(/^All/) | ||
}) | ||
|
||
it('should render an active Link', () => { | ||
const { filters } = setup(2, 0, TodoFilters.SHOW_ALL) | ||
const Link = filters.find('Link').at(1).render() | ||
expect(Link.text()).toMatch(/^Active/) | ||
}) | ||
|
||
it('should render a completed Link', () => { | ||
const { filters } = setup(2, 0, TodoFilters.SHOW_ALL) | ||
const Link = filters.find('Link').at(2).render() | ||
expect(Link.text()).toMatch(/^Completed/) | ||
}) | ||
|
||
it('should call onShow on click of each Link', () => { | ||
const { filters, actions } = setup(2, 0, TodoFilters.SHOW_ALL) | ||
filters.find('Link').at(0).simulate('click') | ||
expect(actions.onShow).toHaveBeenCalled() | ||
}) | ||
|
||
it('should not show a clear completed button if todos are completed', () => { | ||
const { clearCompleted } = setup(2, 0, TodoFilters.SHOW_ALL) | ||
expect(clearCompleted.length).toEqual(0) | ||
}) | ||
|
||
it('should show a clear completed button if todos are completed', () => { | ||
const { clearCompleted } = setup(2, 2, TodoFilters.SHOW_ALL) | ||
expect(clearCompleted.length).toEqual(1) | ||
}) | ||
|
||
it('should render clear completed button with Clear Completed text', () => { | ||
const { clearCompleted } = setup(2, 2, TodoFilters.SHOW_ALL) | ||
expect(clearCompleted.text()).toEqual('Clear completed') | ||
}) | ||
|
||
it('should call onClearCompleted with clear completed button clicked', () => { | ||
const { clearCompleted, actions } = setup(2, 2, TodoFilters.SHOW_ALL) | ||
clearCompleted.simulate('click') | ||
expect(actions.onClearCompleted).toHaveBeenCalled() | ||
}) | ||
|
||
}) |
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,51 @@ | ||
import expect from 'expect' | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import Link from '../../components/Link' | ||
|
||
function setup(active, displayName) { | ||
const actions = { | ||
onClick: expect.createSpy() | ||
} | ||
|
||
const component = shallow( | ||
<Link active={active} {...actions}> | ||
{displayName} | ||
</Link> | ||
) | ||
|
||
return { | ||
component: component, | ||
actions: actions, | ||
listItem: component.find('li'), | ||
anchor: component.find('a') | ||
} | ||
} | ||
|
||
describe('<Link />', () => { | ||
it('should render a list item', () => { | ||
const { listItem } = setup(true, 'All') | ||
expect(listItem.length).toEqual(1) | ||
}) | ||
|
||
it('should render the specified text for the text', () => { | ||
const { anchor } = setup(true, 'All') | ||
expect(anchor.text()).toEqual('All') | ||
}) | ||
|
||
it('should render selected class if was passed active as true', () => { | ||
const { listItem } = setup(true, 'All') | ||
expect(listItem.find('.selected').length).toEqual(1) | ||
}) | ||
|
||
it('should not render selected class if was passed active as false', () => { | ||
const { listItem } = setup(false, 'All') | ||
expect(listItem.find('.selected').length).toEqual(0) | ||
}) | ||
|
||
it('should call onClick when clicked', () => { | ||
const { actions, anchor } = setup(true, 'All') | ||
anchor.props().onClick({ preventDefault: () => {}, target: { value: '' } }) | ||
expect(actions.onClick).toHaveBeenCalled() | ||
}) | ||
}) |
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,77 @@ | ||
import expect from 'expect' | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import Todo from '../../components/Todo' | ||
|
||
function setup() { | ||
const actions = { | ||
editTodo: expect.createSpy(), | ||
deleteTodo: expect.createSpy(), | ||
completeTodo: expect.createSpy() | ||
} | ||
|
||
const todo = { | ||
id: 0, | ||
text: 'Use Redux', | ||
complete: false | ||
} | ||
|
||
const component = shallow( | ||
<Todo todo={todo} {...actions} /> | ||
) | ||
|
||
return { | ||
component: component, | ||
actions: actions, | ||
listItem: component.find('li') | ||
} | ||
} | ||
|
||
describe('<Todo />', () => { | ||
it('should render a list item', () => { | ||
const { listItem } = setup() | ||
expect(listItem.length).toEqual(1) | ||
}) | ||
|
||
it('should render a view class when not editing', () => { | ||
const { component } = setup() | ||
component.setState({ editing: false }) | ||
const view = component.find('.view') | ||
const todoTextInput = component.find('TodoTextInput') | ||
expect(view.length).toEqual(1) | ||
expect(todoTextInput.length).toEqual(0) | ||
}) | ||
|
||
it('should render a TodoTextInput when editing', () => { | ||
const { component } = setup() | ||
component.setState({ editing: true }) | ||
const todoTextInput = component.find('TodoTextInput') | ||
const view = component.find('.view') | ||
expect(todoTextInput.length).toEqual(1) | ||
expect(view.length).toEqual(0) | ||
}) | ||
|
||
it('should render a complete todo checkbox', () => { | ||
const { component } = setup() | ||
component.setState({ editing: false }) | ||
const completeCheckbox = component.find('.toggle') | ||
expect(completeCheckbox.length).toEqual(1) | ||
}) | ||
|
||
it('should call completeTodo when todo checkbox toggled', () => { | ||
const { actions, component } = setup() | ||
component.setState({ editing: false }) | ||
const completeCheckbox = component.find('.toggle') | ||
completeCheckbox.simulate('change') | ||
expect(actions.completeTodo).toHaveBeenCalled() | ||
}) | ||
|
||
it('should call deleteTodo on click on delete button', () => { | ||
const { actions, component } = setup() | ||
component.setState({ editing: false }) | ||
const deleteButton = component.find('.destroy') | ||
deleteButton.simulate('click') | ||
expect(actions.deleteTodo).toHaveBeenCalled() | ||
}) | ||
|
||
}) |
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,55 @@ | ||
import expect from 'expect' | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import TodoList from '../../components/TodoList' | ||
|
||
function setup() { | ||
const actions = { | ||
editTodo: expect.createSpy(), | ||
deleteTodo: expect.createSpy(), | ||
completeTodo: expect.createSpy(), | ||
completeAll: expect.createSpy() | ||
} | ||
|
||
const todos = [ | ||
{ | ||
id: 0, | ||
text: 'Use Redux', | ||
completed: false | ||
} | ||
] | ||
|
||
const component = shallow( | ||
<TodoList todos={todos} completedCount={0} {...actions} /> | ||
) | ||
|
||
return { | ||
component: component, | ||
actions: actions, | ||
toggleAll: component.find('.toggle-all'), | ||
todoList: component.find('.todo-list') | ||
} | ||
} | ||
|
||
describe('<TodoList />', () => { | ||
it('should render a toggle all input', () => { | ||
const { toggleAll } = setup() | ||
expect(toggleAll.length).toEqual(1) | ||
}) | ||
|
||
it('should call completeAll when toggle all input changed', () => { | ||
const { actions, toggleAll } = setup() | ||
toggleAll.simulate('change') | ||
expect(actions.completeAll).toHaveBeenCalled() | ||
}) | ||
|
||
it('should render a todo list', () => { | ||
const { todoList } = setup() | ||
expect(todoList.length).toEqual(1) | ||
}) | ||
|
||
it('should render a list of todos', () => { | ||
const { todoList } = setup() | ||
expect(todoList.find('Todo').at(0).length).toEqual(1) | ||
}) | ||
}) |
Oops, something went wrong.