siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
94 lines (77 loc) • 3.59 kB
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js">/*
Siesta 5.6.1
Copyright(c) 2009-2022 Bryntum AB
https://bryntum.com/contact
https://bryntum.com/products/siesta/license
*/
Class('Siesta.Test.SimulatorExtJS', {
isa : Siesta.Test.Simulator,
has : {
simulateEventsWith : {
is : 'rw',
lazy : function () {
var isIE9 = navigator.userAgent.match(/MSIE 9.0;/)
var Ext = this.global.Ext
// no Ext or Ext3, should use standard "dispatchEvent" method
if (!Ext || !Ext.getVersion) return 'dispatchEvent'
var extVersion = Ext.getVersion('extjs')
// the "Ext.getVersion('extjs')" is just "true" in Ext3? (when testing SA)
var isBelowExt421 = Boolean((extVersion && extVersion.isLessThan && extVersion.isLessThan('4.2.1.883')))
var div = document.createElement('div')
return div.attachEvent && (isIE9 || isBelowExt421) ? 'fireEvent' : 'dispatchEvent'
}
}
},
methods : {
// Overridden to deal with the different event firing mechanisms in Ext JS 3 vs 4
// This code is required because in IE events are simulated using fireEvent instead of dispatchEvent and it seems fireEvent will
// will not update a checkbox 'checked' state properly so we're forcing the toggle to solve this situation.
// This issue is only relevant in IE + Ext.
//
// Test case: 507_form_checkbox.t.js
simulateMouseClick: function (clickInfo, options) {
var me = this
var el = clickInfo.el
var Ext = this.global.Ext
var isExt5 = Ext && Ext.getVersion && Ext.getVersion('extjs') && Ext.getVersion('extjs').major == 5
// Force check toggle for input checkboxes
if (
(this.getSimulateEventsWith() === 'fireEvent' || isExt5)
&&
(el.type === 'checkbox' || el.type === 'radio') && !el.disabled && !el.readOnly
) {
var oldState = el.checked;
return this.SUPER(clickInfo, options).then(function () {
if (el.checked === oldState) {
el.checked = !oldState;
var optionsWithBubble = Joose.O.copy(options)
optionsWithBubble.bubbles = true
me.simulateEvent(el, 'change', optionsWithBubble)
}
});
} else {
return this.SUPERARG(arguments);
}
}
}
})
</pre>
</body>
</html>