aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/components/Header/FileMenuSpec.js
blob: 0d87530b943b4180e099c67c451ad3b13c2a9997 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React from 'react'
import renderer from 'react-test-renderer'
import { FileMenu } from '../../../components/Header/FileMenu'

global.confirm = jest.fn( s => true )

describe('FileMenu Component', () => {
    let clearFn = jest.fn(),
        loadFn = jest.fn(),
        saveFn = jest.fn(),
        openModalFn = jest.fn(),
        mockEvent = {
            preventDefault: jest.fn(),
            target: { files: ["foo", "bar "] }
        },
        createNodeMock = () => { return { click: jest.fn() }},
        fileMenu = renderer.create(
            <FileMenu
                clearFlows={clearFn}
                loadFlows={loadFn}
                saveFlows={saveFn}
                openModal={openModalFn}
            />,
            { createNodeMock }),
        tree = fileMenu.toJSON()

    it('should render correctly', () => {
        expect(tree).toMatchSnapshot()
    })

    let ul = tree.children[1]

    it('should clear flows', () => {
        let a = ul.children[0].children[1]
        a.props.onClick(mockEvent)
        expect(mockEvent.preventDefault).toBeCalled()
        expect(clearFn).toBeCalled()
    })

    it('should load flows', () => {
        let fileChooser = ul.children[1].children[1],
            input = fileChooser.children[2]
        input.props.onChange(mockEvent)
        expect(loadFn).toBeCalledWith("foo")
    })

    it('should save flows', () => {
        let a = ul.children[2].children[1]
        a.props.onClick(mockEvent)
        expect(saveFn).toBeCalled()
    })

    it('should open optionModal', () => {
        let a = ul.children[3].children[1]
        a.props.onClick(mockEvent)
        expect(openModalFn).toBeCalled()
    })
})