UNPKG

principles-ui-components

Version:

Supporting UI controller for Tizen TV web application, which developed base on React Framework.

68 lines (49 loc) 2.79 kB
import React from 'react'; import {shallow, mount} from 'enzyme'; import PressFeedback from '../UI_Component/common/PressFeedback'; describe('<PressFeedback />', () => { it('normal case, set PressFeedback initial, than start animaiton', () => { const feedbackWrapper = mount(<PressFeedback start={false}/>); expect(feedbackWrapper.props().start).toEqual(false); const feedbackInst = feedbackWrapper.instance(); expect(feedbackInst).toBeInstanceOf(PressFeedback); const animationDoneCB = jest.fn(); feedbackWrapper.setProps({start: true, animationDoneCB:animationDoneCB}); expect(feedbackWrapper.state().styleIndex).toBe(1); const e ={target: 'div', currentTarget: 'div', type: 'animationend', preventDefault: jest.fn()}; feedbackInst.animationDone(e); expect(animationDoneCB).toHaveBeenCalled(); feedbackWrapper.setProps({start: true, animationDoneCB:animationDoneCB}); expect(feedbackWrapper.state().styleIndex).toBe(2); feedbackInst.animationDone(e); expect(animationDoneCB).toHaveBeenCalled(); feedbackWrapper.setProps({start: true, animationDoneCB:animationDoneCB}); expect(feedbackWrapper.state().styleIndex).toBe(1); feedbackInst.animationDone(e); expect(animationDoneCB).toHaveBeenCalled(); feedbackWrapper.unmount(); }); it(' reset PressFeedback animaiton', () => { const feedbackWrapper = mount(<PressFeedback start={true}/>); feedbackWrapper.setProps({start: false,}); feedbackWrapper.unmount(); }); it('abnormal case, do not start PressFeedback animaiton', () => { const feedbackWrapper = mount(<PressFeedback start={false} animationDoneCB={undefined}/>); // start point failed feedbackWrapper.setState({styleIndex : -1}); feedbackWrapper.setProps({start: true}); const feedbackInst = feedbackWrapper.instance(); expect(feedbackInst).toBeInstanceOf(PressFeedback); // animation capture phase, do not start const e2 ={target: 'div', currentTarget: 'div-child', type: 'animationend', preventDefault: jest.fn()}; feedbackInst.animationDone(e2); // animation name is not "animationend", do not start const e3 ={target: 'div', currentTarget: 'div', type: 'animationend2', preventDefault: jest.fn()}; feedbackInst.animationDone(e3); // callback function undefined const e ={target: 'div', currentTarget: 'div', type: 'animationend', preventDefault: jest.fn()}; feedbackInst.animationDone(e); feedbackWrapper.unmount(); }); });