@@ -118,22 +118,147 @@ describe('TreeViewNode.vue', () => {
118118
119119 it ( 'should have a title attribute on the node\'s text' , ( ) => {
120120 let elem = wrapper . find ( `.tree-view-node-self-text` ) . element ;
121- expect ( elem . getAttribute ( " title" ) ) . to . equal ( " My Title" ) ;
121+ expect ( elem . getAttribute ( ' title' ) ) . to . equal ( ' My Title' ) ;
122122 } ) ;
123123 } ) ;
124124
125125 describe ( 'when given a title in the model data for an input node' , ( ) => {
126126
127127 beforeEach ( ( ) => {
128128 let data = getDefaultPropsData ( ) ;
129- data . initialModel . treeNodeSpec . title = " My Title" ;
129+ data . initialModel . treeNodeSpec . title = ' My Title' ;
130130
131131 wrapper = createWrapper ( data ) ;
132132 } ) ;
133133
134134 it ( 'should have a title attribute on the node\'s label' , ( ) => {
135135 let elem = wrapper . find ( `.tree-view-node-self-label` ) . element ;
136- expect ( elem . getAttribute ( "title" ) ) . to . equal ( "My Title" ) ;
136+ expect ( elem . getAttribute ( 'title' ) ) . to . equal ( 'My Title' ) ;
137+ } ) ;
138+ } ) ;
139+
140+ describe ( 'when given a name in the model data for an input node' , ( ) => {
141+
142+ describe ( 'and it is a non-radio button input' , ( ) => {
143+
144+ describe ( 'and that name is not a string' , ( ) => {
145+
146+ beforeEach ( ( ) => {
147+ let data = getDefaultPropsData ( ) ;
148+ data . initialModel . treeNodeSpec . input . name = 42 ;
149+ wrapper = createWrapper ( data ) ;
150+ } ) ;
151+
152+ it ( 'should set the name to null' , ( ) => {
153+ expect ( wrapper . vm . model . treeNodeSpec . input . name ) . to . be . null ;
154+ } ) ;
155+ } ) ;
156+
157+ describe ( 'and that trimmed name is an empty string' , ( ) => {
158+
159+ beforeEach ( ( ) => {
160+ let data = getDefaultPropsData ( ) ;
161+ data . initialModel . treeNodeSpec . input . name = ' ' ;
162+ wrapper = createWrapper ( data ) ;
163+ } ) ;
164+
165+ it ( 'should set the name to null' , ( ) => {
166+ expect ( wrapper . vm . model . treeNodeSpec . input . name ) . to . be . null ;
167+ } ) ;
168+ } ) ;
169+ } ) ;
170+
171+ describe ( 'and it is a radio button input' , ( ) => {
172+
173+ let data ;
174+
175+ beforeEach ( ( ) => {
176+ data = getDefaultPropsData ( ) ;
177+ data . initialModel = generateNodes ( [ 'r' ] ) [ 0 ] ;
178+ } ) ;
179+
180+ describe ( 'and that name is not a string' , ( ) => {
181+
182+ beforeEach ( ( ) => {
183+ data . initialModel . treeNodeSpec . input . name = 42 ;
184+ wrapper = createWrapper ( data ) ;
185+ } ) ;
186+
187+ it ( 'should set the name to unspecifiedRadioName' , ( ) => {
188+ expect ( wrapper . vm . model . treeNodeSpec . input . name ) . to . equal ( 'unspecifiedRadioName' ) ;
189+ } ) ;
190+ } ) ;
191+
192+ describe ( 'and that trimmed name is an empty string' , ( ) => {
193+
194+ beforeEach ( ( ) => {
195+ data . initialModel . treeNodeSpec . input . name = ' ' ;
196+ wrapper = createWrapper ( data ) ;
197+ } ) ;
198+
199+ it ( 'should set the name to null' , ( ) => {
200+ expect ( wrapper . vm . model . treeNodeSpec . input . name ) . to . equal ( 'unspecifiedRadioName' ) ;
201+ } ) ;
202+ } ) ;
203+ } ) ;
204+ } ) ;
205+
206+ describe ( 'when given a value in the model data for an input node' , ( ) => {
207+
208+ describe ( 'and it is a radio button input' , ( ) => {
209+
210+ let data ;
211+
212+ beforeEach ( ( ) => {
213+ data = getDefaultPropsData ( ) ;
214+ data . initialModel = generateNodes ( [ 'r' ] ) [ 0 ] ;
215+ data . initialModel . label = 'A \'Label\' & <Thing>/ "Stuff"' ;
216+ } ) ;
217+
218+ describe ( 'and that value is not a string' , ( ) => {
219+
220+ beforeEach ( ( ) => {
221+ data . initialModel . treeNodeSpec . input . value = 42 ;
222+ wrapper = createWrapper ( data ) ;
223+ } ) ;
224+
225+ it ( 'should set the value to the label value, minus disallowed characters' , ( ) => {
226+ expect ( wrapper . vm . model . treeNodeSpec . input . value ) . to . equal ( 'ALabelThingStuff' ) ;
227+ } ) ;
228+ } ) ;
229+
230+ describe ( 'and that trimmed value is an empty string' , ( ) => {
231+
232+ beforeEach ( ( ) => {
233+ data . initialModel . treeNodeSpec . input . value = ' ' ;
234+ wrapper = createWrapper ( data ) ;
235+ } ) ;
236+
237+ it ( 'should set the value to the label value, minus disallowed characters' , ( ) => {
238+ expect ( wrapper . vm . model . treeNodeSpec . input . value ) . to . equal ( 'ALabelThingStuff' ) ;
239+ } ) ;
240+ } ) ;
241+ } ) ;
242+ } ) ;
243+
244+ describe ( 'when given an input model with no input state specified' , ( ) => {
245+
246+ beforeEach ( ( ) => {
247+ let data = getDefaultPropsData ( ) ;
248+ data . initialModel = generateNodes ( [ 'c' ] ) [ 0 ] ;
249+ data . initialModel . treeNodeSpec . state . input = null ;
250+ wrapper = createWrapper ( data ) ;
251+ } ) ;
252+
253+ it ( 'should default the disabled state to false' , ( ) => {
254+ expect ( wrapper . vm . model . treeNodeSpec . state . input . disabled ) . to . be . false ;
255+ } ) ;
256+
257+ describe ( 'and the input is a checkbox' , ( ) => {
258+
259+ it ( 'should set the value of the input to false' , ( ) => {
260+ expect ( wrapper . vm . model . treeNodeSpec . state . input . value ) . to . be . false ;
261+ } ) ;
137262 } ) ;
138263 } ) ;
139264
@@ -193,7 +318,7 @@ describe('TreeViewNode.vue', () => {
193318
194319 wrapper = createWrapper ( {
195320 ariaKeyMap : { } ,
196- initialModel : generateNodes ( [ 'esa' ] , "" , addChildCallback ) [ 0 ] ,
321+ initialModel : generateNodes ( [ 'esa' ] , '' , addChildCallback ) [ 0 ] ,
197322 modelDefaults : { } ,
198323 depth : 0 ,
199324 treeId : 'tree' ,
0 commit comments