UNPKG

siesta-lite

Version:

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

644 lines (532 loc) 22.7 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.ResultPanel&#39;, { extend : &#39;Ext.Panel&#39;, alias : &#39;widget.resultpanel&#39;, requires : [ &#39;Siesta.Project.Browser.UI.AssertionGrid&#39;, &#39;Siesta.Project.Browser.UI.DomContainer&#39;, &#39;Siesta.Project.Browser.UI.SourcePanel&#39;, &#39;Siesta.Recorder.UI.RecorderPanel&#39; ], slots : true, test : null, testListeners : null, maintainViewportSize : true, scaleToFit : true, scaleToFitMode : &#39;full&#39;, viewDOM : false, border : false, canManageDOM : true, project : null, isStandalone : false, showToolbar : true, title : &#39;Result panel&#39;, header : false, minWidth : 100, layout : &#39;border&#39;, sourceButton : null, filterButton : null, inspectionButton : null, recorderPanel : null, recorderConfig : null, recorderPanelClass : &#39;Siesta.Recorder.UI.RecorderPanel&#39;, domContainerRegion : &#39;east&#39;, isReadOnlyReport : false, initComponent : function () { var me = this; var R = Siesta.Resource(&#39;Siesta.Project.Browser.UI.ResultPanel&#39;); var domContainerRegion = this.domContainerRegion || &#39;east&#39; Ext.apply(this, { cls : &#39;tr-container&#39;, tbar : { cls : &#39;resultpanel-toolbar&#39;, defaults : { tooltipType : &#39;title&#39;, scope : this }, items : this.getTopToolbarItems(R) }, items : [ // a card container { region : &#39;center&#39;, slot : &#39;cardContainer&#39;, xtype : &#39;container&#39;, layout : { type : &#39;card&#39;, deferredRender : true }, activeItem : 0, minWidth : 100, items : [ // grid with assertion { xtype : &#39;assertiongrid&#39;, slot : &#39;grid&#39;, isStandalone : this.isStandalone, listeners : { itemdblclick : this.onAssertionDoubleClick, scope : this } }, // eof grid with assertion { xtype : &#39;sourcepanel&#39;, slot : &#39;source&#39;, listeners : { render : function(panel) { var el = panel.getEl().appendChild({ cls : &#39;si-sourcepanel-close fa-close&#39;, style : &#39;right:&#39; + (Ext.getScrollbarSize().width + 5) + &#39;px&#39; }); el.on(&#39;click&#39;, this.hideSource, this); }, scope : this } } ].concat( Ext.ClassManager.getByAlias(&#39;widget.coveragereport&#39;) ? { // to avoid coverage report to be picked up as a dependency by sencha cmd compiler xtype : &#39;coverage&#39; + &#39;report&#39;, slot : &#39;coverageReport&#39;, project : this.project } : [] ) }, { xtype : &#39;domcontainer&#39;, region : domContainerRegion, collapsible : true, hidden : this.isReadOnlyReport, split : { size : 7 }, bodyStyle : &#39;text-align : center&#39;, slot : &#39;domContainer&#39;, stateful : true, // Turn off for recursive siesta demo id : this.id + &#39;-domContainer&#39;, width : (domContainerRegion == &#39;east&#39; || domContainerRegion == &#39;west&#39;) ? &#39;50%&#39; : null, height : (domContainerRegion == &#39;south&#39; || domContainerRegion == &#39;north&#39;) ? &#39;50%&#39; : null, cls : &#39;siesta-domcontainer&#39;, collapsed : !this.viewDOM, scaleToFit : this.scaleToFit, scaleToFitMode : this.scaleToFitMode } ] }) this.callParent() this.slots.domContainer &amp;&amp; this.slots.domContainer.on({ expand : this.onDomContainerExpand, collapse : this.onDomContainerCollapse, inspectionstart : function () { this.inspectionButton.toggle(true); }, inspectionstop : function () { this.inspectionButton.toggle(false); }, scope : this }); }, onLoadReportFileChange : function (field) { var me = this var file = field.fileInputEl.dom.files[ 0 ] var reader = new FileReader() reader.onload = function () { try { var json = JSON.parse(reader.result) } catch (e) { Ext.Msg.alert(&quot;Error&quot;, &quot;Error parsing JSON&quot;) } if (json) me.fireEvent(&#39;newjsonreport&#39;, me, json) } reader.onerror = function () { Ext.Msg.alert(&quot;Error&quot;, &quot;Error loading file&quot;) } reader.readAsText(file) }, getTopToolbarItems : function (R) { var me = this; if (!this.showToolbar) return null var state = this.stateConfig; var isReadOnlyReport = this.isReadOnlyReport var items = [] if (!isReadOnlyReport) items.push( { text : R.get(&#39;rerunText&#39;), cls : &#39;rerun-button&#39;, glyph : 0xf04b, scale : &#39;medium&#39;, handler : this.onRunTestClick } ) items.push( { xtype : &#39;label&#39;, cls : &#39;resultpanel-testtitle&#39;, itemId : &#39;resultpanel-testtitle&#39;, margin : &#39;0 0 0 10&#39;, height : 48, text : &#39; &#39;, flex : 1 } ) if (isReadOnlyReport &amp;&amp; window.FileReader) items.push( { xtype : &#39;fileuploadfield&#39;, buttonOnly : true, buttonText : &#39;Load data file&#39;, listeners : { change : this.onLoadReportFileChange, scope : this } } ) if (!isReadOnlyReport) items.push( { xtype : &#39;label&#39;, cls : &#39;speedlabel&#39;, margin : &#39;0 20&#39;, text : &#39;Mouse speed&#39;, // need some dummy id to avoid some warning in FF (requested by Sergey) forId : &#39;dummyId&#39; }, { xtype : &#39;segmentedbutton&#39;, cls : &#39;speed-button&#39;, scale : &#39;small&#39;, margin : &#39;0 30 0 0&#39;, items : [{ text : &#39;Slow&#39;, tooltip : &#39;Slow and accurate mouse simulation&#39;, pressed : !state.speedRun &amp;&amp; !state.turboMode, option : &#39;mouseSimSlow&#39; }, { text : &#39;Fast&#39;, tooltip : &#39;Fast, but still accurate mouse simulation&#39;, pressed : state.speedRun &amp;&amp; !state.turboMode, option : &#39;mouseSimFast&#39; }, { text : &#39;Turbo&#39;, pressed : state.turboMode, tooltip : &#39;Turbo mode! Super fast with reduced mouse precision (read docs before using)&#39;, option : &#39;mouseSimFastest&#39; }], listeners : { toggle : function (segmentedButton, button) { me.fireEvent(&#39;optionchange&#39;, button, button.option, true); } } }, this.viewDomButton = new Ext.Button({ tooltip : &quot;Force native events simulation&quot;, cls : &#39;testaction-button&#39;, action : &#39;force-native&#39;, scale : &#39;medium&#39;, glyph : 0xf25a, enableToggle : true, scope : this, pressed : this.project.simulation == &#39;native&#39;, handler : function (btn) { this.project.simulation = btn.pressed ? &#39;native&#39; : &#39;synthetic&#39; } }), this.viewDomButton = new Ext.Button({ tooltip : R.get(&#39;toggleDomVisibleText&#39;), cls : &#39;testaction-button&#39;, action : &#39;view-dom&#39;, scale : &#39;medium&#39;, glyph : 0xf26c, enableToggle : true, scope : this, pressed : this.viewDOM, handler : function (btn) { this.setViewDOM(btn.pressed); } }), this.scaleToFitButton = new Ext.SplitButton({ tooltip : &#39;Scale to fit&#39;, cls : &#39;testaction-button&#39;, action : &#39;scale-to-fit&#39;, scale : &#39;medium&#39;, glyph : 0xf065, enableToggle : true, pressed : Boolean(this.scaleToFit), menu : { items : [ { glyph : 0xf0b2, text : &#39;Fit full&#39;, itemId : &#39;full&#39; }, { glyph : 0xf07e, text : &#39;Fit width&#39;, itemId : &#39;width&#39; }, { glyph : 0xf07d, text : &#39;Fit height&#39;, itemId : &#39;height&#39; } ], listeners: { click : function(menu, item) { this.slots.domContainer.setScaleToFit(true, item.itemId) this.scaleToFitButton.setPressed(true); }, scope : this } }, scope : this, handler : function(btn) { this.slots.domContainer.setScaleToFit(btn.pressed) } }), this.sourceButton = new Ext.Button({ tooltip : R.get(&#39;viewSourceText&#39;), action : &#39;view-source&#39;, cls : &#39;testaction-button&#39;, glyph : 0xf0f6, scale : &#39;medium&#39;, tooltipType : &#39;title&#39;, disabled : true, enableToggle : true, scope : this, handler : function (btn) { if (btn.pressed) { this.showSource(); } else { this.hideSource() } } }), this.filterButton = new Ext.Button({ tooltip : R.get(&#39;showFailedOnlyText&#39;), action : &#39;show-failed-only&#39;, cls : &#39;testaction-button&#39;, scale : &#39;medium&#39;, glyph : 0xf188, tooltipType : &#39;title&#39;, scope : this, enableToggle : true, handler : this.onAssertionFilterClick }), this.inspectionButton = new Ext.Button({ glyph : 0xf002, cls : &#39;testaction-button cmp-inspector&#39;, action : &#39;toggle-cmp-inspector&#39;, scale : &#39;medium&#39;, tooltip : &#39;Target highlighter&#39;, tooltipType : &#39;title&#39;, handler : this.toggleComponentInspectionMode, scope : this, enableToggle : true }), this.recorderButton = new Ext.Button({ glyph : 0xf03d, action : &#39;toggle-recorder&#39;, cls : &#39;testaction-button&#39;, scale : &#39;medium&#39;, disabled : !Siesta.Recorder || Ext.isIE9m, tooltip : R.get(&#39;eventRecorderText&#39;), handler : this.onRecorderClick, margin : &#39;0 30 0 0&#39;, scope : this, enableToggle : true }), { xtype : &#39;versionupdatebutton&#39; }, { xtype : &#39;component&#39;, id : &#39;siesta-logo&#39; } ) return items }, // This method makes sure that the min width of the card panel is respected when // the width of this class changes (after resizing Test TreePanel). ensureLayout : function () { var availableWidth = this.getWidth(); var cardPanel = this.slots.cardContainer; var domContainer = this.slots.domContainer; var domContainerWidth = domContainer.getWidth(); var minimumForCard = cardPanel.minWidth + 20; // Some splitter space if (availableWidth - domContainerWidth &lt; minimumForCard) { domContainer.setWidth(Math.max(0, availableWidth - minimumForCard)); } }, showSource : function (lineNbr) { var test = this.test if (!this.test) return; var sourceLines = []; var slots = this.slots var cardContainer = slots.cardContainer var sourceCt = slots.source; // Do this first since rendering is deferred cardContainer.layout.setActiveItem(sourceCt); if (arguments.length === 0) { // Highlight all failed rows Ext.each(test.getFailedAssertions(), function (assertion) { if (assertion.sourceLine != null) { sourceLines.push(assertion.sourceLine) } }); } else { // Highlight just a single row (user double clicked a failed row) sourceLines = [lineNbr]; } sourceCt.setSource(test.getSource(), sourceLines); }, hideSource : function () { var slots = this.slots var cardContainer = slots.cardContainer if (cardContainer.layout.getActiveItem() === slots.source) { this.sourceButton.setPressed(false); cardContainer.layout.setActiveItem(slots.grid); } }, setViewDOM : function (value) { var domContainer = this.slots.domContainer if (value) domContainer.expand(false) else domContainer.collapse(null, false) }, onDomContainerCollapse : function () { this.viewDOM = false; this.viewDomButton.toggle(false); this.fireEvent(&#39;viewdomchange&#39;, this, false); }, onDomContainerExpand : function () { this.viewDOM = true; this.viewDomButton.toggle(true); this.fireEvent(&#39;viewdomchange&#39;, this, true); }, onRunTestClick : function () { this.fireEvent(&#39;runbuttonclick&#39;, this); }, showTest : function (test, assertionsStore) { var recorder = this.slots.recorderPanel; this.slots.source.clear(); this.filterButton &amp;&amp; this.filterButton.toggle(false) this.hideSource(); this.sourceButton &amp;&amp; this.sourceButton.enable() var url = test.url; Ext.suspendLayouts(); this.slots.grid.showTest(test, assertionsStore) this.slots.domContainer.showTest(test, assertionsStore) if (recorder) { if (!recorder.test || test.url !== recorder.test.url) { recorder.stop(); recorder.attachTo(test); } } this.setTestTitle(url === &#39;/&#39; ? recorder.getRecordingName() : url); Ext.resumeLayouts(); this.test = test; }, setTestTitle : function (url) { this.testTitle.setText(url); }, onAssertionFilterClick : function (btn) { var grid = this.slots.grid; var assertionsStore = grid.store; // need this check for cases when users clicks on the button // before running any test - in this case assertion grid will have an empty Ext.data.TreeStore instance if (!assertionsStore.filterTreeBy) return if (btn.pressed) { grid.addCls(&#39;assertiongrid-filtered&#39;); assertionsStore.filterTreeBy(function (resultRecord) { var result = resultRecord.getResult() // this covers the cases when &quot;result&quot; is a summary record, diagnostic record, etc return result.passed === false &amp;&amp; !result.isTodo }) } else { grid.removeCls(&#39;assertiongrid-filtered&#39;); assertionsStore.clearTreeFilter() } }, alignIFrame : function () { this.slots.domContainer.alignIFrame() }, hideIFrame : function () { this.slots.domContainer.hideIFrame() }, setInitializing : function (initializing) { this.slots.grid.setInitializing(initializing) }, onAssertionDoubleClick : function (view, record) { var result = record.getResult() if ((result instanceof Siesta.Result.Assertion) &amp;&amp; !result.isPassed(true)) { this.showSource(result.sourceLine); } }, toggleComponentInspectionMode : function (btn) { this.slots.domContainer.toggleInspectionMode(btn.pressed); }, onRecorderClick : function () { var cardContainer = this.slots.cardContainer if (!this.recorderPanel) { this.recorderPanel = Ext.create(this.recorderPanelClass, { slot : &#39;recorderPanel&#39;, project : this.project, domContainer : this.slots.domContainer, recorderConfig : this.recorderConfig, closeButton : { text : Siesta.Resource(&#39;Siesta.Project.Browser.UI.ResultPanel&#39;, &#39;closeText&#39;), cls : &#39;recorder-tool&#39;, handler : function () { cardContainer.layout.setActiveItem(0); } }, listeners : { startrecord : function (pnl, test) { this.fireEvent(&#39;startrecord&#39;, pnl, test); this.showTest(test); }, show : function () { this.recorderButton.toggle(true); }, play : function (pnl, test) { this.showTest(test); }, hide : function () { this.recorderButton.toggle(false); }, scope : this } }); this.slots.cardContainer.add(this.recorderPanel); this.relayEvents(this.recorderPanel, [ &#39;startrecord&#39;, &#39;play&#39; ], &#39;recorder&#39;); if (this.test) { this.slots.recorderPanel.attachTo(this.test); } } if (cardContainer.layout.getActiveItem() === this.recorderPanel) { cardContainer.layout.setActiveItem(this.slots.grid); } else { cardContainer.layout.setActiveItem(this.recorderPanel); } }, afterRender : function () { this.callParent(arguments); var splitter = this.child(&#39;bordersplitter&#39;); this.testTitle = this.down(&#39;#resultpanel-testtitle&#39;); // To avoid the DOM container splitter getting stuck splitter &amp;&amp; (splitter.tracker.tolerance = 0); } }); </pre> </body> </html>