aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/app/dropdowns/tests/menu.test.js
blob: 9f5f13f00a8bd0891f79bed83dcd5730c4c68886 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React from 'react'
import assert from 'assert'
import sinon from 'sinon'
import { shallow } from 'enzyme'
import { Menu, Item, Divider, CloseArea } from '../components/menu'

describe('Dropdown Menu Components', () => {

  describe('Menu', () => {
    let wrapper

    beforeEach(() => {
      wrapper = shallow(
        <Menu className = {'Test Class'} isShowing = {true}/>
      )
    })

    it('adds prop className to menu', () => {
      assert.equal(wrapper.find('.menu').prop('className'), 'menu Test Class')
    })

  })

  describe('Item', () => {
    let wrapper

    const onClickSpy = sinon.spy()

    beforeEach(() => {
      wrapper = shallow(
        <Item
          icon = {'test icon'}
          text = {'test text'}
          className = {'test className'}
          onClick = {onClickSpy}
        />
      )
    })

    it('add className based on props', () => {
      assert.equal(wrapper.find('.menu__item').prop('className'), 'menu__item menu__item test className menu__item--clickable')
    })

    it('simulates onClick called', () => {
      wrapper.find('.menu__item').prop('onClick')()
      assert.equal(onClickSpy.callCount, 1)
    })

    it('adds icon based on icon props', () => {
      assert.equal(wrapper.find('.menu__item__icon').text(), 'test icon')
    })

    it('adds html text based on text props', () => {
      assert.equal(wrapper.find('.menu__item__text').text(), 'test text')
    })
  })

  describe('Divider', () => {
    let wrapper

    before(() => {
      wrapper = shallow(<Divider />)
    })

    it('renders menu divider', () => {
      assert.equal(wrapper.find('.menu__divider').length, 1)
    })
  })

  describe('CloseArea', () => {
    let wrapper

    const onClickSpy = sinon.spy()

    beforeEach(() => {
      wrapper = shallow(<CloseArea
        onClick = {onClickSpy}
      />)
    })

    it('simulates click', () => {
      wrapper.prop('onClick')()
      assert.equal(onClickSpy.callCount, 1)
    })
  })

})