@@ -10,7 +10,7 @@ Vue.component("AbstractField", AbstractField);
10
10
let el , vm , field ;
11
11
12
12
function createField ( test , schema = { } , model = null , disabled = false , options ) {
13
- let elm = document . createElement ( "div" ) ;
13
+ let elm = document . createElement ( "div" ) ;
14
14
15
15
vm = new Vue ( {
16
16
// eslint-disable-next-line quotes
@@ -55,16 +55,16 @@ describe("abstractField.vue", function() {
55
55
} ) ;
56
56
57
57
} ) ;
58
-
58
+
59
59
describe ( "check nested value" , ( ) => {
60
60
let schema = {
61
61
type : "text" ,
62
62
label : "Name" ,
63
63
model : "user.name"
64
64
} ;
65
- let model = {
65
+ let model = {
66
66
user : {
67
- name : "John Doe"
67
+ name : "John Doe"
68
68
}
69
69
} ;
70
70
@@ -90,7 +90,7 @@ describe("abstractField.vue", function() {
90
90
label : "Name" ,
91
91
model : "user.name.first"
92
92
} ;
93
- let model = {
93
+ let model = {
94
94
user : {
95
95
}
96
96
} ;
@@ -169,7 +169,7 @@ describe("abstractField.vue", function() {
169
169
expect ( model . name ) . to . be . equal ( "!!Foo Bar!!" ) ;
170
170
} ) ;
171
171
172
- } ) ;
172
+ } ) ;
173
173
174
174
describe ( "check schema onChanged event" , ( ) => {
175
175
let schema = {
@@ -194,12 +194,12 @@ describe("abstractField.vue", function() {
194
194
} ) ;
195
195
} ) ;
196
196
197
- } ) ;
197
+ } ) ;
198
198
199
199
describe ( "check validateAfterChanged option" , ( ) => {
200
200
let schema = {
201
- type : "text" ,
202
- label : "Name" ,
201
+ type : "text" ,
202
+ label : "Name" ,
203
203
model : "name"
204
204
} ;
205
205
@@ -230,13 +230,13 @@ describe("abstractField.vue", function() {
230
230
} ) ;
231
231
} ) ;
232
232
233
- } ) ;
233
+ } ) ;
234
234
235
235
describe ( "check validate function with one validator" , ( ) => {
236
236
let schema = {
237
- type : "text" ,
238
- label : "Name" ,
239
- model : "name" ,
237
+ type : "text" ,
238
+ label : "Name" ,
239
+ model : "name" ,
240
240
validator : sinon . spy ( )
241
241
} ;
242
242
@@ -253,13 +253,13 @@ describe("abstractField.vue", function() {
253
253
expect ( schema . validator . calledWith ( field . value , schema , model ) ) . to . be . true ;
254
254
} ) ;
255
255
256
- } ) ;
256
+ } ) ;
257
257
258
258
describe ( "check validate function if field is disabled" , ( ) => {
259
259
let schema = {
260
- type : "text" ,
261
- label : "Name" ,
262
- model : "name" ,
260
+ type : "text" ,
261
+ label : "Name" ,
262
+ model : "name" ,
263
263
validator : sinon . spy ( )
264
264
} ;
265
265
@@ -275,13 +275,13 @@ describe("abstractField.vue", function() {
275
275
expect ( schema . validator . callCount ) . to . be . equal ( 0 ) ;
276
276
} ) ;
277
277
278
- } ) ;
278
+ } ) ;
279
279
280
280
describe ( "check validate function if field is readonly" , ( ) => {
281
281
let schema = {
282
- type : "text" ,
283
- label : "Name" ,
284
- model : "name" ,
282
+ type : "text" ,
283
+ label : "Name" ,
284
+ model : "name" ,
285
285
readonly : true ,
286
286
validator : sinon . spy ( )
287
287
} ;
@@ -298,15 +298,15 @@ describe("abstractField.vue", function() {
298
298
expect ( schema . validator . callCount ) . to . be . equal ( 0 ) ;
299
299
} ) ;
300
300
301
- } ) ;
301
+ } ) ;
302
302
303
303
describe ( "check validate function with validator array" , ( ) => {
304
304
let spy1 = sinon . spy ( ) ;
305
305
let spy2 = sinon . spy ( ) ;
306
306
let schema = {
307
- type : "text" ,
308
- label : "Name" ,
309
- model : "name" ,
307
+ type : "text" ,
308
+ label : "Name" ,
309
+ model : "name" ,
310
310
validator : [ spy1 , spy2 ]
311
311
} ;
312
312
@@ -355,7 +355,7 @@ describe("abstractField.vue", function() {
355
355
expect ( schema . onValidated . calledWith ( model , field . errors , schema ) ) . to . be . true ;
356
356
} ) ;
357
357
358
- } ) ;
358
+ } ) ;
359
359
360
360
describe ( "check schema onValidated event" , ( ) => {
361
361
let schema = {
@@ -369,7 +369,7 @@ describe("abstractField.vue", function() {
369
369
let onValidated = sinon . spy ( ) ;
370
370
371
371
beforeEach ( ( ) => {
372
- let elm = document . createElement ( "div" ) ;
372
+ let elm = document . createElement ( "div" ) ;
373
373
374
374
vm = new Vue ( {
375
375
// eslint-disable-next-line quotes
@@ -384,7 +384,7 @@ describe("abstractField.vue", function() {
384
384
} ) . $mount ( elm ) ;
385
385
el = vm . $el ;
386
386
387
- field = vm . $refs . field ;
387
+ field = vm . $refs . field ;
388
388
} ) ;
389
389
390
390
it ( "should return empty array" , ( ) => {
@@ -448,6 +448,36 @@ describe("abstractField.vue", function() {
448
448
expect ( field . errors [ 0 ] ) . to . be . equal ( "Validation error!" ) ;
449
449
} ) ;
450
450
451
- } ) ;
451
+ } ) ;
452
+
453
+ describe ( "check getFieldID function" , ( ) => {
454
+
455
+ let schema = {
456
+ type : "text" ,
457
+ label : "First Name" ,
458
+ model : "user__model" ,
459
+ inputName : "input_name"
460
+ } ;
461
+ let model = { } ;
462
+
463
+ before ( ( ) => {
464
+ createField ( this , schema , model ) ;
465
+ } ) ;
466
+
467
+ it ( "should return slugified inputName, if available" , ( ) => {
468
+ expect ( field . getFieldID ( schema ) ) . to . be . equal ( "input-name" ) ;
469
+ } ) ;
470
+
471
+ it ( "should return slugified label, if no inputName" , ( ) => {
472
+ delete ( schema . inputName ) ;
473
+ expect ( field . getFieldID ( schema ) ) . to . be . equal ( "first-name" ) ;
474
+ } ) ;
475
+
476
+ it ( "should return slugified model name, if no inputName or label" , ( ) => {
477
+ delete ( schema . label ) ;
478
+ expect ( field . getFieldID ( schema ) ) . to . be . equal ( "user-model" ) ;
479
+ } ) ;
480
+
481
+ } ) ;
452
482
453
- } ) ;
483
+ } ) ;
0 commit comments