Skip to content

Commit a38e2e6

Browse files
committed
unit onchange
1 parent 39850c5 commit a38e2e6

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import { ActionName } from '@sensenet/control-mapper'
2-
import { mount, ReactWrapper } from 'enzyme'
2+
import { mount } from 'enzyme'
33
import React from 'react'
44
import { act } from 'react-dom/test-utils'
55
import { defaultLocalization, HtmlEditor } from '../src/fieldcontrols'
66

77
jest.mock('react-monaco-editor', () =>
88
jest.fn((props) => {
9-
return <div data-test="mock-monaco-editor">{props.value}</div>
9+
return (
10+
<div data-test="mock-monaco-editor" onChange={props.onChange}>
11+
{props.value}
12+
</div>
13+
)
1014
}),
1115
)
1216

1317
describe('Html Editor', () => {
1418
it('should display the content', async () => {
19+
const onChange = jest.fn()
1520
const props = {
1621
actionName: 'edit' as ActionName,
1722
settings: {
@@ -26,18 +31,24 @@ describe('Html Editor', () => {
2631
},
2732
localization: defaultLocalization,
2833
fieldValue: '<p>Test</p>',
29-
fieldOnChange: jest.fn(),
34+
35+
onChange,
3036
}
3137

32-
let wrapper: ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>
38+
const wrapper = mount(<HtmlEditor {...props} />)
3339

34-
await act(async () => {
35-
wrapper = mount(<HtmlEditor {...props} />)
36-
})
37-
wrapper!.update()
40+
wrapper.update()
3841

3942
const htmlEditorContainer = wrapper!.find('[data-test="html-editor-container"]')
4043

4144
expect(htmlEditorContainer.text()).toBe('<p>Test</p>')
45+
46+
const mockMonacoEditor = wrapper.find('[data-test="mock-monaco-editor"]')
47+
48+
await act(async () => {
49+
mockMonacoEditor.prop('onChange')?.('<p>Changed Test</p>' as any)
50+
})
51+
52+
expect(htmlEditorContainer.text()).toBe('<p>Changed Test</p>')
4253
})
4354
})

0 commit comments

Comments
 (0)