All files / list/__tests__ List-test.js

100% Statements 44/44
100% Branches 0/0
100% Functions 13/13
100% Lines 44/44
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    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 1x 1x 1x 1x     1x 1x 1x   1x 1x        
/* global describe, it */
 
import assert from 'assert'
import React from 'react'
import { shallow, mount } from 'enzyme'
import { List, Row } from '../'
 
describe('List', () => {
  it('should work', () => {
    const wrapper = shallow(<List />)
    assert.equal(wrapper.find('.List').length, 1)
  })
 
  it('should render the child Rows', () => {
    const wrapper = mount(
      <List>
        <Row primary='A' />
        <Row primary='B' />
      </List>)
    assert.equal(wrapper.find('.List-row').length, 2)
  })
 
  describe('Row', () => {
    it('should render "primary"', () => {
      const wrapper = shallow(<Row primary='ABC' />)
      assert.equal(wrapper.find('.List-row-text-primary').text(), 'ABC')
    })
 
    it('should render "secondary"', () => {
      const wrapper = shallow(<Row primary='ABC' secondary='ppp' />)
      assert.equal(wrapper.find('.List-row-text-secondary').first().text(), 'ppp')
      assert.equal(wrapper.find('.List-row--twoline').length, 1)
    })
 
    it('should render "secondary" and "subheader"', () => {
      const wrapper = shallow(<Row primary='ABC' subheader='asd' secondary='ppp' />)
      assert.equal(wrapper.find('.List-row-text-secondary').first().text(), 'ppp')
      assert.equal(wrapper.find('.List-row-text-subheader').text(), 'asd')
      assert.equal(wrapper.find('.List-row--threeline').length, 1)
    })
 
    it('should render "avatar" with url', () => {
      const wrapper = shallow(<Row primary='ABC' avatar='http://foo.com/image.jpg' />)
      assert.equal(wrapper.find('.List-row-avatar img').prop('src'), 'http://foo.com/image.jpg')
    })
 
    it('should render "avatar" with element', () => {
      const wrapper = shallow(<Row primary='ABC' avatar={<div x='foo' />} />)
      assert.equal(wrapper.find('.List-row-avatar > div').prop('x'), 'foo')
    })
 
    it('should render "icon" left', () => {
      const dummy = <div x='foo' />
      const wrapper = shallow(
        <Row primary='ABC' icon={dummy} />
      )
      assert.equal(wrapper.find('.List-row-icon-left > div').prop('x'), 'foo')
    })
 
    it('should render "avatar" with url and "icon" right', () => {
      const dummy = <div x='foo' />
      const wrapper = shallow(<Row primary='ABC' avatar='http://foo.com/image.jpg' icon={dummy} />)
      assert.equal(wrapper.find('.List-row-avatar img').prop('src'), 'http://foo.com/image.jpg')
      assert.equal(wrapper.find('.List-row-icon-right > div').prop('x'), 'foo')
    })
 
    it('calls onClick', (done) => {
      const onClick = () => {
        done()
      }
      const wrapper = shallow(<Row primary='ABC' onClick={onClick} />)
      wrapper.simulate('click')
    })
  })
})