aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/components/FlowTableSpec.js
blob: 4d8de12cafc145e192ecfe4fe2dd0cf05565dc48 (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
import React from 'react'
import renderer from 'react-test-renderer'
import FlowTable from '../../components/FlowTable'
import TestUtils from 'react-dom/test-utils'
import { TFlow, TStore } from '../ducks/tutils'
import { Provider } from 'react-redux'

window.addEventListener = jest.fn()

describe('FlowTable Component', () => {
    let selectFn = jest.fn(),
        tflow = TFlow(),
        store = TStore()

    it('should render correctly', () => {
        let provider = renderer.create(
                <Provider store={store}>
                    <FlowTable onSelect={selectFn} flows={[tflow]}/>
                </Provider>),
            tree = provider.toJSON()
        expect(tree).toMatchSnapshot()
    })

    let provider = TestUtils.renderIntoDocument(
        <Provider store={store} >
            <FlowTable onSelect={selectFn} flows={[tflow]}/>
        </Provider>),
        flowTable = TestUtils.findRenderedComponentWithType(provider, FlowTable)

    it('should handle componentWillUnmount', () => {
        flowTable.componentWillUnmount()
        expect(window.addEventListener).toBeCalledWith('resize', flowTable.onViewportUpdate)
    })

    it('should handle componentDidUpdate', () => {
        // flowTable.shouldScrollIntoView == false
        expect(flowTable.componentDidUpdate()).toEqual(undefined)
        // rowTop - headHeight < viewportTop
        flowTable.shouldScrollIntoView = true
        flowTable.componentDidUpdate()
        // rowBottom > viewportTop + viewportHeight
        flowTable.shouldScrollIntoView = true
        flowTable.componentDidUpdate()
    })

    it('should handle componentWillReceiveProps', () => {
        flowTable.componentWillReceiveProps({selected: tflow})
        expect(flowTable.shouldScrollIntoView).toBeTruthy()
    })
})