Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4128191
ve.EventSequencer.test.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ve.EventSequencer.test.js
View Options
/*!
* VisualEditor EventSequencer tests.
*
* @copyright See AUTHORS.txt
*/
QUnit
.
module
(
've.EventSequencer'
);
/* Stubs */
// EventSequencer with script-controlled implementation of "postpone"
ve
.
TestEventSequencer
=
function
VeTestEventSequencer
()
{
// Parent constructor
ve
.
TestEventSequencer
.
super
.
apply
(
this
,
arguments
);
// { number: callback } (for faking setTimeout/clearTimeout)
this
.
postponedCallbacks
=
{};
this
.
postponedCallbackId
=
1
;
};
OO
.
inheritClass
(
ve
.
TestEventSequencer
,
ve
.
EventSequencer
);
ve
.
TestEventSequencer
.
prototype
.
postpone
=
function
(
callback
)
{
this
.
postponedCallbacks
[
this
.
postponedCallbackId
++
]
=
callback
;
};
ve
.
TestEventSequencer
.
prototype
.
cancelPostponed
=
function
(
timeoutId
)
{
delete
this
.
postponedCallbacks
[
timeoutId
];
};
ve
.
TestEventSequencer
.
prototype
.
runPostponed
=
function
()
{
function
sortStringIds
(
a
,
b
)
{
return
parseInt
(
a
)
-
parseInt
(
b
);
}
let
ids
;
while
(
(
ids
=
Object
.
keys
(
this
.
postponedCallbacks
)
).
length
>
0
)
{
ids
.
sort
(
sortStringIds
);
for
(
let
i
=
0
,
len
=
ids
.
length
;
i
<
len
;
i
++
)
{
const
callback
=
this
.
postponedCallbacks
[
ids
[
i
]
];
delete
this
.
postponedCallbacks
[
ids
[
i
]
];
// Check for existence, because a previous iteration may have cancelled
if
(
callback
)
{
callback
();
}
}
}
};
/* Tests */
QUnit
.
test
(
'EventSequencer'
,
(
assert
)
=>
{
const
calls
=
[];
let
sequencer
=
new
ve
.
TestEventSequencer
(
[
'event1'
,
'event2'
,
'event3'
]
).
on
(
{
event1
:
()
=>
{
calls
.
push
(
'on1'
);
},
event3
:
()
=>
{
calls
.
push
(
'on3'
);
}
}
).
after
(
{
event2
:
()
=>
{
calls
.
push
(
'after2'
);
},
event3
:
()
=>
{
calls
.
push
(
'after3'
);
}
}
).
onLoop
(
()
=>
{
calls
.
push
(
'onLoop'
);
}
).
afterLoop
(
()
=>
{
calls
.
push
(
'afterLoop'
);
}
).
afterOne
(
{
event1
:
()
=>
{
calls
.
push
(
'after1One'
);
}
}
);
sequencer
.
onEvent
(
'event1'
);
sequencer
.
onEvent
(
'event2'
);
sequencer
.
onEvent
(
'event3'
);
sequencer
.
runPostponed
();
assert
.
deepEqual
(
calls
,
[
'onLoop'
,
'on1'
,
'after1One'
,
'after2'
,
'on3'
,
'after3'
,
'afterLoop'
],
'First event loop'
);
calls
.
length
=
0
;
sequencer
.
afterLoopOne
(
()
=>
{
calls
.
push
(
'afterLoopOne'
);
}
);
sequencer
.
onEvent
(
'event1'
);
sequencer
.
onEvent
(
'event2'
);
sequencer
.
onEvent
(
'event3'
);
sequencer
.
runPostponed
();
assert
.
deepEqual
(
calls
,
[
'onLoop'
,
'on1'
,
'after2'
,
'on3'
,
'after3'
,
'afterLoop'
,
'afterLoopOne'
],
'Second event loop'
);
calls
.
length
=
0
;
sequencer
=
new
ve
.
TestEventSequencer
(
[
'keydown'
,
'keypress'
]
).
on
(
{
keydown
:
()
=>
{
calls
.
push
(
'onkeydown'
);
},
keypress
:
()
=>
{
calls
.
push
(
'onkeypress'
);
}
}
).
after
(
{
keydown
:
()
=>
{
calls
.
push
(
'afterkeydown'
);
},
keypress
:
()
=>
{
calls
.
push
(
'afterkeypress'
);
}
}
);
sequencer
.
onEvent
(
'keydown'
);
sequencer
.
onEvent
(
'keypress'
);
sequencer
.
runPostponed
();
assert
.
deepEqual
(
calls
,
[
'onkeydown'
,
'onkeypress'
,
'afterkeydown'
,
'afterkeypress'
],
'Keydown/keypress special-cased ordering'
);
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 19, 09:07 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
87/99/41f520305da4ca94e0292a97aa24
Default Alt Text
ve.EventSequencer.test.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment