All files / modal/__tests__ Modal-test.js

100% Statements 35/35
100% Branches 0/0
100% Functions 10/10
100% Lines 35/35
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    1x 1x 1x 1x   1x 1x 1x 1x     1x 1x 1x     1x 1x 1x 1x   1x 1x     1x 1x 1x 1x   1x 1x     1x 1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x      
/* global it, describe */
 
import assert from 'assert'
import React from 'react'
import Modal from '../'
import {mount} from 'enzyme'
 
describe('Modal', () => {
  it('should work', () => {
    const wrapper = mount(<Modal visible />)
    assert.equal(wrapper.find('.Modal').length, 1)
  })
 
  it('should be hidden by default', () => {
    const wrapper = mount(<Modal />)
    assert.equal(wrapper.find('.Modal').length, 0)
  })
 
  it('should callback when clicking on dark background', (done) => {
    const callback = (visible) => {
      assert.equal(visible, false)
      done()
    }
    const wrapper = mount(<Modal visible toggle={callback} />)
    wrapper.find('.Modal-overlay').simulate('click')
  })
 
  it('should callback when touching dark background', (done) => {
    const callback = (visible) => {
      assert.equal(visible, false)
      done()
    }
    const wrapper = mount(<Modal visible toggle={callback} />)
    wrapper.find('.Modal-overlay').simulate('touchend')
  })
 
  it('should have a custom header', () => {
    const header = <p>my custom header</p>
    const wrapper = mount(<Modal visible header={header} />)
    assert.equal(wrapper.find('.Modal-header').text(), 'my custom header')
  })
 
  it('should have a custom body', () => {
    const body = <p>my custom body</p>
    const wrapper = mount(<Modal visible body={body} />)
    assert.equal(wrapper.find('.Modal-body').text(), 'my custom body')
  })
 
  it('should have a custom footer', () => {
    const footer = <p>my custom footer</p>
    const wrapper = mount(<Modal visible footer={footer} />)
    assert.equal(wrapper.find('.Modal-footer').text(), 'my custom footer')
  })
})