siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
124 lines (94 loc) • 3.73 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
*/
Ext.define('Siesta.Recorder.UI.Store.Action', {
extend : 'Ext.data.TreeStore',
alias : 'store.actionstore',
model : 'Siesta.Recorder.UI.Model.Action',
proxy : 'memory',
root : {
expanded : true
},
tabSize : 4,
generateCode : function (name) {
var root = this.getRootNode();
var code = '';
var isPageNav = this.doesRecordingNavigatePages();
if (root.childNodes.length > 0) {
if (root.firstChild.isLeaf()) {
// Make a simple chain
code = this.generateChain(root);
} else {
// Group assertions into "it" statements
code = root.childNodes.map(this.generateCodeForNode, this).join('\n\n');
}
}
// If recording navigates between pages we need to force enablePageRedirect option or test execution will break
if (isPageNav) {
return 'describe({\n name : "' + name + '",' +
'\n enablePageRedirect : true\n}, function(t) {\n' + code + '\n});'
} else {
return 'describe("' + name + '", function(t) {\n' + code + '\n});'
}
},
doesRecordingNavigatePages : function() {
var pageNav = false;
this.getRoot().cascadeBy(function(node) {
if (node.get('waitForPageLoad')) {
pageNav = true;
return false;
}
});
return pageNav;
},
generateCodeForNode : function (node) {
if (node.isLeaf()) {
return this.getIndent(node.data.depth + 1) + node.asCode();
}
if (node.get('action') === 'group') {
return this.generateIt(node);
}
},
generateIt : function (node) {
var indent = this.getIndent(node.data.depth);
var itPre = indent + 't.it("' + (node.get('value') || 'should...') + '", function(t) {\n';
var itPost = '\n' + indent + '});';
return itPre + this.generateChain(node) + itPost;
},
generateChain : function (node) {
var me = this;
var indent = this.getIndent(node.data.depth + 1);
var chainPre = indent + 't.chain(\n';
var chainPost = '\n' + indent + ');';
var codeForSteps = node.childNodes.map(function (step) {
return me.generateCodeForNode(step);
}).join(',\n\n');
return chainPre + codeForSteps + chainPost;
},
getIndent : function (tabs) {
return new Array((this.tabSize * tabs) + 1).join(' ');
}
});
</pre>
</body>
</html>