| author | ymh <ymh.work@gmail.com> |
| Mon, 08 Oct 2018 18:35:47 +0200 | |
| changeset 168 | ea92f4fe783d |
| parent 13 | d6eef0e9f7e1 |
| permissions | -rw-r--r-- |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
// cf. http://redux.js.org/docs/recipes/WritingTests.html |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
|
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
import * as actions from '../notesActions' |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
import * as types from '../../constants/actionTypes' |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
|
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
describe('actions', () => { |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
|
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
it('should create an action to add a note', () => { |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
9 |
const text = 'hello world'; |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
10 |
const dateNote = Date.now(); |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
11 |
const data = { |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
12 |
raw: { |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
13 |
document: { |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
14 |
nodes: [ |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
15 |
{ |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
16 |
object: 'block', |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
17 |
type: 'paragraph', |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
18 |
nodes: [ |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
19 |
{ |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
20 |
object: 'text', |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
21 |
leaves: [ |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
22 |
{ |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
23 |
text: text, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
24 |
}, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
25 |
], |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
26 |
}, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
27 |
], |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
28 |
}, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
29 |
], |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
30 |
}, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
31 |
}, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
32 |
plain: text, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
33 |
html: text, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
34 |
startedAt: dateNote, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
35 |
finishedAt: dateNote + 10000, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
36 |
categories: [], |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
37 |
marginComment: 'empty', |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
38 |
} |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
39 |
const session = { _id: 'abcd123' } |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
const expectedAction = { |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
type: types.ADD_NOTE, |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
note: { |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
43 |
_id: expect.stringMatching(/[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}/), |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
44 |
session: session._id |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
} |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
} |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
48 |
const receivedAction = actions.addNote(session, data); |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
expect(receivedAction).toMatchObject(expectedAction); |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
|
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
}) |
| 13 | 52 |
}) |