principles-ui-components
Version:
Supporting UI controller for Tizen TV web application, which developed base on React Framework.
42 lines (29 loc) • 1.5 kB
JavaScript
import React from 'react';
import {shallow, mount} from 'enzyme';
import ScrollText from '../UI_Component/common/ScrollText';
import CommonAPI from '../UI_Component/common/CommonAPI';
describe('<ScrollText />', () => {
it('ScrollText unit test, start scroll case', () => {
const getTextWidth = jest.fn(()=>{return 100;});
CommonAPI.getTextWidth = getTextWidth;
const textWrapper = mount(<ScrollText width={80} height={40} scroll={true}>{'ScrollText message'}</ScrollText>);
expect(textWrapper.props().children).toEqual('ScrollText message');
const textInst = textWrapper.instance();
expect(textInst).toBeInstanceOf(ScrollText);
const e ={target: 'div', currentTarget: 'div', type: 'animationend', preventDefault: jest.fn()};
textInst.animationDone(e);
textInst.animationDone(e);
textWrapper.setProps({scroll: false});
textWrapper.unmount();
});
it('ScrollText unit test, reset props, start scroll case', () => {
const getTextWidth = jest.fn(()=>{return 100;});
CommonAPI.getTextWidth = getTextWidth;
const textWrapper = mount(<ScrollText width={120} height={40} scroll={false}>{'ScrollText'}</ScrollText>);
expect(textWrapper.props().width).toBe(120);
const getTextWidth2 = jest.fn(()=>{return 200;});
CommonAPI.getTextWidth = getTextWidth2;
textWrapper.setProps({scroll: true, children: 'ScrollText message'});
textWrapper.unmount();
});
});