Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-02-16 14:02:18 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-02-19 15:21:14 -0500
commitf788edd675e3662192c2421ae142fb1f42d3da49 (patch)
tree3d4c10c25b31bf1ffcf8190c7951577281e83d76 /src
parent253f8458039f1331a6b62f3a8a6d3510ae49868b (diff)
downloadtame-f788edd675e3662192c2421ae142fb1f42d3da49.tar.gz
tame-f788edd675e3662192c2421ae142fb1f42d3da49.tar.bz2
tame-f788edd675e3662192c2421ae142fb1f42d3da49.zip
Initial embedding of YAML test case runner
Diffstat (limited to 'src')
-rw-r--r--src/current/include/entry-form.xsl1
-rw-r--r--src/current/scripts/entry-form.js84
l---------src/current/scripts/tame-progtest.js1
-rw-r--r--src/current/summary.css8
4 files changed, 94 insertions, 0 deletions
diff --git a/src/current/include/entry-form.xsl b/src/current/include/entry-form.xsl
index 8d2cc2c..804c173 100644
--- a/src/current/include/entry-form.xsl
+++ b/src/current/include/entry-form.xsl
@@ -132,6 +132,7 @@
</xsl:for-each-group>
</form>
+ <script type="text/javascript" src="{$fw-path}/rater/scripts/tame-progtest.js"></script>
<script type="text/javascript" src="{$fw-path}/rater/scripts/entry-form.js"></script>
</xsl:template>
diff --git a/src/current/scripts/entry-form.js b/src/current/scripts/entry-form.js
index 616e100..2f1f728 100644
--- a/src/current/scripts/entry-form.js
+++ b/src/current/scripts/entry-form.js
@@ -1501,8 +1501,41 @@ var client = ( function()
loadQuote( qid, qdata_host );
} );
+ const yamlconsole = dom.createElement( 'textarea' );
+ yamlconsole.style.display = 'none';
+ yamlconsole.id = 'yamlconsole';
+
+ const yamlbrowse = dom.createElement( 'input' );
+ yamlbrowse.type = 'file';
+ yamlbrowse.style.display = 'none';
+ yamlbrowse.accept = '.yml, .yaml';
+ yamlbrowse.multiple = 'multiple';
+ yamlbrowse.addEventListener( 'change', e =>
+ {
+ yamlconsole.style.display = '';
+ yamlconsole.textContent = '';
+
+ runYamlTestCases(
+ Array.prototype.slice.call( yamlbrowse.files, 0 ),
+ createYamlRunner( yamlconsole )
+ );
+
+ return false;
+ } );
+
+ const yamlcases = dom.createElement( 'button' );
+ yamlcases.innerHTML = 'Load YAML Test Cases';
+ yamlcases.addEventListener( 'click', e =>
+ {
+ yamlbrowse.click();
+ return false;
+ } );
+
dialog.appendChild( retest );
dialog.appendChild( loadquote );
+ dialog.appendChild( yamlcases );
+ dialog.appendChild( yamlbrowse );
+ dialog.appendChild( yamlconsole );
dialog.appendChild( getPriorTable() );
dom.body.appendChild( dialog );
@@ -1517,6 +1550,57 @@ var client = ( function()
};
+ /**
+ * Create YAML test case runner
+ *
+ * @param {HTMLElement} yamlconsole element to contain runner output
+ *
+ * @return {function(string)} runner
+ */
+ const createYamlRunner = yamlconsole => require( 'progtest' )
+ .env.console(
+ { rater: window.rater },
+ {
+ write( str )
+ {
+ yamlconsole.textContent += str;
+ }
+ }
+ );
+
+
+ /**
+ * Run test cases in each YAML file FILES
+ *
+ * @param {Array<File>} files YAML files
+ * @param {function(string)} runner test case runner
+ *
+ * @return {undefined}
+ */
+ const runYamlTestCases = function( files, runner )
+ {
+ if ( files.length === 0 )
+ {
+ return;
+ }
+
+ const testfile = files.shift();
+ const reader = new FileReader();
+
+ reader.onload = ev =>
+ {
+ const yaml = ev.target.result;
+
+ runner( yaml );
+
+ // run for remaining files
+ runYamlTestCases( files, runner );
+ };
+
+ reader.readAsBinaryString( testfile );
+ };
+
+
var getPriorTable = function()
{
var table = dom.createElement( 'table' ),
diff --git a/src/current/scripts/tame-progtest.js b/src/current/scripts/tame-progtest.js
new file mode 120000
index 0000000..c2cb3ef
--- /dev/null
+++ b/src/current/scripts/tame-progtest.js
@@ -0,0 +1 @@
+../../../progtest/tame-progtest.js \ No newline at end of file
diff --git a/src/current/summary.css b/src/current/summary.css
index 64d3948..6b97113 100644
--- a/src/current/summary.css
+++ b/src/current/summary.css
@@ -1020,3 +1020,11 @@ body:not(.prior) #voi-container td.prior
background-color: #ffc0c0;
border-color: #c00000;
}
+
+#yamlconsole
+{
+ display: block;
+ width: 95%;
+ height: 40ex;
+ margin: 2ex 0px;
+}