Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
changed: test XForms can now be dropped into /test/mock to use them i…
Browse files Browse the repository at this point in the history
…n tests instead of generating transformation resuls outside of enketo-core,

closes #293
  • Loading branch information
MartijnR committed Apr 1, 2016
1 parent 1bc6fb6 commit 415306b
Show file tree
Hide file tree
Showing 19 changed files with 1,803 additions and 423 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/build/js/
/build/lib/
/lib/bower-components/
/test/mock/forms.json
temp
.sass-cache
._*
Expand Down
37 changes: 34 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* jshint node:true */
/* global Promise */

/**
* When using enketo-core in your own app, you'd want to replace
* this build file with one of your own in your project root.
*/

/*jshint node:true*/
'use strict';

module.exports = function( grunt ) {
Expand Down Expand Up @@ -119,8 +120,38 @@ module.exports = function( grunt ) {
},
} );

grunt.registerTask( 'transforms', 'Creating forms.json', function( task ) {
var forms = {};
var done = this.async();
var jsonStringify = require( 'json-pretty' );
var formsJsonPath = 'test/mock/forms.json';
var xformsPaths = grunt.file.expand( {}, 'test/forms/*.xml' );
var transformer = require( 'enketo-transformer' );

xformsPaths.reduce( function( prevPromise, filePath ) {
return prevPromise.then( function() {
var xformStr = grunt.file.read( filePath );
grunt.log.writeln( 'Transforming ' + filePath + '...' );
return transformer.transform( {
xform: xformStr
} )
.then( function( result ) {
forms[ filePath.substring( filePath.lastIndexOf( '/' ) + 1 ) ] = {
html_form: result.form,
xml_model: result.model
};
} );
} );

}, Promise.resolve() )
.then( function() {
grunt.file.write( formsJsonPath, jsonStringify( forms ) );
done();
} );
} );

grunt.registerTask( 'compile', [ 'browserify', 'uglify' ] );
grunt.registerTask( 'test', [ 'jsbeautifier:test', 'jshint', 'compile', 'karma:headless' ] );
grunt.registerTask( 'test', [ 'jsbeautifier:test', 'jshint', 'compile', 'transforms', 'karma:headless' ] );
grunt.registerTask( 'style', [ 'sass' ] );
grunt.registerTask( 'server', [ 'connect:server:keepalive' ] );
grunt.registerTask( 'develop', [ 'browserify', 'concurrent:develop' ] );
Expand Down
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
"homepage": "https://enketo.org",
"version": "4.5.12",
"license": "Apache-2.0",
"os": [ "darwin", "linux" ],
"keywords": [ "enketo", "OpenRosa", "ODK", "XForms" ],
"os": [
"darwin",
"linux"
],
"keywords": [
"enketo",
"OpenRosa",
"ODK",
"XForms"
],
"repository": {
"type": "git",
"url": "https://github.com/enketo/enketo-core"
Expand All @@ -25,6 +33,7 @@
"test": "grunt test"
},
"devDependencies": {
"enketo-transformer": "*",
"grunt": "0.4.x",
"grunt-browserify": "5.0.x",
"grunt-concurrent": "2.x.x",
Expand All @@ -36,6 +45,7 @@
"grunt-karma": "0.12.x",
"grunt-sass": "1.1.x",
"jasmine-core": "2.4.x",
"json-pretty": "0.0.1",
"karma": "0.13.x",
"karma-browserify": "5.0.x",
"karma-chrome-launcher": "0.2.x",
Expand Down
27 changes: 27 additions & 0 deletions test/forms/calcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<h:head>
<h:title>calcs</h:title>
<model>
<instance>
<calcs id="calcs">
<calc1/>
<calc2/>
<cond1/>
<meta>
<instanceID/>
</meta>
</calcs>
</instance>
<bind calculate="1 + 2" nodeset="/calcs/calc1" relevant=" /calcs/cond1 = 'yes'" type="string"/>
<bind calculate="concat('1', '2')" nodeset="/calcs/calc2" type="string"/>
<bind nodeset="/calcs/cond1" type="string"/>
<bind calculate="concat('uuid:', uuid())" nodeset="/calcs/meta/instanceID" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<input ref="/calcs/cond1">
<label>enter 'yes' to make calc1 relevant</label>
</input>
</h:body>
</h:html>
49 changes: 49 additions & 0 deletions test/forms/calcs_in_repeats.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<h:head>
<h:title>calcs_in_repeats</h:title>
<model>
<instance>
<calcs_in_repeats id="calcs_in_repeats">
<formhub>
<uuid/>
</formhub>
<calc1/>
<calc2/>
<cond1/>
<rep1 jr:template="">
<num1/>
<calc3/>
</rep1>
<note1/>
<meta>
<instanceID/>
</meta>
</calcs_in_repeats>
</instance>
<bind calculate="1 + 2" nodeset="/calcs_in_repeats/calc1" relevant=" /calcs_in_repeats/cond1 = 'yes'" type="string"/>
<bind calculate="concat('1', '2')" nodeset="/calcs_in_repeats/calc2" type="string"/>
<bind nodeset="/calcs_in_repeats/cond1" type="string"/>
<bind nodeset="/calcs_in_repeats/rep1/num1" type="int"/>
<bind calculate=" /calcs_in_repeats/rep1/num1 * 20" nodeset="/calcs_in_repeats/rep1/calc3" type="string"/>
<bind nodeset="/calcs_in_repeats/note1" readonly="true()" type="string"/>
<bind calculate="concat('uuid:', uuid())" nodeset="/calcs_in_repeats/meta/instanceID" readonly="true()" type="string"/>
<bind calculate="'47eed988240249948e42aadfa6bcdb86'" nodeset="/calcs_in_repeats/formhub/uuid" type="string"/>
</model>
</h:head>
<h:body>
<input ref="/calcs_in_repeats/cond1">
<label>enter 'yes' to make calc1 relevant</label>
</input>
<group ref="/calcs_in_repeats/rep1">
<label/>
<repeat nodeset="/calcs_in_repeats/rep1">
<input ref="/calcs_in_repeats/rep1/num1">
<label>enter a number</label>
</input>
</repeat>
</group>
<input ref="/calcs_in_repeats/note1">
<label>value of num1 inside (first) repeat is: <output value=" /calcs_in_repeats/rep1/num1 "/></label></input>
</h:body>
</h:html>
175 changes: 175 additions & 0 deletions test/forms/cascading_mixture_itext_noitext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa">
<h:head>
<h:title>Cascading Triple Select Form</h:title>
<model>
<itext>
<translation lang="english">
<text id="washington">
<value>Washington State</value>
</text>
<text id="illinois">
<value>Illinois State</value>
</text>
<text id="king">
<value>King County</value>
</text>
<text id="pierce">
<value>Pierce County</value>
</text>
<text id="douglas">
<value>Douglas County</value>
</text>
<text id="cook">
<value>Cook County</value>
</text>
</translation>
<translation lang="italian">
<text id="washington">
<value>State of Washington</value>
</text>
<text id="illinois">
<value>State of Illinois</value>
</text>
<text id="king">
<value>County King</value>
</text>
<text id="pierce">
<value>County Pierce</value>
</text>
<text id="douglas">
<value>County Douglas</value>
</text>
<text id="cook">
<value>County Cook</value>
</text>
</translation>
</itext>
<instance>
<form id="CascadingTripleSelect" version="2012072301">
<state />
<county />
<city />
</form>
</instance>
<instance id="choices">
<states>
<state>
<value>washington</value>
<counties>
<county>
<value>king</value>
<cities>
<city>
<name>Seattle</name>
<value>sea</value>
</city>
<city>
<name>Redmond</name>
<value>red</value>
</city>
</cities>
</county>
<county>
<value>pierce</value>
<cities>
<city>
<name>Tacoma</name>
<value>tac</value>
</city>
<city>
<name>Puyallup</name>
<value>puy</value>
</city>
</cities>
</county>
<county>
<value>douglas</value>
<cities>
<city>
<name>Bridgeport</name>
<value>bri</value>
</city>
<city>
<name>Coulee Dam</name>
<value>cod</value>
</city>
<city>
<name>East Wenatchee</name>
<value>ewe</value>
</city>
<city>
<name>Rock Island</name>
<value>roi</value>
</city>
</cities>
</county>
</counties>
</state>
<state>
<value>illinois</value>
<counties>
<county>
<value>cook</value>
<cities>
<city>
<name>Chicago</name>
<value>chi</value>
</city>
<city>
<name>Oak Lawn</name>
<value>oal</value>
</city>
<city>
<name>Oak Forest</name>
<value>oaf</value>
</city>
</cities>
</county>
<county>
<value>douglas</value>
<cities>
<city>
<name>Arcola</name>
<value>arc</value>
</city>
<city>
<name>Tuscola</name>
<value>tus</value>
</city>
<city>
<name>Villa Grove</name>
<value>vig</value>
</city>
</cities>
</county>
</counties>
</state>
</states>
</instance>
<bind nodeset="/form/state" type="select1" />
<bind nodeset="/form/county" type="select1" />
<bind nodeset="/form/city" type="select1" />
</model>
</h:head>
<h:body>
<select1 ref="/form/state">
<itemset nodeset="instance('choices')/states/state">
<label ref="jr:itext(value)" />
<value ref="value" />
</itemset>
</select1>
<select1 ref="/form/county">
<itemset nodeset="instance('choices')/states/state[value=/form/state]/counties/county">
<label ref="jr:itext(value)" />
<value ref="value" />
</itemset>
</select1>
<select1 ref="/form/city">
<itemset nodeset="instance('choices')/states/state[value=/form/state]/counties/county[value=/form/county]/cities/city">
<label ref="name" />
<value ref="value" />
</itemset>
</select1>
</h:body>
</h:html>
Loading

0 comments on commit 415306b

Please sign in to comment.