Skip to content

Commit

Permalink
cascading selections inside repeats fixed, closes SEL-Columbia#421 (&…
Browse files Browse the repository at this point in the history
… refactored some older tests)
  • Loading branch information
Martijn van de Rijdt committed Apr 10, 2013
1 parent 099c456 commit 44a9ecd
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 40 deletions.
1 change: 1 addition & 0 deletions Code_Igniter/application/controllers/unit_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function generate_js_test_form_mocks()
'issue208.xml',
'cascading_mixture_itext_noitext.xml',
'new_cascading_selections.xml',
'new_cascading_selections_inside_repeats.xml',
'nested_repeats.xml',
'calcs.xml',
'readonly.xml'
Expand Down
Binary file not shown.
280 changes: 280 additions & 0 deletions devinfo/Forms/new_cascading_selections_inside_repeats.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
<?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>cascading selections inside repeats</h:title>
<model>
<itext>
<translation lang="Dutch">
<text id="static_instance-cities-3">
<value>De Engelen</value>
</text>
<text id="static_instance-cities-2">
<value>Nieuw Amsterdam</value>
</text>
<text id="static_instance-cities-1">
<value>Denver</value>
</text>
<text id="static_instance-cities-0">
<value>Amsterdam</value>
</text>
<text id="static_instance-neighborhoods-2">
<value>Goeie lucht</value>
</text>
<text id="static_instance-cities-5">
<value>Dronten</value>
</text>
<text id="static_instance-cities-4">
<value>Rotterdam</value>
</text>
<text id="/new_cascading_selections_inside_repeats/group1/country/usa:label">
<value>Verenigde Staten</value>
</text>
<text id="static_instance-neighborhoods-5">
<value>De haven</value>
</text>
<text id="static_instance-neighborhoods-6">
<value>De Dam</value>
</text>
<text id="static_instance-neighborhoods-7">
<value>'t Centrum</value>
</text>
<text id="static_instance-neighborhoods-0">
<value>Van der Bronk Plantage</value>
</text>
<text id="static_instance-neighborhoods-1">
<value>Haarlem</value>
</text>
<text id="/new_cascading_selections_inside_repeats/group1/country/nl:label">
<value>Nederland</value>
</text>
<text id="static_instance-neighborhoods-3">
<value>Westerpark</value>
</text>
<text id="static_instance-countries-1">
<value>Verenigde Staten</value>
</text>
<text id="static_instance-countries-0">
<value>Nederland</value>
</text>
<text id="static_instance-neighborhoods-8">
<value>De haven</value>
</text>
<text id="static_instance-neighborhoods-4">
<value>Park Heuvel</value>
</text>
</translation>
<translation lang="English">
<text id="static_instance-cities-3">
<value>Los Angeles</value>
</text>
<text id="static_instance-cities-2">
<value>New York City</value>
</text>
<text id="static_instance-cities-1">
<value>Denver</value>
</text>
<text id="static_instance-cities-0">
<value>Amsterdam</value>
</text>
<text id="static_instance-neighborhoods-2">
<value>Bel Air</value>
</text>
<text id="static_instance-cities-5">
<value>Dronten</value>
</text>
<text id="static_instance-cities-4">
<value>Rotterdam</value>
</text>
<text id="/new_cascading_selections_inside_repeats/group1/country/usa:label">
<value>United States</value>
</text>
<text id="static_instance-neighborhoods-5">
<value>Harbor</value>
</text>
<text id="static_instance-neighborhoods-6">
<value>Dam</value>
</text>
<text id="static_instance-neighborhoods-7">
<value>Downtown</value>
</text>
<text id="static_instance-neighborhoods-0">
<value>Bronx</value>
</text>
<text id="static_instance-neighborhoods-1">
<value>Harlem</value>
</text>
<text id="/new_cascading_selections_inside_repeats/group1/country/nl:label">
<value>The Netherlands</value>
</text>
<text id="static_instance-neighborhoods-3">
<value>Westerpark</value>
</text>
<text id="static_instance-countries-1">
<value>United States</value>
</text>
<text id="static_instance-countries-0">
<value>The Netherlands</value>
</text>
<text id="static_instance-neighborhoods-8">
<value>Harbor</value>
</text>
<text id="static_instance-neighborhoods-4">
<value>Park Hill</value>
</text>
</translation>
</itext>
<instance>
<new_cascading_selections_inside_repeats id="cascading_select_inside_repeats">
<group1 jr:template="">
<country/>
<city/>
<neighborhood/>
</group1>
<meta>
<instanceID/>
</meta>
</new_cascading_selections_inside_repeats>
</instance>
<instance id="cities">
<root>
<item>
<itextId>static_instance-cities-0</itextId>
<country>nl</country>
<name>ams</name>
</item>
<item>
<itextId>static_instance-cities-1</itextId>
<country>usa</country>
<name>den</name>
</item>
<item>
<itextId>static_instance-cities-2</itextId>
<country>usa</country>
<name>nyc</name>
</item>
<item>
<itextId>static_instance-cities-3</itextId>
<country>usa</country>
<name>la</name>
</item>
<item>
<itextId>static_instance-cities-4</itextId>
<country>nl</country>
<name>rot</name>
</item>
<item>
<itextId>static_instance-cities-5</itextId>
<country>nl</country>
<name>dro</name>
</item>
</root>
</instance>
<instance id="neighborhoods">
<root>
<item>
<itextId>static_instance-neighborhoods-0</itextId>
<city>nyc</city>
<country>usa</country>
<name>bronx</name>
</item>
<item>
<itextId>static_instance-neighborhoods-1</itextId>
<city>nyc</city>
<country>usa</country>
<name>harlem</name>
</item>
<item>
<itextId>static_instance-neighborhoods-2</itextId>
<city>la</city>
<country>usa</country>
<name>belair</name>
</item>
<item>
<itextId>static_instance-neighborhoods-3</itextId>
<city>ams</city>
<country>nl</country>
<name>wes</name>
</item>
<item>
<itextId>static_instance-neighborhoods-4</itextId>
<city>den</city>
<country>usa</country>
<name>parkhill</name>
</item>
<item>
<itextId>static_instance-neighborhoods-5</itextId>
<city>rot</city>
<country>nl</country>
<name>haven</name>
</item>
<item>
<itextId>static_instance-neighborhoods-6</itextId>
<city>ams</city>
<country>nl</country>
<name>dam</name>
</item>
<item>
<itextId>static_instance-neighborhoods-7</itextId>
<city>rot</city>
<country>nl</country>
<name>centrum</name>
</item>
<item>
<itextId>static_instance-neighborhoods-8</itextId>
<city>dro</city>
<country>nl</country>
<name>haven</name>
</item>
</root>
</instance>
<instance id="countries">
<root>
<item>
<itextId>static_instance-countries-0</itextId>
<name>nl</name>
</item>
<item>
<itextId>static_instance-countries-1</itextId>
<name>usa</name>
</item>
</root>
</instance>
<bind nodeset="/new_cascading_selections_inside_repeats/group1/country" type="select1"/>
<bind nodeset="/new_cascading_selections_inside_repeats/group1/city" type="select1"/>
<bind nodeset="/new_cascading_selections_inside_repeats/group1/neighborhood" type="select1"/>
<bind calculate="concat('uuid:', uuid())" nodeset="/new_cascading_selections_inside_repeats/meta/instanceID" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<group ref="/new_cascading_selections_inside_repeats/group1">
<label>Cascading Selects with Radio Buttons</label>
<repeat nodeset="/new_cascading_selections_inside_repeats/group1">
<select1 ref="/new_cascading_selections_inside_repeats/group1/country">
<label>Country</label>
<item>
<label ref="jr:itext('/new_cascading_selections_inside_repeats/group1/country/nl:label')"/>
<value>nl</value>
</item>
<item>
<label ref="jr:itext('/new_cascading_selections_inside_repeats/group1/country/usa:label')"/>
<value>usa</value>
</item>
</select1>
<select1 ref="/new_cascading_selections_inside_repeats/group1/city">
<label>City</label>
<itemset nodeset="instance('cities')/root/item[country= /new_cascading_selections_inside_repeats/group1/country ]">
<value ref="name"/>
<label ref="jr:itext(itextId)"/>
</itemset>
</select1>
<select1 ref="/new_cascading_selections_inside_repeats/group1/neighborhood">
<label>Neighborhood</label>
<itemset nodeset="instance('neighborhoods')/root/item[country= /new_cascading_selections_inside_repeats/group1/country and city= /new_cascading_selections_inside_repeats/group1/city ]">
<value ref="name"/>
<label ref="jr:itext(itextId)"/>
</itemset>
</select1>
</repeat>
</group>
</h:body>
</h:html>
28 changes: 0 additions & 28 deletions js_tests/mocks/form.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,34 +359,6 @@ var formStr6 =
'</label>'+
'</form>';

var dataStr8 =
'<model>'+
'<instance>'+
'<new_cascading_select id="cascading_select_test">'+
'<state>colorado</state>'+
'<county/>'+
'<city>denver</city>'+
'<meta>'+
'<instanceID/>'+
'</meta>'+
'</new_cascading_select>'+
'</instance>'+
'<instance id="cities">'+
'<root>'+
'<item>'+
'<itextId>static_instance-states-0</itextId>'+
'<name>denver</name>'+
'<state>colorado</state>'+
'</item>'+
'<item>'+
'<itextId>static_instance-states-1</itextId>'+
'<name>boulder</name>'+
'<state>colorado</state>'+
'</item>'+
'</root>'+
'</instance>'+
'</model>';

var dataEditStr_nested_repeats =
'<nested_repeats id="nested_repeats">'+
'<formhub>'+
Expand Down
Empty file modified js_tests/mocks/json_drishti.mock.js
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions js_tests/mocks/transforms.mock.js

Large diffs are not rendered by default.

50 changes: 42 additions & 8 deletions js_tests/specs/form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,15 @@ describe('Itemset functionality', function(){
var form;

it('is able to address an instance by id with the instance(id)/path/to/node syntax', function(){
form = new Form('', dataStr8);
form.init();
console.debug('data:', form.getDataO().$);
expect(form.getDataO().evaluate("instance('cities')/root/item/name", "string")).toEqual('denver');
expect(form.getDataO().evaluate("instance('cities')/root/item[state=/new_cascading_select/state]/name", "string")).toEqual('denver');
expect(form.getDataO().evaluate("instance('cities')/root/item[state=/new_cascading_select/state and 1<2]", "nodes").length).toEqual(2);
expect(form.getDataO().evaluate("instance('cities')/root/item[state=/new_cascading_select/state and name=/new_cascading_select/city]", "nodes").length).toEqual(1);
//form = new Form('', dataStr8);
//form = new Form('', )
//form.init();
var dataO = getFormDataO('new_cascading_selections.xml');
console.log('data:', dataO.$.find('instance'));
expect(dataO.evaluate("instance('cities')/root/item/name", "string")).toEqual('ams');
expect(dataO.evaluate("instance('cities')/root/item[country=/new_cascading_selections/group4/country4]/name", "string")).toEqual('den');
expect(dataO.evaluate("instance('cities')/root/item[country=/new_cascading_selections/group4/country4 and 1<2]", "nodes").length).toEqual(3);
expect(dataO.evaluate("instance('cities')/root/item[country=/new_cascading_selections/group4/country4 and name=/new_cascading_selections/group4/city4]", "nodes").length).toEqual(1);
});

describe('in a cascading select using itext for all labels', function(){
Expand Down Expand Up @@ -954,7 +956,7 @@ describe('Itemset functionality', function(){
});

waitsFor(function(){return formHTMLO.itemsetUpdate.mostRecentCall.args[0] === 'state';}, 'itemsetUpdate not called!', 1000);

//select second option
runs(function(){
form.getFormO().$.find(sel2Radio+'[value="king"]')
Expand All @@ -971,5 +973,37 @@ describe('Itemset functionality', function(){
});
});
});

describe('in a clone repeat that includes a cascading select', function(){
var countrySelector = '[data-name="/new_cascading_selections_inside_repeats/group1/country"]',
citySelector = 'label:not(.itemset-template) [data-name="/new_cascading_selections_inside_repeats/group1/city"]',

form, $masterRepeat, $clonedRepeat;

beforeEach(function(){
form = loadForm('new_cascading_selections_inside_repeats.xml'),
form.init();
$masterRepeat = form.getFormO().$.find('.jr-repeat'),
//select usa in master repeat
$masterRepeat.find(countrySelector+'[value="usa"]').prop('checked', true).trigger('change');
//add repeat
$masterRepeat.find('button.repeat').click();
$clonedRepeat = form.getFormO().$.find('.jr-repeat.clone');
});

it('the itemset of the cloned repeat is correct (and not a cloned copy of the master repeat)', function(){
expect($masterRepeat.find(citySelector).length).toEqual(3);
expect($clonedRepeat.find(countrySelector+':selected').val()).toBeUndefined();
expect($clonedRepeat.find(citySelector).length).toEqual(0);
});

it('the itemset of the master repeat is not affected if the cloned is changed', function(){
$clonedRepeat.find(countrySelector+'[value="nl"]').prop('checked', true).trigger('change');
expect($masterRepeat.find(citySelector).length).toEqual(3);
expect($masterRepeat.find(citySelector).eq(0).attr('value')).toEqual('den');
expect($clonedRepeat.find(citySelector).length).toEqual(3);
expect($clonedRepeat.find(citySelector).eq(0).attr('value')).toEqual('ams');
});
});
});

Empty file modified js_tests/specs/helpers.spec.js
100644 → 100755
Empty file.
Empty file modified js_tests/utils/test_utils.js
100644 → 100755
Empty file.
Loading

0 comments on commit 44a9ecd

Please sign in to comment.