33 * For licensing, see LICENSE.md.
44 */
55
6- /* globals Event */
6+ /* global Event */
77
88import ListItemView from '../../src/list/listitemview' ;
9+ import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler' ;
910
1011describe ( 'ListItemView' , ( ) => {
1112 let view ;
@@ -24,6 +25,48 @@ describe( 'ListItemView', () => {
2425 it ( 'creates element from template' , ( ) => {
2526 expect ( view . element . classList . contains ( 'ck-list__item' ) ) . to . be . true ;
2627 } ) ;
28+
29+ it ( 'should create #keystrokes instance' , ( ) => {
30+ expect ( view . keystrokes ) . to . be . instanceOf ( KeystrokeHandler ) ;
31+ } ) ;
32+ } ) ;
33+
34+ describe ( 'init()' , ( ) => {
35+ it ( 'starts listening for #keystrokes coming from #element' , ( ) => {
36+ const spy = sinon . spy ( view . keystrokes , 'listenTo' ) ;
37+
38+ view . init ( ) ;
39+ sinon . assert . calledOnce ( spy ) ;
40+ sinon . assert . calledWithExactly ( spy , view . element ) ;
41+ } ) ;
42+
43+ // https://github.com/ckeditor/ckeditor5-ui/issues/153
44+ it ( 'triggers view#execute event when Enter or Space key is pressed' , ( ) => {
45+ const spy = sinon . spy ( ) ;
46+ const evtData = {
47+ keyCode : 10 ,
48+ preventDefault : sinon . spy ( ) ,
49+ stopPropagation : sinon . spy ( )
50+ } ;
51+
52+ view . on ( 'execute' , spy ) ;
53+ view . keystrokes . press ( evtData ) ;
54+
55+ sinon . assert . notCalled ( spy ) ;
56+ sinon . assert . notCalled ( evtData . preventDefault ) ;
57+
58+ evtData . keyCode = 13 ;
59+ view . keystrokes . press ( evtData ) ;
60+
61+ sinon . assert . calledOnce ( spy ) ;
62+ sinon . assert . calledOnce ( evtData . preventDefault ) ;
63+
64+ evtData . keyCode = 32 ;
65+ view . keystrokes . press ( evtData ) ;
66+
67+ sinon . assert . calledTwice ( spy ) ;
68+ sinon . assert . calledTwice ( evtData . preventDefault ) ;
69+ } ) ;
2770 } ) ;
2871
2972 describe ( 'DOM bindings' , ( ) => {
0 commit comments