UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

519 lines (427 loc) 19.1 kB
<!DOCTYPE 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(&#39;Siesta.Project.Browser.UI.TestGrid&#39;, { extend : &#39;Ext.tree.Panel&#39;, alias : &#39;widget.testgrid&#39;, requires : [ &#39;Siesta.Project.Browser.UI.FilterableTreeView&#39;, &#39;Siesta.Project.Browser.UI.TestGridController&#39;, &#39;Siesta.Project.Browser.UI.TestNameColumn&#39; ], controller : &#39;testgrid&#39;, stateful : true, rootVisible : false, header : false, rowLines : false, useArrows : true, border : false, cls : &#39;tr-testgrid&#39;, iconCls : &#39;tr-status-neutral-small&#39;, width : 340, collapsible : true, expanded : true, viewType : &#39;filterabletreeview&#39;, enableColumnMove : false, project : null, lines : false, filter : null, filterGroups : false, resultSummary : null, stateConfig : null, showSizeControls : false, isReadOnlyReport : false, menuHideTimeout : false, viewConfig : { enableTextSelection : true, toggleOnDblClick : false, markDirty : false, trackOver : false, getRowClass : function(record) { if (record.get(&#39;descriptor&#39;).isSystemDescriptor) { return &#39;siesta-system-descriptor&#39;; } }, // Avoid DOM updates when irrelevant shouldUpdateCell : function(record, column, changedFieldNames) { if (column.dataIndex === &#39;passCount&#39; &amp;&amp; changedFieldNames &amp;&amp; !( Ext.Array.contains(changedFieldNames, &#39;passCount&#39;) || Ext.Array.contains(changedFieldNames, &#39;todoPassCount&#39;) ) ) { return 0; } if (column.dataIndex === &#39;failCount&#39; &amp;&amp; changedFieldNames &amp;&amp; !( Ext.Array.contains(changedFieldNames, &#39;failCount&#39;) || Ext.Array.contains(changedFieldNames, &#39;todoFailCount&#39;) ) ) { return 0; } return Ext.tree.View.prototype.shouldUpdateCell.apply(this, arguments); } }, initComponent : function () { var me = this; var R = Siesta.Resource(&#39;Siesta.Project.Browser.UI.TestGrid&#39;); var state = this.stateConfig; Ext.apply(this, { title : R.get(&#39;title&#39;), columns : { // Hack, prevent Ext JS grid column to react to click/keys in filter field createFocusableContainerKeyNav : Ext.emptyFn, // EOF Hack items : [ { xtype : &#39;testnamecolumn&#39;, store : this.store, project : this.project }, { header : R.get(&#39;passText&#39;), width : 35, sortable : false, tdCls : &#39;x-unselectable result-cell&#39;, menuDisabled : true, dataIndex : &#39;passCount&#39;, align : &#39;center&#39;, renderer : this.passedColumnRenderer, scope : this }, { header : R.get(&#39;failText&#39;), width : 35, sortable : false, tdCls : &#39;x-unselectable result-cell&#39;, menuDisabled : true, dataIndex : &#39;failCount&#39;, align : &#39;center&#39;, renderer : this.failedColumnRenderer, scope : this }, { header : &#39;Time&#39;, width : 50, sortable : false, dataIndex : &#39;time&#39;, align : &#39;center&#39;, renderer : function (value, meta, record) { if (!record.isLeaf()) return &#39;&#39; return value + &#39;ms&#39;; }, hidden : !(this.project.showTestDurationColumn || this.isReadOnlyReport) } ] }, bbar : { xtype : &#39;toolbar&#39;, cls : &#39;main-bbar siesta-toolbar&#39;, border : false, height : 45, defaults : { scale : &#39;large&#39;, width : 30, tooltipType : &#39;title&#39; }, items : this.getBottomBarItems(state, R) }, dockedItems : this.showSizeControls ? [ { xtype : &#39;toolbar&#39;, cls : &#39;size-toolbar&#39;, border : true, dock : &#39;bottom&#39;, items : [ { xtype : &#39;slider&#39;, itemId : &#39;framesizeSlider&#39;, width : 130, value : 3, increment : 1, minValue : 0, maxValue : this.viewportSizes.length - 1, listeners : { change : this.onDimensionOrOrientationChange, scope : this } }, { xtype : &#39;label&#39;, cls : &#39;size-label&#39;, itemId : &#39;sizeLabel&#39;, width : 65 }, { boxLabel : R.get(&#39;landscape&#39;), itemId : &#39;orientationCheckbox&#39;, xtype : &#39;checkbox&#39;, checked : true, listeners : { change : this.onDimensionOrOrientationChange, scope : this } } ] } ] : [] }) this.callParent(arguments); this.getView().on(&#39;beforerefresh&#39;, function () { var trigger = me.down(&#39;#trigger&#39;) if (me.filterGroups) trigger.setFilterGroups(me.filterGroups) if (me.filter) trigger.setValue(me.filter) // cancel refresh if there&#39;s a filter - in this case an additional refresh will be triggered by // the filtering which will be already not canceled since this is 1 time listener return !me.filter }, null, { single : true }) this.on(&#39;viewready&#39;, this.onMyViewReady, this, { delay : 10 }); }, getBottomBarItems : function (state, R) { var items = [] if (!this.isReadOnlyReport) { items.push( { glyph : 0xf04b, cls : &#39;run-checked&#39;, text : &#39;&lt;span class=&quot;subicon fa-check&quot;&gt;&lt;/span&gt;&#39;, tooltip : R.get(&#39;runCheckedText&#39;), actionName : &#39;run-checked&#39; }, { glyph : 0xf04e, cls : &#39;run-all&#39;, tooltip : R.get(&#39;runAllText&#39;), actionName : &#39;run-all&#39; }, { glyph : 0xf04b, cls : &#39;run-failed&#39;, text : &#39;&lt;span class=&quot;subicon fa-bug&quot;&gt;&lt;/span&gt;&#39;, tooltip : R.get(&#39;runFailedText&#39;), actionName : &#39;run-failed&#39; }, { glyph : 0xf013, tooltip : R.get(&#39;optionsText&#39;), cls : &#39;options&#39;, action : &#39;options&#39;, listeners : { mouseover : this.onOptionsButtonMouseOver, mouseout : this.onOptionsButtonMouseOut, scope : this }, menu : { itemId : &#39;tool-menu&#39;, listeners : { mouseenter : { fn : this.onOptionsMenuMouseEnter, // delay to cancel the hide _after_ the &quot;mouseleave&quot; from the sub-menu delay : 100 }, mouseover : { fn : this.onOptionsMenuMouseEnter, delay : 100 }, mouseleave : this.onOptionsMenuMouseLeave, scope : this }, items : [ { text : R.get(&#39;transparentExText&#39;), option : &#39;transparentEx&#39;, checked : state.transparentEx, tooltip : R.get(&#39;transparentExTooltip&#39;) }, // { // text : R.get(&#39;cachePreloadsText&#39;), // option : &#39;cachePreload&#39;, // checked : state.cachePreload // }, { text : R.get(&#39;breakOnFailText&#39;), option : &#39;breakOnFail&#39;, checked : state.breakOnFail, tooltip : R.get(&#39;breakOnFailTooltip&#39;) }, { text : R.get(&#39;debuggerOnFailText&#39;), option : &#39;debuggerOnFail&#39;, checked : state.debuggerOnFail, tooltip : R.get(&#39;debuggerOnFailTooltip&#39;) }, { itemId : &#39;observerModeMenuItem&#39;, text : R.get(&#39;observerModeText&#39;), option : &#39;observerMode&#39;, checked : state.observerMode, tooltip : R.get(&#39;observerModeTooltip&#39;) }, { text : R.get(&#39;autoLaunchText&#39;), option : &#39;autoRun&#39;, checked : state.autoRun, tooltip : R.get(&#39;autoLaunchTooltip&#39;) }, { xtype : &#39;menuseparator&#39; }, { text : R.get(&#39;aboutText&#39;), itemId : &#39;aboutSiesta&#39; }, { text : R.get(&#39;documentationText&#39;), href : R.get(&#39;siestaDocsUrl&#39;), hrefTarget : &#39;_blank&#39; } ] } } ) } items.push( &#39;-&gt;&#39;, { xtype : &#39;component&#39;, cls : &#39;summary-bar&#39;, border : false, width : 55, itemId : &#39;result-summary&#39;, data : { pass : 0, fail : 0 }, tpl : &#39;&lt;div&gt;&lt;span class=&quot;total-pass&quot;&gt;{pass}&lt;/span&gt;&lt;span class=&quot;icon fa-check&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;total-fail&quot;&gt;{fail}&lt;/span&gt;&lt;span class=&quot;icon fa-bug&quot;&gt;&lt;/span&gt;&lt;/div&gt;&#39; } ) return items }, onHistoryChange : function(token) { if (token) { var testFile = this.store.getNodeById(token) if (testFile) { this.selectTestFile(testFile); } } }, onDimensionOrOrientationChange : function (slider, val) { var newSize = this.viewportSizes[this.framesizeSlider.getValue()]; var landscape = this.orientationCheckbox.getValue(); this.sizeLabel.setText(newSize.join(&#39;x&#39;)); this.fireEvent(&#39;framesizechange&#39;, slider, newSize[0], newSize[1], landscape); }, getFilterValue : function () { return this.down(&#39;#trigger&#39;).getValue() }, getFilterGroups : function () { return this.down(&#39;#trigger&#39;).getFilterGroups() }, passedColumnRenderer : function (value, meta, record) { if (!record.isLeaf()) return &#39;&#39; if (record.data.todoPassCount &gt; 0) { value += &#39; &lt;span title=&quot;&#39; + record.data.todoPassCount + &#39; &#39; + Siesta.Resource(&#39;Siesta.Project.Browser.UI.TestGrid&#39;, &#39;todoPassedText&#39;) + &#39;&quot; class=&quot;tr-test-todo tr-test-todo-pass&quot;&gt;+ &#39; + record.data.todoPassCount + &#39;&lt;/span&gt;&#39;; } return value; }, failedColumnRenderer : function (value, meta, record) { if (!record.isLeaf()) return &#39;&#39; if (record.data.todoFailCount &gt; 0) { value += &#39; &lt;span title=&quot;&#39; + record.data.todoFailCount + &#39; &#39; + Siesta.Resource(&#39;Siesta.Project.Browser.UI.TestGrid&#39;, &#39;todoFailedText&#39;) + &#39;&quot; class=&quot;tr-test-todo tr-test-todo-fail&quot;&gt;+ &#39; + record.data.todoFailCount + &#39;&lt;/span&gt;&#39;; } return value; }, onOptionsButtonMouseOver : function (button) { clearTimeout(this.menuHideTimeout) button.showMenu() button.menu.hide = function () {} setTimeout(function () { delete button.menu.hide }, 1000) }, onOptionsButtonMouseOut : function (button) { var me = this if (this.menuHideTimeout) return this.menuHideTimeout = setTimeout(function () { delete button.menu.hide button.hideMenu() me.menuHideTimeout = null }, 500) }, onOptionsMenuMouseEnter : function (menu) { clearTimeout(this.menuHideTimeout) this.menuHideTimeout = null }, onOptionsMenuMouseLeave : function () { var me = this var menu = this.down(&#39;#tool-menu&#39;) if (this.menuHideTimeout) return this.menuHideTimeout = setTimeout(function () { delete menu.hide menu.hide() me.menuHideTimeout = null }, 500) }, afterRender : function () { this.callParent(arguments); this.summaryPassEl = this.el.down(&#39;.total-pass&#39;); this.summaryFailEl = this.el.down(&#39;.total-fail&#39;); if (this.showSizeControls) { this.orientationCheckbox = this.down(&#39;#orientationCheckbox&#39;); this.sizeLabel = this.down(&#39;#sizeLabel&#39;); this.framesizeSlider = this.down(&#39;#framesizeSlider&#39;); var size = this.viewportSizes[ this.framesizeSlider.getValue() ]; this.sizeLabel.setText(size.join(&#39;x&#39;)); } }, onMyViewReady : function() { Ext.History.on(&#39;change&#39;, this.onHistoryChange, this); var hash = window.location.hash; if (hash) { this.onHistoryChange(hash.substring(1)); } }, updateStatus : function (pass, fail) { this.summaryPassEl.update(String(pass)); this.summaryFailEl.update(String(fail)); }, setFilterValue : function (value) { this.down(&#39;treefilter&#39;).setValue(value) }, selectTestFile : function(testFile) { if (testFile) { testFile.bubble(function(parent) { parent.expand(); }); // Make sure test is not filtered out if (this.store.getById(testFile.id) &amp;&amp; this.store.indexOf(testFile) &gt;= 0 ) { if (!this.getCollapsed() &amp;&amp; this.getView().getNodes().length &gt; 0) { this.ensureVisible(testFile); } this.getSelectionModel().select(testFile) } } } }) </pre> </body> </html>