Skip to content

Commit 4052641

Browse files
committed
more test on MainSection's behavior
1 parent 1769a89 commit 4052641

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

examples/todomvc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"build": "NODE_ENV=production browserify src/app.jsx --extension=.jsx --extension=.es6 | java -jar bin/compiler.jar > public/app.js",
2222
"start": "ecstatic -p 8000 public",
2323
"watch": "watchify -d src/app.jsx --extension=.jsx --extension=.es6 -o public/app.js -dv",
24-
"test": "jest"
24+
"test": "jest --coverage"
2525
},
2626
"jest": {
2727
"moduleFileExtensions": [

examples/todomvc/src/components/MainSection.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const remote = 'todos.json';
77
import * as most from 'most'
88
import Intent from '../todo.action'
99
import r from 'ramda'
10-
const anyToId = ()=>r.identity
10+
const alwaysId = ()=>r.identity
1111

1212
const MainSection = ({todos,filter}) => {
1313
const completedCount = todos.reduce((count, todo) => todo.done ? count + 1 : count, 0);
@@ -42,7 +42,7 @@ export default connect((intent$)=>{
4242
Delete: id => r.over(lensTodos, r.filter(todo=>todo.id!=id)),
4343
Filter: filter=>state=>({ filter }),
4444
Done: index=>r.over(lensTodoComplete(index), r.not),
45-
_:anyToId
45+
_: alwaysId
4646
}))
4747
let data$ = most.fromPromise(rest(remote))
4848
.map(x=>JSON.parse(x.entity))

examples/todomvc/src/components/__tests__/MainSection-spec.jsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,45 @@ describe('MainSection', ()=>{
108108
})
109109
})
110110
})
111+
112+
describe('delete', ()=> {
113+
it('should remove todos id 0', ()=>{
114+
do$([
115+
()=>send(Intent.Delete(0)),
116+
])
117+
return historyStreamOf(mainSection)
118+
.take$(2)
119+
.then(state=>{
120+
expect(state.todos).toEqual([{"done": false, "id": 1, "text": "Give it a Star on Github"}])
121+
})
122+
})
123+
})
124+
125+
describe('done', ()=> {
126+
it('should complete todo 0', ()=>{
127+
do$([
128+
()=>send(Intent.Done(0)),
129+
])
130+
return historyStreamOf(mainSection)
131+
.take$(2)
132+
.then(state=>{
133+
expect(state.todos).toEqual([{"done": true, "id": 0, "text": "Try React Most"}, {"done": false, "id": 1, "text": "Give it a Star on Github"}])
134+
})
135+
})
136+
})
137+
138+
describe('click filter completed', ()=> {
139+
it('should only use SHOW_COMPLETED filter', ()=>{
140+
do$([
141+
()=>send(Intent.Edit({id:0, done:true}, 0)),
142+
()=>send(Intent.Filter(FILTER_FUNC['SHOW_COMPLETED'])),
143+
])
144+
return historyStreamOf(mainSection)
145+
.take$(3)
146+
.then(state=>{
147+
expect(state.filter).toEqual(FILTER_FUNC['SHOW_COMPLETED'])
148+
})
149+
})
150+
})
111151
})
112152
});

0 commit comments

Comments
 (0)