Skip to content

Commit 4c6f94d

Browse files
committed
Functional tests for #177
1 parent 295efae commit 4c6f94d

File tree

6 files changed

+207
-41
lines changed

6 files changed

+207
-41
lines changed

grails-app/assets/javascripts/forms.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ function orEmptyArray(v) {
772772
if (_.isArray(val)) {
773773
selectedSoFar = selectedSoFar.concat(val);
774774
}
775-
else {
775+
else if (val != null) {
776776
selectedSoFar.push(val);
777777
}
778778
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"modelName": "Constraints example",
3+
"dataModel": [
4+
{
5+
"dataType": "number",
6+
"name": "number1"
7+
},
8+
{
9+
"dataType": "text",
10+
"name": "notes"
11+
},
12+
{
13+
"dataType": "list",
14+
"name": "list",
15+
"columns": [
16+
{
17+
"name": "value1",
18+
"dataType": "text"
19+
},
20+
{
21+
"name": "nestedList",
22+
"dataType": "list",
23+
"columns": [
24+
{
25+
"name": "value2",
26+
"dataType": "text",
27+
"constraints": {
28+
"type": "computed",
29+
"excludePath": "list.nestedList.value2",
30+
"default": [
31+
"c1",
32+
"c2",
33+
"c3",
34+
"c4"
35+
]
36+
}
37+
},
38+
{
39+
"name": "value3",
40+
"dataType": "stringList",
41+
"constraints": {
42+
"type": "computed",
43+
"includePath": "list.nestedList.value2",
44+
"default": ["Default value"]
45+
}
46+
}
47+
]
48+
}
49+
]
50+
}
51+
],
52+
"viewModel": [
53+
{
54+
"type": "row",
55+
"items": [
56+
{
57+
"type": "number",
58+
"source": "number1",
59+
"preLabel": "number1"
60+
}
61+
]
62+
},
63+
{
64+
"type": "row",
65+
"items": [
66+
{
67+
"type": "textarea",
68+
"source": "notes",
69+
"preLabel": "notes"
70+
}
71+
]
72+
},
73+
{
74+
"type": "repeat",
75+
"source": "list",
76+
"userAddedRows": true,
77+
"items": [
78+
{
79+
"type": "row",
80+
"items": [
81+
{
82+
"preLabel": "Value1",
83+
"type": "selectOne",
84+
"source": "value1"
85+
}
86+
]
87+
},
88+
{
89+
"type": "table",
90+
"source": "nestedList",
91+
"userAddedRows": true,
92+
"columns": [
93+
{
94+
"type": "selectOne",
95+
"title": "Value 2",
96+
"source": "value2"
97+
},
98+
{
99+
"type": "selectMany",
100+
"title": "Value 3",
101+
"source": "value3"
102+
}
103+
]
104+
}
105+
]
106+
}
107+
]
108+
}

package-lock.json

+33-39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@turf/convex": "^6.0.2",
1616
"@turf/length": "^6.0.2",
1717
"@turf/simplify": "^5.1.5",
18-
"chromedriver": "108.0.0",
18+
"chromedriver": "110.0.0",
1919
"geojson2svg": "^1.2.3",
2020
"handlebars": "^4.7.7",
2121
"jasmine-ajax": "^3.4.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package au.org.ala.ecodata.forms
2+
3+
import geb.module.Checkbox
4+
import geb.module.Select
5+
import geb.spock.GebReportingSpec
6+
import grails.testing.mixin.integration.Integration
7+
import pages.PreviewPage
8+
9+
@Integration
10+
class ConstraintsSpec extends GebReportingSpec {
11+
12+
def "Constraints can be specified such that each constraint may be selected only once on a form"() {
13+
when:
14+
to ([name:'constraintsExample', data:'none'], PreviewPage)
15+
16+
then:
17+
title == "Preview Constraints example"
18+
page.model != null
19+
20+
when: "We first enter the page, the select configured as one value per form has all constraints available"
21+
def selectValue2 = page.findFieldByModelName("value2").module(Select)
22+
23+
then:
24+
selectValue2.find("option")*.value() == ['', 'c1', 'c2', 'c3', 'c4']
25+
26+
when: "We select a value from a value1 select"
27+
selectValue2.selected = 'c2'
28+
page.addTableRow("nestedList")
29+
def value2List = page.findFieldByModelName("value2")
30+
31+
then: "that value should be unavailable for other instances of value1"
32+
value2List[1].find("option")*.value() == ['', 'c1', 'c3', 'c4']
33+
34+
}
35+
36+
def "Constraints can be specified such that they take their values from selections of other fields "() {
37+
when:
38+
to ([name:'constraintsExample', data:'none'], PreviewPage)
39+
40+
then:
41+
title == "Preview Constraints example"
42+
page.model != null
43+
44+
when: "We first enter the page, the checkboxes configured to obtain options from value2 will have only the default"
45+
def checkboxValue3 = $("[name=value3-0]").module(Checkbox)
46+
47+
then:
48+
checkboxValue3.attr('value') == "Default value"
49+
!checkboxValue3.checked
50+
51+
when: "We select something from value2"
52+
def selectValue2 = page.findFieldByModelName("value2").module(Select)
53+
selectValue2.selected = 'c3'
54+
55+
then: "That value becomes available for selection in our field"
56+
def checkboxValue3Number2 = $("[name='value3-0']")
57+
checkboxValue3Number2*.attr('value') == ['Default value', 'c3']
58+
59+
}
60+
}

src/integration-test/groovy/pages/PreviewPage.groovy

+4
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,8 @@ class PreviewPage extends Page {
9797
}
9898
}
9999

100+
void addTableRow(String modelName) {
101+
$("button[data-bind*='click:"+modelName+".addRow']").click()
102+
}
103+
100104
}

0 commit comments

Comments
 (0)