AbstractTestCard.js (3896B)
1 /** 2 * This class represents an abstract test card. The purpose of this card is to run 3 * specific tests, display the test results and offer a "re-test" button which the 4 * user can click in order to perform the tests. 5 * 6 * Additionally, the "next" button of the wizward will be disabled if the test fails. 7 */ 8 Ext.define('PartKeeprSetup.AbstractTestCard', { 9 extend: 'Ext.Container', 10 11 /** 12 * Contains the test results for this card 13 * @var PartKeeprSetup.TestResultPanel 14 */ 15 testResultPanel: null, 16 17 /** 18 * Contains the initially hidden "Re-test" button to re-trigger the tests. 19 */ 20 retestButton: null, 21 22 /** 23 * Contains the test which will be run 24 * @var array 25 */ 26 tests: null, 27 28 /** 29 * Text which will be shown above the test result panel. 30 * @var string 31 */ 32 cardMessage: null, 33 34 /** 35 * Various Style Settings 36 */ 37 autoScroll: true, 38 39 rerunTestText: "Re-run checks", 40 41 margin: 20, 42 43 layout: { 44 type: 'vbox', 45 align: 'stretch' 46 }, 47 /** 48 * Inits the component 49 */ 50 initComponent: function () 51 { 52 this.testResultPanel = Ext.create("PartKeeprSetup.TestResultPanel", { 53 flex: 1 54 }); 55 this.testResultPanel.on("test-error", this.onTestError, this); 56 57 this.retestButton = Ext.create("Ext.button.Button", { 58 text: this.rerunTestText, 59 hidden: true, 60 height: 20 61 }); 62 63 this.retestButton.on("click", this.retest, this); 64 65 this.items = [ 66 { 67 border: false, 68 bodyStyle: 'background:none;padding-bottom: 10px;', 69 height: 20, 70 html: this.cardMessage 71 }, 72 this.testResultPanel, 73 this.retestButton 74 ]; 75 76 this.tests = new Array(); 77 78 this.testRunner = Ext.create("PartKeeprSetup.TestRunner"); 79 this.testRunner.on("success", this.onTestSuccessful, this); 80 81 this.setupTests(); 82 this.callParent(); 83 this.on("activate", this.onActivate, this); 84 }, 85 86 /** 87 * Re-runs the configured tests and hides the Re-test button, 88 * because we don't know if the tests will be successful. 89 */ 90 retest: function () 91 { 92 this.retestButton.hide(); 93 this.runTests(); 94 }, 95 /** 96 * Called when an error occurs. Shows the "re-test" button 97 * and disables the "next" button. 98 */ 99 onTestError: function () 100 { 101 this.retestButton.show(); 102 Ext.ComponentQuery.query('#nextBtn')[0].disable(); 103 }, 104 /** 105 * Called when all tests are successful. Hides the "re-test" 106 * button and enables the "next" button. 107 */ 108 onTestSuccessful: function () 109 { 110 this.retestButton.hide(); 111 112 Ext.ComponentQuery.query('#nextBtn')[0].enable(); 113 }, 114 /** 115 * Invokes the test runner with all configured tests 116 */ 117 runTests: function () 118 { 119 this.testResultPanel.clear(); 120 121 // We need to clone the test array, because we wouldn't be able to run all tests twice 122 var clonedTests = this.tests.slice(0); 123 this.testRunner.run(clonedTests, this.testResultPanel); 124 125 }, 126 /** 127 * When the card is activated, automatically invoke all tests. 128 */ 129 onActivate: function () 130 { 131 Ext.ComponentQuery.query('#nextBtn')[0].disable(); 132 this.retestButton.hide(); 133 134 this.runTests(); 135 }, 136 /** 137 * This method needs to be overridden by subclasses. Subclasses 138 * need to append tests to the "tests" array, e.g. 139 * 140 * var j = Ext.create("PartKeeprSetup.FilesystemPermissionTest"); 141 * j.callback = this.testResultPanel; 142 * this.tests.push(j); 143 * 144 */ 145 setupTests: function () 146 { 147 window.alert("The method setupTests() need to be overridden in a subclass!"); 148 } 149 }); 150