@@ -29,14 +29,15 @@ describe("pat-dependshandler", function () {
29
29
} ) ;
30
30
} ) ;
31
31
32
- describe ( "_findInput " , function ( ) {
32
+ describe ( "_findInputs " , function ( ) {
33
33
it ( "no input, nothing found" , function ( ) {
34
34
document . body . innerHTML = `
35
35
<div id="lab"></div>
36
36
` ;
37
37
const lab = document . getElementById ( "lab" ) ;
38
38
const handler = new DependsHandler ( lab , "foo" ) ;
39
- expect ( handler . _findInput ( "foo" ) ) . toBe ( null ) ;
39
+
40
+ expect ( handler . _findInputs ( "foo" ) . length ) . toBe ( 0 ) ;
40
41
} ) ;
41
42
42
43
it ( "find input by name" , function ( ) {
@@ -48,7 +49,9 @@ describe("pat-dependshandler", function () {
48
49
const lab = document . getElementById ( "lab" ) ;
49
50
const foo = document . querySelector ( "[name=foo]" ) ;
50
51
const handler = new DependsHandler ( lab , "foo" ) ;
51
- expect ( handler . _findInput ( "foo" ) ) . toBe ( foo ) ;
52
+
53
+ expect ( handler . _findInputs ( "foo" ) . length ) . toBe ( 1 ) ;
54
+ expect ( handler . _findInputs ( "foo" ) [ 0 ] ) . toBe ( foo ) ;
52
55
} ) ;
53
56
54
57
it ( "find input by id" , function ( ) {
@@ -61,7 +64,8 @@ describe("pat-dependshandler", function () {
61
64
const bar = document . getElementById ( "bar" ) ;
62
65
const handler = new DependsHandler ( lab , "bar" ) ;
63
66
64
- expect ( handler . _findInput ( "bar" ) ) . toBe ( bar ) ;
67
+ expect ( handler . _findInputs ( "bar" ) . length ) . toBe ( 1 ) ;
68
+ expect ( handler . _findInputs ( "bar" ) [ 0 ] ) . toBe ( bar ) ;
65
69
} ) ;
66
70
67
71
it ( "Restrict searches to current form" , function ( ) {
@@ -76,7 +80,25 @@ describe("pat-dependshandler", function () {
76
80
const foo1 = document . getElementById ( "foo1" ) ;
77
81
const handler = new DependsHandler ( lab , "foo" ) ;
78
82
79
- expect ( handler . _findInput ( "foo" ) ) . toBe ( foo1 ) ;
83
+ expect ( handler . _findInputs ( "foo" ) . length ) . toBe ( 1 ) ;
84
+ expect ( handler . _findInputs ( "foo" ) [ 0 ] ) . toBe ( foo1 ) ;
85
+ } ) ;
86
+
87
+ it ( "find multiple inputs of the same name, e.g. for radio buttons" , function ( ) {
88
+ document . body . innerHTML = `
89
+ <div id="lab">
90
+ <input type="radio" name="foo:list"/>
91
+ <input type="radio" name="foo:list"/>
92
+ <input type="radio" name="foo:list"/>
93
+ </div>
94
+ ` ;
95
+ const lab = document . getElementById ( "lab" ) ;
96
+ const foos = document . querySelectorAll ( "[name='foo:list']" ) ;
97
+ const handler = new DependsHandler ( lab , "foo:list" ) ;
98
+ expect ( handler . _findInputs ( "foo:list" ) . length ) . toBe ( 3 ) ;
99
+ expect ( handler . _findInputs ( "foo:list" ) [ 0 ] ) . toBe ( foos [ 0 ] ) ;
100
+ expect ( handler . _findInputs ( "foo:list" ) [ 1 ] ) . toBe ( foos [ 1 ] ) ;
101
+ expect ( handler . _findInputs ( "foo:list" ) [ 2 ] ) . toBe ( foos [ 2 ] ) ;
80
102
} ) ;
81
103
} ) ;
82
104
@@ -128,6 +150,37 @@ describe("pat-dependshandler", function () {
128
150
129
151
expect ( handler . _getValue ( "foo" ) ) . toBe ( "bar" ) ;
130
152
} ) ;
153
+
154
+ it ( "Returns the value of the checked radio buttons in a list of multiple radio buttons." , function ( ) {
155
+ document . body . innerHTML = `
156
+ <div id="lab">
157
+ <input type="radio" name="foo:list" value="bar"/>
158
+ <input type="radio" name="foo:list" value="baz"/>
159
+ <input type="radio" name="foo:list" value="fuzz" checked/>
160
+ <input type="radio" name="foo:list" value="nuzz"/>
161
+ </div>
162
+ ` ;
163
+ const lab = document . getElementById ( "lab" ) ;
164
+ const handler = new DependsHandler ( lab , "foo:list" ) ;
165
+
166
+ expect ( handler . _getValue ( "foo:list" ) ) . toBe ( "fuzz" ) ;
167
+ } ) ;
168
+
169
+ it ( "Returns no value in a list of multiple radio buttons of no one is checked." , function ( ) {
170
+ document . body . innerHTML = `
171
+ <div id="lab">
172
+ <input type="radio" name="foo:list" value="bar"/>
173
+ <input type="radio" name="foo:list" value="baz"/>
174
+ <input type="radio" name="foo:list" value="fuzz"/>
175
+ <input type="radio" name="foo:list" value="nuzz"/>
176
+ </div>
177
+ ` ;
178
+ const lab = document . getElementById ( "lab" ) ;
179
+ const handler = new DependsHandler ( lab , "foo:list" ) ;
180
+
181
+ expect ( handler . _getValue ( "foo:list" ) ) . toBe ( null ) ;
182
+ } ) ;
183
+
131
184
} ) ;
132
185
133
186
describe ( "getAllInputs" , function ( ) {
0 commit comments