File tree 2 files changed +47
-2
lines changed
app/code/Magento/Ui/view/base/web/js/lib/validation
dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/lib/validation 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -84,8 +84,10 @@ define([
84
84
] ,
85
85
'range-words' : [
86
86
function ( value , params ) {
87
- return utils . stripHtml ( value ) . match ( / \b \w + \b / g) . length >= params [ 0 ] &&
88
- value . match ( / b w + b / g) . length < params [ 1 ] ;
87
+ var match = utils . stripHtml ( value ) . match ( / \b \w + \b / g) || [ ] ;
88
+
89
+ return match . length >= params [ 0 ] &&
90
+ match . length <= params [ 1 ] ;
89
91
} ,
90
92
$ . mage . __ ( 'Please enter between {0} and {1} words.' )
91
93
] ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+
6
+ /* eslint-disable max-nested-callbacks */
7
+ define ( [
8
+ 'Magento_Ui/js/lib/validation/rules'
9
+ ] , function ( rules ) {
10
+ 'use strict' ;
11
+
12
+ describe ( 'Magento_Ui/js/lib/validation/rules' , function ( ) {
13
+ describe ( '"range-words" method' , function ( ) {
14
+ it ( 'Check on empty value' , function ( ) {
15
+ var value = '' ,
16
+ params = [ 1 , 3 ] ;
17
+
18
+ expect ( rules [ 'range-words' ] . handler ( value , params ) ) . toBe ( false ) ;
19
+ } ) ;
20
+
21
+ it ( 'Check on redundant words' , function ( ) {
22
+ var value = 'a b c d' ,
23
+ params = [ 1 , 3 ] ;
24
+
25
+ expect ( rules [ 'range-words' ] . handler ( value , params ) ) . toBe ( false ) ;
26
+ } ) ;
27
+
28
+ it ( 'Check with three words' , function ( ) {
29
+ var value = 'a b c' ,
30
+ params = [ 1 , 3 ] ;
31
+
32
+ expect ( rules [ 'range-words' ] . handler ( value , params ) ) . toBe ( true ) ;
33
+ } ) ;
34
+
35
+ it ( 'Check with one word' , function ( ) {
36
+ var value = 'a' ,
37
+ params = [ 1 , 3 ] ;
38
+
39
+ expect ( rules [ 'range-words' ] . handler ( value , params ) ) . toBe ( true ) ;
40
+ } ) ;
41
+ } ) ;
42
+ } ) ;
43
+ } ) ;
You can’t perform that action at this time.
0 commit comments