| author | ymh <ymh.work@gmail.com> |
| Mon, 08 Oct 2018 18:35:47 +0200 | |
| changeset 168 | ea92f4fe783d |
| parent 14 | df6780e48eb5 |
| permissions | -rw-r--r-- |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
1 |
// import React from 'react'; |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
2 |
// import { shallow, mount } from 'enzyme'; |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
3 |
// import NoteInput from '../NoteInput'; |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
4 |
// import { Plain } from 'slate' |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
6 |
// const setup = (propOverrides, doMount=false) => { |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
7 |
// const props = Object.assign({ |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
8 |
// addNote: jest.fn(), |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
9 |
// session: { _id: 'abcd' }, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
10 |
// autoSubmit: false, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
11 |
// setAutoSubmit: jest.fn(), |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
12 |
// annotationCategories: [] |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
13 |
// }, propOverrides); |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
15 |
// const renderFn = doMount?mount:shallow; |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
16 |
// const wrapper = renderFn(<NoteInput {...props} />); |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
18 |
// return { |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
19 |
// props, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
20 |
// wrapper, |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
21 |
// } |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
22 |
// }; |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
|
| 14 | 24 |
// Element.focus() doesn't work |
25 |
// @see https://stackoverflow.com/questions/42213522/mocking-document-createrange-for-jest |
|
| 8 | 26 |
beforeAll(() => { |
27 |
window.getSelection = () => { |
|
28 |
return { |
|
| 14 | 29 |
removeAllRanges: () => {}, |
30 |
addRange: () => {} |
|
31 |
}; |
|
32 |
}; |
|
33 |
||
34 |
window.Range = function Range() {}; |
|
35 |
||
36 |
const createContextualFragment = (html) => { |
|
37 |
const div = document.createElement('div'); |
|
38 |
div.innerHTML = html; |
|
39 |
return div.children[0]; // so hokey it's not even funny |
|
40 |
}; |
|
41 |
||
42 |
Range.prototype.createContextualFragment = (html) => createContextualFragment(html); |
|
43 |
||
44 |
// HACK: Polyfil that allows codemirror to render in a JSDOM env. |
|
45 |
window.document.createRange = function createRange() { |
|
46 |
return { |
|
47 |
setEnd: () => {}, |
|
48 |
setStart: () => {}, |
|
49 |
getBoundingClientRect: () => { |
|
50 |
return { right: 0 }; |
|
51 |
}, |
|
52 |
compareBoundaryPoints: () => { |
|
53 |
return 0; |
|
54 |
}, |
|
55 |
getClientRects: () => [], |
|
56 |
createContextualFragment, |
|
| 8 | 57 |
}; |
58 |
}; |
|
59 |
}); |
|
60 |
||
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
describe('Notes container Component', () => { |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
test('render', () => { |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
63 |
//pass |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
}); |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
65 |
// test('render', () => { |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
66 |
// const { wrapper } = setup({}, true); |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
67 |
// expect(wrapper.exists()).toBe(true) |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
68 |
// }); |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
|
| 14 | 70 |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
71 |
// test('button is disabled when there is no text', () => { |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
72 |
// const { props, wrapper } = setup({}, true); |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
73 |
// const button = wrapper.find('button'); |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
75 |
// expect(button.prop('disabled')).toBe(true); |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
76 |
// }); |
| 14 | 77 |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
78 |
// test('button is not disabled when there is text', () => { |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
79 |
// const { props, wrapper } = setup({}, true); |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
80 |
// const button = wrapper.find('button'); |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
81 |
// const editor = wrapper.find('SlateEditor').find('Editor').node; |
| 14 | 82 |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
83 |
// // FIXME simulate('change') doesn't work |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
84 |
// editor.onChange(Plain.deserialize('Hello world')); |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
85 |
|
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
86 |
// expect(button.prop('disabled')).toBe(false); |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
14
diff
changeset
|
87 |
// }); |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
|
| 14 | 89 |
// test('click button', () => { |
90 |
// const { props, wrapper } = setup({}, true); |
|
91 |
// wrapper.find('button').simulate('click'); |
|
92 |
// expect(props.addNote.mock.calls.length).toBe(1); |
|
93 |
// }); |
|
94 |
||
95 |
// test('note value on clickbutton', () => { |
|
96 |
// const { props, wrapper } = setup({}, true); |
|
97 |
// // This does nothing... must find a way to make it work |
|
98 |
// wrapper.find('SlateEditor').simulate('change', {target: {value: 'note text'}}); |
|
99 |
// wrapper.find('button').simulate('click'); |
|
100 |
// expect(props.addNote.mock.calls.length).toBe(1); |
|
101 |
// // cf. previous comment |
|
102 |
// //expect(props.addNote.mock.calls[0]).toEqual(['note text']); |
|
103 |
// }); |
|
104 |
||
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
105 |
}); |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |