@@ -7,7 +7,7 @@ import {Editable} from '../src/core.js'
77import Selection from '../src/selection.js'
88const { key} = Keyboard
99
10- describe ( 'Dispatcher' , function ( ) {
10+ describe ( 'Dispatcher: ' , function ( ) {
1111 let editable , elem
1212
1313 // create a Cursor object and set the selection to it
@@ -55,7 +55,7 @@ describe('Dispatcher', function () {
5555 return obj
5656 }
5757
58- describe ( 'for editable' , function ( ) {
58+ describe ( 'for editable: ' , function ( ) {
5959
6060 beforeEach ( function ( ) {
6161 elem = document . createElement ( 'div' )
@@ -71,7 +71,7 @@ describe('Dispatcher', function () {
7171 editable . unload ( )
7272 } )
7373
74- describe ( 'on focus' , function ( ) {
74+ describe ( 'on focus: ' , function ( ) {
7575 it ( 'should trigger the focus event' , function ( ) {
7676 elem . blur ( )
7777 const focus = on ( 'focus' , function ( element ) {
@@ -103,7 +103,7 @@ describe('Dispatcher', function () {
103103 } )
104104 } )
105105
106- describe ( 'on enter' , function ( ) {
106+ describe ( 'on enter: ' , function ( ) {
107107
108108 it ( 'fires insert "after" if cursor is at the end' , function ( ) {
109109 // <div>foo\</div>
@@ -162,7 +162,7 @@ describe('Dispatcher', function () {
162162 } )
163163 } )
164164
165- describe ( 'on backspace' , function ( ) {
165+ describe ( 'on backspace: ' , function ( ) {
166166
167167 it ( 'fires "merge" if cursor is at the beginning' , function ( done ) {
168168 elem . innerHTML = 'foo'
@@ -175,21 +175,9 @@ describe('Dispatcher', function () {
175175
176176 elem . dispatchEvent ( new KeyboardEvent ( 'keydown' , { keyCode : key . backspace } ) )
177177 } )
178-
179- it ( 'fires "change" if cursor is not at the beginning' , ( done ) => {
180- elem . innerHTML = 'foo'
181- createCursor ( createRangeAtEnd ( elem ) )
182-
183- on ( 'change' , ( element ) => {
184- expect ( element ) . to . equal ( elem )
185- done ( )
186- } )
187-
188- elem . dispatchEvent ( new KeyboardEvent ( 'keydown' , { keyCode : key . backspace } ) )
189- } )
190178 } )
191179
192- describe ( 'on delete' , function ( ) {
180+ describe ( 'on delete: ' , function ( ) {
193181
194182 it ( 'fires "merge" if cursor is at the end' , ( done ) => {
195183 elem . innerHTML = 'foo'
@@ -202,25 +190,9 @@ describe('Dispatcher', function () {
202190
203191 elem . dispatchEvent ( new KeyboardEvent ( 'keydown' , { keyCode : key . delete } ) )
204192 } )
205-
206- it ( 'fires "change" if cursor is at the beginning' , ( done ) => {
207- elem . innerHTML = 'foo'
208- createCursor ( createRangeAtBeginning ( elem ) )
209- on ( 'change' , ( ) => done ( ) )
210- elem . dispatchEvent ( new KeyboardEvent ( 'keydown' , { keyCode : key . delete } ) )
211- } )
212193 } )
213194
214- describe ( 'on keydown' , function ( ) {
215-
216- it ( 'fires change when a character is pressed' , ( done ) => {
217- const evt = new KeyboardEvent ( 'keydown' , { keyCode : 'e' . charCodeAt ( 0 ) } )
218- on ( 'change' , ( ) => done ( ) )
219- elem . dispatchEvent ( evt )
220- } )
221- } )
222-
223- describe ( 'on newline' , function ( ) {
195+ describe ( 'on newline:' , function ( ) {
224196
225197 function typeKeys ( element , chars ) {
226198 const selection = window . getSelection ( )
@@ -245,25 +217,28 @@ describe('Dispatcher', function () {
245217 expect ( elem . innerHTML ) . to . equal ( '<br>\uFEFF' )
246218 } )
247219
248- it ( 'appends a zero-width space after the br tag to force a line break' , ( ) => {
220+ it ( 'appends a zero-width space after the br tag to force a line break' , async ( ) => {
249221 typeKeys ( elem , 'foobar' )
250222 shiftReturn ( elem )
223+ elem . addEventListener ( 'input' , function ( e ) { console . log ( 'input event' , e ) } )
224+ await 1
251225 expect ( elem . innerHTML ) . to . equal (
252226 `\uFEFFfoobar<br>\uFEFF`
253227 )
254228 } )
255229
256- it ( 'does not append another zero-width space when one is present already' , ( ) => {
230+ it ( 'does not append another zero-width space when one is present already' , async ( ) => {
257231 typeKeys ( elem , 'foobar' )
258232 shiftReturn ( elem )
259233 shiftReturn ( elem )
234+ await 1
260235 expect ( elem . innerHTML ) . to . equal (
261236 `\uFEFFfoobar<br><br>\uFEFF`
262237 )
263238 } )
264239 } )
265240
266- describe ( 'on bold' , function ( ) {
241+ describe ( 'on bold: ' , function ( ) {
267242
268243 it ( 'fires toggleBold when ctrl + b is pressed' , ( done ) => {
269244 elem . innerHTML = 'foo'
@@ -280,7 +255,7 @@ describe('Dispatcher', function () {
280255 } )
281256 } )
282257
283- describe ( 'on italic' , function ( ) {
258+ describe ( 'on italic: ' , function ( ) {
284259
285260 it ( 'fires toggleEmphasis when ctrl + i is pressed' , ( done ) => {
286261 elem . innerHTML = 'foo'
@@ -297,7 +272,7 @@ describe('Dispatcher', function () {
297272 } )
298273 } )
299274
300- describe ( 'selectToBoundary event:' , function ( ) {
275+ describe ( 'selectToBoundary event:: ' , function ( ) {
301276
302277 it ( 'fires "both" if all is selected' , function ( ) {
303278 elem . innerHTML = 'People Make The World Go Round'
@@ -353,7 +328,7 @@ describe('Dispatcher', function () {
353328 } )
354329 } )
355330
356- describe ( 'on paste' , function ( ) {
331+ describe ( 'on paste: ' , function ( ) {
357332
358333 it ( 'inserts plain text clipboard content' , ( done ) => {
359334 on ( 'paste' , ( block , blocks ) => {
@@ -408,5 +383,19 @@ describe('Dispatcher', function () {
408383 elem . dispatchEvent ( evt )
409384 } )
410385 } )
386+
387+ describe ( 'input event:' , function ( ) {
388+ it ( 'fires "change" event' , ( done ) => {
389+ elem . innerHTML = 'foo'
390+ createCursor ( createRangeAtEnd ( elem ) )
391+
392+ on ( 'change' , ( element ) => {
393+ expect ( element ) . to . equal ( elem )
394+ done ( )
395+ } )
396+
397+ elem . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) )
398+ } )
399+ } )
411400 } )
412401} )
0 commit comments