@@ -10,13 +10,11 @@ import modelingModule from 'src/features/modeling';
10
10
11
11
import { createKeyEvent } from 'diagram-js/test/util/KeyEvents' ;
12
12
13
- import {
14
- KEYS_REDO ,
15
- KEYS_UNDO
16
- } from 'diagram-js/lib/features/keyboard/KeyboardBindings' ;
17
-
18
13
import schema from '../../form.json' ;
19
14
15
+ var KEYS_REDO = [ 'y' , 'Y' , 89 ] ;
16
+ var KEYS_UNDO = [ 'z' , 'Z' , 90 ] ;
17
+
20
18
21
19
describe ( 'features/editor-actions' , function ( ) {
22
20
@@ -32,22 +30,27 @@ describe('features/editor-actions', function() {
32
30
getFormEditor ( ) . destroy ( ) ;
33
31
} ) ;
34
32
33
+ function triggerEvent ( key , attrs , target ) {
34
+ return getFormEditor ( ) . invoke ( function ( config ) {
35
+ target = target || config . renderer . container ;
36
+
37
+ return target . dispatchEvent ( createKeyEvent ( key , attrs ) ) ;
38
+ } ) ;
39
+ }
35
40
36
41
KEYS_UNDO . forEach ( ( key ) => {
37
42
38
- it ( 'should undo' , inject ( function ( keyboard , editorActions ) {
43
+ it ( 'should undo' , inject ( function ( config , keyboard , editorActions ) {
39
44
40
45
// given
41
46
const undoSpy = sinon . spy ( editorActions , 'trigger' ) ;
42
47
43
- const event = createKeyEvent ( key , {
48
+ // when
49
+ triggerEvent ( key , {
44
50
ctrlKey : true ,
45
51
shiftKey : false
46
52
} ) ;
47
53
48
- // when
49
- keyboard . _keyHandler ( event ) ;
50
-
51
54
// then
52
55
expect ( undoSpy ) . to . have . been . calledWith ( 'undo' ) ;
53
56
} ) ) ;
@@ -62,45 +65,45 @@ describe('features/editor-actions', function() {
62
65
// given
63
66
const redoSpy = sinon . spy ( editorActions , 'trigger' ) ;
64
67
65
- const event = createKeyEvent ( key , {
68
+ // when
69
+ triggerEvent ( key , {
66
70
ctrlKey : true ,
67
71
shiftKey : false
68
72
} ) ;
69
73
70
- // when
71
- keyboard . _keyHandler ( event ) ;
72
-
73
74
// then
74
75
expect ( redoSpy ) . to . have . been . calledWith ( 'redo' ) ;
75
76
} ) ) ;
76
77
77
78
} ) ;
78
79
79
80
80
- it ( 'should undo/redo when focused on input' , inject ( function ( formEditor , keyboard , editorActions ) {
81
+ it ( 'should undo/redo when focused on input' , inject (
82
+ function ( formEditor , keyboard , editorActions ) {
81
83
82
- // given
83
- const spy = sinon . spy ( editorActions , 'trigger' ) ;
84
+ // given
85
+ const spy = sinon . spy ( editorActions , 'trigger' ) ;
84
86
85
- const container = formEditor . _container ;
86
- const inputField = document . createElement ( 'input' ) ;
87
+ const container = formEditor . _container ;
88
+ const inputEl = document . createElement ( 'input' ) ;
87
89
88
- container . appendChild ( inputField ) ;
90
+ container . appendChild ( inputEl ) ;
89
91
90
- // when
91
- // select all
92
- keyboard . _keyHandler ( { key : 'a' , ctrlKey : true , target : inputField } ) ;
92
+ // when
93
+ // select all
94
+ triggerEvent ( 'a' , { ctrlKey : true } , inputEl ) ;
93
95
94
- // then
95
- expect ( spy ) . to . not . have . been . called ;
96
+ // then
97
+ expect ( spy ) . to . not . have . been . called ;
96
98
97
- // when
98
- // undo/redo
99
- keyboard . _keyHandler ( { key : 'z' , ctrlKey : true , target : inputField , preventDefault : ( ) => { } } ) ;
100
- keyboard . _keyHandler ( { key : 'y' , ctrlKey : true , target : inputField , preventDefault : ( ) => { } } ) ;
99
+ // when
100
+ // undo/redo
101
+ triggerEvent ( 'z' , { ctrlKey : true } , inputEl ) ;
102
+ triggerEvent ( 'y' , { ctrlKey : true } , inputEl ) ;
101
103
102
- // then
103
- expect ( spy ) . to . have . been . called . calledTwice ;
104
- } ) ) ;
104
+ // then
105
+ expect ( spy ) . to . have . been . called . calledTwice ;
106
+ }
107
+ ) ) ;
105
108
106
109
} ) ;
0 commit comments