aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/components/ContentView/CodeEditorSpec.js
blob: ba7acf07f0eb1606f819bc5d242f348a7fc6b792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
jest.mock('react-codemirror')
import React from 'react'
import renderer from 'react-test-renderer'
import CodeEditor from '../../../components/ContentView/CodeEditor'

describe('CodeEditor Component', () => {
    let content = "foo content",
        changeFn = jest.fn(),
        codeEditor = renderer.create(
            <CodeEditor content={content} onChange={changeFn}/>
        ),
        tree = codeEditor.toJSON()
    
    it('should render correctly', () => {
        // This actually does not render properly, but getting a full CodeMirror rendering
        // is cumbersome. This is hopefully good enough.
        // see: https://github.com/mitmproxy/mitmproxy/pull/2365#discussion_r119766850
        expect(tree).toMatchSnapshot()
    })

    it('should handle key down', () => {
        let mockEvent = { stopPropagation: jest.fn() }
        tree.props.onKeyDown(mockEvent)
        expect(mockEvent.stopPropagation).toBeCalled()
    })
})