aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/components/common/DropdownSpec.js
blob: c8c57ea6dbcec2fc63a624fe2f72105c1bec0f77 (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
import React from 'react'
import renderer from 'react-test-renderer'
import Dropdown, { Divider } from '../../../components/common/Dropdown'

describe('Dropdown Component', () => {
    let dropup = renderer.create(<Dropdown dropup btnClass="foo">
            <a href="#">1</a>
            <Divider/>
            <a href="#">2</a>
        </Dropdown>),
        dropdown = renderer.create(<Dropdown btnClass="foo">
            <a href="#">1</a>
            <a href="#">2</a>
        </Dropdown>)

    it('should render correctly', () => {
        let tree = dropup.toJSON()
        expect(tree).toMatchSnapshot()

        tree = dropdown.toJSON()
        expect(tree).toMatchSnapshot()
    })

    it('should handle open/close action', () => {
        document.body.addEventListener('click', ()=>{})
        let tree = dropup.toJSON(),
            e = { preventDefault: jest.fn() }
        tree.children[0].props.onClick(e)
        expect(tree).toMatchSnapshot()

        // click action when the state is open
        tree.children[0].props.onClick(e)

        // close
        document.body.click()
        expect(tree).toMatchSnapshot()
    })
})