UNPKG

principles-ui-components

Version:

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

90 lines (59 loc) 3.24 kB
import React from 'react'; import {shallow, mount} from 'enzyme'; import DropdownButton, { DROPDOWN_TYPE, ARROW_TYPE } from '../UI_Component/DropdownButton'; describe('<DropdownButton />', () => { it('DropdownButton unit test, Set button focus', () => { const btnWrapper = mount(<DropdownButton text={'text button'} buttonType={DROPDOWN_TYPE.TEXT} arrowType={ARROW_TYPE.UP}/>); expect(btnWrapper.props().text).toEqual('text button'); const btnInst = btnWrapper.instance(); expect(btnInst).toBeInstanceOf(DropdownButton); btnInst.SetFocus(true); btnInst.SetFocus(true); btnInst.SetFocus(false); btnInst.DisableButton(true); btnInst.SetFocus(true); btnInst.DisableButton(false); btnInst.DisableButton(false); btnWrapper.unmount(); }); it('DropdownButton unit test, Select button focus', () => { const btnWrapper = mount(<DropdownButton text={'text button'} buttonType={DROPDOWN_TYPE.TEXT} arrowType={ARROW_TYPE.DOWN}/>); expect(btnWrapper.props().text).toEqual('text button'); btnWrapper.setProps({selectCB: jest.fn(), unselectCB: jest.fn()}); const btnInst = btnWrapper.instance(); expect(btnInst).toBeInstanceOf(DropdownButton); btnInst.SetFocus(true); btnInst.SelectButton(true); btnInst.SelectButton(true); const e ={target: 'div', currentTarget: 'div', type: 'animationend', animationName: 'SelectedIn', preventDefault: jest.fn()}; btnInst.animationDone(e); expect(btnWrapper.props().selectCB).toHaveBeenCalled(); const e2 ={target: 'div', currentTarget: 'div', type: 'animationend', animationName: 'SelectedOut', preventDefault: jest.fn()}; btnInst.animationDone(e2); expect(btnWrapper.props().unselectCB).toHaveBeenCalled(); btnInst.SelectButton(false); btnWrapper.setProps({arrowType: ARROW_TYPE.UP}); btnInst.SelectButton(true); btnInst.DisableButton(true); btnInst.SelectButton(true); btnWrapper.unmount(); }); it('icon basicbutton test, acc test', () => { const iconOSD = {l: 22, t: 23, w: 38, h: 38, url_n: '' }; const btnWrapper = mount(<DropdownButton buttonType={DROPDOWN_TYPE.ICON} iconOSD={iconOSD} arrowType={ARROW_TYPE.DOWN}/>); const btnInst = btnWrapper.instance(); expect(btnInst).toBeInstanceOf(DropdownButton); btnInst.SetFocus(true); const iconOSD2 = {l: 22, t: 23, w: 38, h: 38, url_n: '', url_f: '',}; btnWrapper.setProps({iconOSD: iconOSD2, highContrast: true, ttsEnable: true}); btnInst.playTTS(); btnInst.SetFocus(false); btnWrapper.unmount(); }); it('Text basicbutton test, custom buttonScale, and enlarge ', () => { const btnWrapper = mount(<DropdownButton text={'text button'} buttonType={DROPDOWN_TYPE.TEXT} arrowType={ARROW_TYPE.DOWN}/>); const buttonScale = 1.2; btnWrapper.setProps({ buttonScale: buttonScale, enlarge: true }); btnWrapper.unmount(); }); });