Skip to content

Commit

Permalink
Showing 2 changed files with 47 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js
Original file line number Diff line number Diff line change
@@ -84,8 +84,10 @@ define([
],
'range-words': [
function (value, params) {
return utils.stripHtml(value).match(/\b\w+\b/g).length >= params[0] &&
value.match(/bw+b/g).length < params[1];
var match = utils.stripHtml(value).match(/\b\w+\b/g) || [];

return match.length >= params[0] &&
match.length <= params[1];
},
$.mage.__('Please enter between {0} and {1} words.')
],
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/* eslint-disable max-nested-callbacks */
define([
'Magento_Ui/js/lib/validation/rules'
], function (rules) {
'use strict';

describe('Magento_Ui/js/lib/validation/rules', function () {
describe('"range-words" method', function () {
it('Check on empty value', function () {
var value = '',
params = [1,3];

expect(rules['range-words'].handler(value, params)).toBe(false);
});

it('Check on redundant words', function () {
var value = 'a b c d',
params = [1,3];

expect(rules['range-words'].handler(value, params)).toBe(false);
});

it('Check with three words', function () {
var value = 'a b c',
params = [1,3];

expect(rules['range-words'].handler(value, params)).toBe(true);
});

it('Check with one word', function () {
var value = 'a',
params = [1,3];

expect(rules['range-words'].handler(value, params)).toBe(true);
});
});
});
});

0 comments on commit 934818d

Please sign in to comment.