|
1 | 1 | jest.mock('rest') |
2 | 2 | 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' |
10 | 11 | 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 | | - }) |
22 | 12 |
|
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) |
31 | 29 | }) |
32 | | - }); |
| 30 | + }) |
33 | 31 |
|
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)) |
40 | 44 | }) |
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 | + }); |
42 | 64 |
|
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 | + }) |
54 | 77 | }) |
55 | 78 | }) |
56 | 79 | }); |
0 commit comments