|
| 1 | +import expect from 'expect'; |
| 2 | +import React from 'react'; |
| 3 | +import ReactDOM from 'react-dom'; |
| 4 | +import ReactTestUtils from 'react-addons-test-utils'; |
| 5 | +import { themr } from 'react-css-themr'; |
| 6 | +import { CHIP } from '../../identifiers.js'; |
| 7 | +import { chipFactory } from '../Chip'; |
| 8 | +import { tooltipFactory } from '../../tooltip'; |
| 9 | + |
| 10 | +const Avatar = ({title}) => <span>{title}</span>; // eslint-disable-line react/prop-types |
| 11 | +const Chip = themr(CHIP)(chipFactory(Avatar)); |
| 12 | + |
| 13 | +describe('Chip', function () { |
| 14 | + describe('with avatar', function () { |
| 15 | + it('adds the avatar class to the element', function () { |
| 16 | + const tree = ReactTestUtils.renderIntoDocument( |
| 17 | + <Chip theme={{avatar: 'avatar-class'}}> |
| 18 | + <Avatar title='Test'/> |
| 19 | + <span>Test</span> |
| 20 | + </Chip> |
| 21 | + ); |
| 22 | + const chip = ReactTestUtils.findRenderedComponentWithType(tree, Chip); |
| 23 | + const chipNode = ReactDOM.findDOMNode(chip); |
| 24 | + expect(chipNode.className).toMatch(/\bavatar-class\b/); |
| 25 | + }); |
| 26 | + |
| 27 | + it('works with non-flat children', function () { |
| 28 | + const TooltippedChip = tooltipFactory()(Chip); |
| 29 | + const tree = ReactTestUtils.renderIntoDocument( |
| 30 | + <TooltippedChip theme={{avatar: 'avatar-class'}} tooltip='Test tooltip'> |
| 31 | + <Avatar title='Test'/> |
| 32 | + <span>Test</span> |
| 33 | + </TooltippedChip> |
| 34 | + ); |
| 35 | + const chip = ReactTestUtils.findRenderedComponentWithType(tree, Chip); |
| 36 | + const chipNode = ReactDOM.findDOMNode(chip); |
| 37 | + expect(chipNode.className).toMatch(/\bavatar-class\b/); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('without avatar', function () { |
| 42 | + it('does not add avatar class to the element', function () { |
| 43 | + const tree = ReactTestUtils.renderIntoDocument( |
| 44 | + <Chip theme={{avatar: 'avatar-class'}}> |
| 45 | + <span>Test</span> |
| 46 | + </Chip> |
| 47 | + ); |
| 48 | + const chip = ReactTestUtils.findRenderedComponentWithType(tree, Chip); |
| 49 | + const chipNode = ReactDOM.findDOMNode(chip); |
| 50 | + expect(chipNode.className).toNotMatch(/\bavatar-class\b/); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments