|
| 1 | +import assert from 'power-assert'; |
| 2 | +import React from 'react'; |
| 3 | +import ReactDOM from 'react-dom'; |
| 4 | +import TestUtils from 'react-addons-test-utils'; |
| 5 | +import { Provider } from 'react-redux'; |
| 6 | +import { Tooltip, Origin, utils } from '../../src/index'; |
| 7 | +import App from '../../examples/style/app'; |
| 8 | +import store from '../../examples/common/store'; |
| 9 | +import { firstComponent, getStyleValue, getComputedStyleValue } from '../helpers'; |
| 10 | + |
| 11 | +const { position } = utils; |
| 12 | + |
| 13 | +describe('Style Example', () => { |
| 14 | + before(() => { |
| 15 | + document.body.innerHTML += '<div id="container" style="position:absolute;top:0;left:0;"></div>'; |
| 16 | + document.body.innerHTML += `<style type="text/css">${window.__html__['examples/style.css']}</style>`; |
| 17 | + }); |
| 18 | + |
| 19 | + let tree; |
| 20 | + beforeEach(() => { |
| 21 | + tree = ReactDOM.render( |
| 22 | + <Provider store={store}> |
| 23 | + <App /> |
| 24 | + </Provider>, |
| 25 | + document.getElementById('container')); |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(() => { |
| 29 | + ReactDOM.unmountComponentAtNode(document.getElementById('container')); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('id tooltip', () => { |
| 33 | + it('should be colored', () => { |
| 34 | + const origin = firstComponent(tree, Origin.WrappedComponent, { name: 'id-tip' }).refs.wrapper; |
| 35 | + TestUtils.Simulate.mouseEnter(origin); |
| 36 | + |
| 37 | + const tooltip = firstComponent(tree, Tooltip.WrappedComponent, { name: 'id-tip' }).refs.tooltip; |
| 38 | + assert(getComputedStyleValue(tooltip, 'background-color') === 'rgb(255, 205, 210)'); |
| 39 | + assert(tooltip.innerText === 'This is a id tooltip.'); |
| 40 | + |
| 41 | + const border = firstComponent(tree, Tooltip.WrappedComponent, { name: 'id-tip' }).refs.border; |
| 42 | + assert(getComputedStyleValue(border, 'border-color') === 'rgb(255, 205, 210) rgba(0, 0, 0, 0) rgba(0, 0, 0, 0)'); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('class tooltip', () => { |
| 47 | + it('should be colored', () => { |
| 48 | + const origin = firstComponent(tree, Origin.WrappedComponent, { name: 'class-tip' }).refs.wrapper; |
| 49 | + TestUtils.Simulate.mouseEnter(origin); |
| 50 | + |
| 51 | + const tooltip = firstComponent(tree, Tooltip.WrappedComponent, { name: 'class-tip' }).refs.tooltip; |
| 52 | + assert(getComputedStyleValue(tooltip, 'background-color') === 'rgb(187, 222, 251)'); |
| 53 | + assert(tooltip.innerText === 'This is a class tooltip.'); |
| 54 | + |
| 55 | + const border = firstComponent(tree, Tooltip.WrappedComponent, { name: 'class-tip' }).refs.border; |
| 56 | + assert(getComputedStyleValue(border, 'border-color') === 'rgb(187, 222, 251) rgba(0, 0, 0, 0) rgba(0, 0, 0, 0)'); |
| 57 | + }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments