diff --git a/containers/App.js b/containers/App.js index ce71cd8..f037ab4 100644 --- a/containers/App.js +++ b/containers/App.js @@ -85,7 +85,7 @@ const matchingVisibleTodosSelector = createSelector( selectMatchingTodos ); -const select = createStructuredSelector({ +export const select = createStructuredSelector({ matchingVisibleTodos: matchingVisibleTodosSelector, visibilityFilter: visibilityFilterSelector, currentTheme: currentThemeSelector, diff --git a/package.json b/package.json index 64d9ed9..1713d66 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,11 @@ "babel-core": "^5.6.18", "babel-loader": "^5.1.4", "babel-plugin-react-transform": "^1.1.0", + "chai": "^3.4.0", "expect": "^1.8.0", "express": "^4.13.3", "jsdom": "^5.6.1", - "mocha": "^2.2.5", + "mocha": "^2.3.3", "node-libs-browser": "^0.5.2", "raw-loader": "^0.5.1", "react-addons-test-utils": "^0.14.0", diff --git a/test/setup.js b/test/setup.js new file mode 100644 index 0000000..47d13a3 --- /dev/null +++ b/test/setup.js @@ -0,0 +1 @@ +import chai from 'chai'; diff --git a/test/specs.js b/test/specs.js new file mode 100644 index 0000000..47648e7 --- /dev/null +++ b/test/specs.js @@ -0,0 +1,50 @@ +import { expect } from 'chai'; + +import { select } from '../containers/App'; + +describe('App', () => { + describe('select function', () => { + + describe('matchingVisibleTodos', () => { + const allTodos = [ + { text: 'a', completed: false }, + { text: 'ab', completed: true }, + { text: 'b', completed: false }, + { text: 'bc', completed: true } + ]; + + it('returns all todos with empty search term and SHOW_ALL filter', () => { + const state = { + todos: allTodos, + searchTerm: '', + visibilityFilter: 'SHOW_ALL' + }; + expect(select(state).matchingVisibleTodos).to.eql(allTodos); + }); + + it('applies visibilty filter', () => { + const state = { + todos: allTodos, + searchTerm: '', + visibilityFilter: 'SHOW_COMPLETED' + }; + expect(select(state).matchingVisibleTodos).to.eql([ + { text: 'ab', completed: true }, + { text: 'bc', completed: true } + ]); + }); + + it('applies the search term', () => { + const state = { + todos: allTodos, + searchTerm: 'a', + visibilityFilter: 'SHOW_ALL' + }; + expect(select(state).matchingVisibleTodos).to.eql([ + { text: 'a', completed: false }, + { text: 'ab', completed: true } + ]); + }); + }); + }); +});