Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#269): constraints which are cleared by clicking next #270

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/form-host.dev.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cht-conf-test-harness",
"version": "5.0.1",
"version": "5.0.2",
"description": "Test Framework for CHT Projects",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions src/form-host/form-filler.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ const nextPage = async () => {
const currentPageIndex = getPages().indexOf(getCurrentPage());
const nextButton = $('button.next-page');
if(nextButton.is(':hidden')) {
const submitButton = $('button.submit');
if (!submitButton.is(':hidden')) {
// revalidate constraints before checking errors
submitButton.click();
}

return !getValidationErrors().length;
}

Expand All @@ -299,6 +305,7 @@ const nextPage = async () => {
observer.disconnect();
return resolve(true);
}

if(getValidationErrors().length) {
observer.disconnect();
return resolve(false);
Expand Down
7 changes: 6 additions & 1 deletion test/app-forms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe('forms that have caused bugs', () => {
it('#234 - datetime field fails enketo validation', async () => {
const result = await harness.fillForm('bug_234', ['2023-01-01 x']);
expect(result.errors).to.not.be.empty;
expect(result.errors[1].msg).to.eq('enketo.constraint.required');
expect(result.errors[0].msg).to.eq('enketo.constraint.required');
});

it('#249 - time field with correct input format', async () => {
Expand Down Expand Up @@ -358,4 +358,9 @@ describe('forms that have caused bugs', () => {
expect(result.errors).to.be.empty;
expect(result.report.fields.fp_follow_up.display_is_muted).to.eq(actual);
});

it('#269 - submit before checking for errors', async () => {
const result = await harness.fillForm('bug_269', ['1', '1']);
expect(result.errors).to.be.empty;
});
});
Binary file added test/collateral/forms/app/bug_269.xlsx
Binary file not shown.
78 changes: 78 additions & 0 deletions test/collateral/forms/app/bug_269.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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" xmlns:orx="http://openrosa.org/xforms">
<h:head>
<h:title>U5 Assessment</h:title>
<model>
<instance>
<bug_123 id="u5_assessment" prefix="J1!u5_assessment!" delimiter="#" version="2022-09-01 00:00:00">
<inputs>
<meta>
<location>
<lat/>
<long/>
<error/>
<message/>
</location>
</meta>
<source>user</source>
<source_id/>
</inputs>
<r_sum/>
<reproducing>
<first/>
<second/>
</reproducing>
<meta tag="hidden">
<instanceID/>
</meta>
</bug_123>
</instance>
<instance id="contact-summary"/>
<bind nodeset="/bug_123/inputs" relevant="./source = 'user'"/>
<bind nodeset="/bug_123/inputs/source" type="string"/>
<bind nodeset="/bug_123/inputs/source_id" type="string"/>
<bind nodeset="/bug_123/r_sum" type="string" calculate="int( /bug_123/reproducing/first )+int( /bug_123/reproducing/second )"/>
<bind nodeset="/bug_123/reproducing/first" type="select1" constraint="int( /bug_123/r_sum ) = 2" required="true()" jr:constraintMsg="Sum to Two"/>
<bind nodeset="/bug_123/reproducing/second" type="select1" constraint="int( /bug_123/r_sum ) = 2" required="true()" jr:constraintMsg="Sum to Two"/>
<bind nodeset="/bug_123/meta/instanceID" type="string" readonly="true()" calculate="concat('uuid:', uuid())"/>
</model>
</h:head>
<h:body class="pages">
<group ref="/bug_123/inputs">
<label>Inputs</label>
</group>
<group appearance="field-list" ref="/bug_123/reproducing">
<label>Reproducing Bug</label>
<select1 ref="/bug_123/reproducing/first">
<label>Value One</label>
<item>
<label>Zero</label>
<value>0</value>
</item>
<item>
<label>One</label>
<value>1</value>
</item>
<item>
<label>Two</label>
<value>2</value>
</item>
</select1>
<select1 ref="/bug_123/reproducing/second">
<label>Value Two</label>
<item>
<label>Zero</label>
<value>0</value>
</item>
<item>
<label>One</label>
<value>1</value>
</item>
<item>
<label>Two</label>
<value>2</value>
</item>
</select1>
</group>
</h:body>
</h:html>
Loading