Skip to content

Commit 2bc3cdd

Browse files
committed
update test for todomvc
1 parent 38f3332 commit 2bc3cdd

File tree

2 files changed

+68
-46
lines changed

2 files changed

+68
-46
lines changed

examples/todomvc/src/components/MainSection.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const id = _=>_
1010
const anyToId = ()=>id
1111

1212
const MainSection = ({todos,filter}) => {
13-
if(!todos||!filter) return <section className="main"/>
1413
const completedCount = todos.reduce((count, todo) => todo.done ? count + 1 : count, 0);
1514

1615
const filteredTodos = filter(todos);
Lines changed: 68 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,79 @@
11
jest.mock('rest')
22
import rest from 'rest'
3-
import React from 'react'
4-
import when from 'when'
5-
import Intent from '../../todo.action'
6-
import MainSection from '../MainSection.jsx'
7-
import Most from '../../../../../lib/react-most'
8-
import {do$, historyStreamOf} from '../../../../../lib/test-utils'
9-
import TestUtils from 'react-addons-test-utils'
3+
import React from 'react'
4+
import when from 'when'
5+
import Intent from '../../todo.action'
6+
import MainSection from '../MainSection.jsx'
7+
import Footer from '../Footer.jsx'
8+
import Most from '../../../../../lib/react-most'
9+
import {do$, historyStreamOf} from '../../../../../lib/test-utils'
10+
import TestUtils from 'react-addons-test-utils'
1011
describe('MainSection', ()=>{
11-
let mainSectionWrapper, mainSection
12-
let response = '[{"text": "Try React Most","completed": false,"id": 0},{"text": "Give it a Star on Github","completed": false,"id": 1}]'
13-
beforeEach(()=>{
14-
rest.__return(response)
15-
mainSectionWrapper = TestUtils.renderIntoDocument(
16-
<Most>
17-
<MainSection history={true}/>
18-
</Most>
19-
)
20-
mainSection = TestUtils.findRenderedComponentWithType(mainSectionWrapper, MainSection);
21-
})
2212

23-
describe('data sink', ()=>{
24-
it('should render default state', ()=>{
25-
expect(mainSection.state.todos).toEqual([
26-
{id:0, text:'Loading...dadada', done:false},
27-
])
28-
})
29-
it('should get data from rest response to MainSection', ()=>{
30-
return historyStreamOf(mainSection).take$(1).then(state=>expect(state.todos).toEqual(JSON.parse(response)))
13+
describe('display', ()=> {
14+
it('correct counts on footer', ()=> {
15+
let mainSection = TestUtils.renderIntoDocument(
16+
<Most>
17+
<MainSection
18+
todos={[
19+
{id:0, text:'Loading...dadada', done:false},
20+
{id:1, text:'dadada', done:false},
21+
]}
22+
filter={_=>_}
23+
/>
24+
</Most>
25+
)
26+
let footer = TestUtils.findRenderedComponentWithType(mainSection, Footer);
27+
expect(footer.props.completedCount).toBe(0)
28+
expect(footer.props.activeCount).toBe(2)
3129
})
32-
});
30+
})
3331

34-
describe('edit sink', ()=>{
35-
it('should update todo 0 item text', ()=>{
36-
do$([
37-
()=>mainSection.actions.fromPromise(when(Intent.Edit({id:0, text:'hehedayo'}))),
38-
])
39-
return historyStreamOf(mainSection).take$(1).then(state=>expect(state.todos[0]).toEqual({"id": 0, "text": "hehedayo"}))
32+
describe('behavior', ()=> {
33+
let mainSectionWrapper, mainSection, send
34+
let response = '[{"text": "Try React Most","completed": false,"id": 0},{"text": "Give it a Star on Github","completed": false,"id": 1}]'
35+
beforeEach(()=>{
36+
rest.__return(response)
37+
mainSectionWrapper = TestUtils.renderIntoDocument(
38+
<Most>
39+
<MainSection history={true}/>
40+
</Most>
41+
)
42+
mainSection = TestUtils.findRenderedComponentWithType(mainSectionWrapper, MainSection);
43+
send = intent => mainSection.actions.fromPromise(when(intent))
4044
})
41-
});
45+
describe('data sink', ()=>{
46+
it('should render default state', ()=>{
47+
expect(mainSection.state.todos).toEqual([
48+
{id:0, text:'Loading...dadada', done:false},
49+
])
50+
})
51+
it('should get data from rest response to MainSection', ()=>{
52+
return historyStreamOf(mainSection).take$(1).then(state=>expect(state.todos).toEqual(JSON.parse(response)))
53+
})
54+
});
55+
56+
describe('edit sink', ()=>{
57+
it('should update todo 0 item text', ()=>{
58+
do$([
59+
()=>send(Intent.Edit({id:0, text:'hehedayo'})),
60+
])
61+
return historyStreamOf(mainSection).take$(2).then(state=>expect(state.todos[0]).toEqual({"id": 0, "text": "hehedayo"}))
62+
})
63+
});
4264

43-
describe('clear sink', ()=> {
44-
it('should remove all done todos', ()=>{
45-
do$([
46-
()=>mainSection.actions.fromPromise(when(Intent.Edit({id:0,text:'done',completed:true}))),
47-
()=>mainSection.actions.fromPromise(when(Intent.Clear())),
48-
])
49-
return historyStreamOf(mainSection)
50-
.take$(2)
51-
.then(state=>{
52-
expect(state.todos).toEqual([])
53-
})
65+
describe('clear sink', ()=> {
66+
it('should remove all done todos', ()=>{
67+
do$([
68+
()=>send(Intent.Edit({id:0,text:'done',completed:true})),
69+
()=>send(Intent.Clear()),
70+
])
71+
return historyStreamOf(mainSection)
72+
.take$(3)
73+
.then(state=>{
74+
expect(state.todos).toEqual([{"completed": false, "id": 1, "text": "Give it a Star on Github"}])
75+
})
76+
})
5477
})
5578
})
5679
});

0 commit comments

Comments
 (0)