Skip to content

Commit 88cfaca

Browse files
committed
Test subthought
1 parent b6ef2bc commit 88cfaca

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Diff for: src/components/__tests__/EmptyThought.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { App } from '../App'
2+
import App from '../../App'
33

44
// eslint-disable-next-line fp/no-let
55
let wrapper = null
@@ -16,7 +16,7 @@ afterAll(() => {
1616
})
1717

1818
it('create and edit empty thought', async () => {
19-
const thoughts = wrapper.find('div.transformContain div ul')
19+
const thoughts = wrapper.find('div.transformContain div ul.children')
2020
const thought = thoughts.find(
2121
'li.leaf div.thought-container div.thought div.editable',
2222
)

Diff for: src/components/__tests__/SubThought.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
2-
import { App } from '../App'
2+
import App from '../../App'
3+
import { getThoughtsRanked } from '../../util.js'
34

45
// eslint-disable-next-line fp/no-let
56
let wrapper = null
@@ -24,10 +25,31 @@ it('create and edit subthought', async () => {
2425
expect(thought.text()).toBe('')
2526
const keyboardResponder = wrapper.find('div#keyboard')
2627
await thought.simulate('change', { target: { value: 'c' } })
27-
await keyboardResponder.simulate('keydown', { key: 'Enter' })
28+
await keyboardResponder.simulate('keydown', { key: 'Enter', ctrlKey: true })
2829
// eslint-disable-next-line no-undef
2930
jest.runAllTimers()
3031
await thought.update()
3132
// eslint-disable-next-line no-undef
3233
expect(thought.text()).toBe('c')
34+
// eslint-disable-next-line fp/no-let
35+
let subthoughtsData = getThoughtsRanked(['c'])
36+
// eslint-disable-next-line fp/no-let
37+
let subthoughtData = subthoughtsData[0]
38+
// eslint-disable-next-line no-undef
39+
expect(subthoughtData.value).toBe('')
40+
await wrapper.update()
41+
const subthought = wrapper.find(
42+
'ul.distance-from-cursor-0 li.leaf div.thought-container div.thought div.editable',
43+
)
44+
await subthought.simulate('change', { target: { value: 's' } })
45+
await keyboardResponder.simulate('keydown', { key: 'Enter' })
46+
// eslint-disable-next-line no-undef
47+
jest.runAllTimers()
48+
await subthought.update()
49+
// eslint-disable-next-line no-undef
50+
expect(subthought.text()).toBe('s')
51+
subthoughtsData = getThoughtsRanked(['c'])
52+
subthoughtData = subthoughtsData[0]
53+
// eslint-disable-next-line no-undef
54+
expect(subthoughtData.value).toBe('s')
3355
})

0 commit comments

Comments
 (0)