Skip to content

Commit

Permalink
- More tests. Fixed an error on number checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Xiao committed Aug 23, 2019
1 parent 20f5dcb commit 03f7662
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 34 deletions.
1 change: 1 addition & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ class Index extends Component {
name: 'Name', // Optional.[String].Default: "". To display in the Error message. i.e Please enter your ${name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
type: 'number',
// type: 'string', // Optional.[String].Default: "string". Validation type, options are ['string', 'number', 'alphanumeric', 'alpha'].
// numberType: 'decimal', // Optional.[String].Default: "decimal". Validation number type, options are ['decimal', 'int']. Handy when the validation type is number.
// showMsg: true, // Optional.[Bool].Default: true. To determin display the error message or not.
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ var component = function component(_ref) {
break;
}

if (_validator["default"][type](internalValue)) {
if (_validator["default"][type](internalValue, null, null)) {
_context.next = 43;
break;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/components/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ var empty = function empty(v) {
return v.replace(/\s/g, '').length ? false : true;
};

var number = function number(v) {
var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 999999999999;
var number = function number(v, min, max) {
if (min === null && max === null) {
return true;
}

if (!isNumeric(v)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/react-inputs-validation.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/react-inputs-validation.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/react-inputs-validation.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/react-inputs-validation.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-inputs-validation",
"version": "3.4.2",
"version": "3.4.3",
"description": "React form input validation components",
"main": "index.js",
"repository": {
Expand Down
22 changes: 0 additions & 22 deletions src/__tests__/Textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,28 +800,6 @@ describe('Textbox component', () => {
expect(wrapper.find(`.${MSG_CLASS_IDENTITIFIER}`).length).toEqual(0);
});

it('[Number invalid]: Should msgHtml be appeared', () => {
const wrapper = mount(
<Textbox
value="foobar"
onBlur={() => {}}
validationOption={{
locale: 'en-US',
type: 'number',
name: '',
check: true,
showMsg: true,
required: true,
msgOnError: '',
}}
/>,
);
const $input = wrapper.find(INPUT);
$input.simulate('focus');
$input.simulate('blur');
expect(wrapper.find(`.${MSG_CLASS_IDENTITIFIER}`).length).toEqual(1);
});

it('[Number autoFormatNumber]: Should .5 to be 0.5', () => {
let value = '';
const wrapper = mount(
Expand Down
14 changes: 13 additions & 1 deletion src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ describe('utils', () => {
it('[toCamelCase("foo bar")(true)]: Should return the camelCase: "FooBar"', () => {
expect(utils.toCamelCase('foo bar')(true)).equal('FooBar');
});
});
it('[getRandomId()]: Should return string', () => {
expect(utils.getRandomId()).to.be.a('string');
});
it('[getNumeric("a1")]: Should return 1', () => {
expect(utils.getNumeric('a1')).equal('1');
});
it('[getAlphanumeric("@a1")]: Should return 1', () => {
expect(utils.getAlphanumeric('@a1')).equal('a1');
});
it('[getAlpha("a1")]: Should return 1', () => {
expect(utils.getAlpha('a1')).equal('a');
});
});
2 changes: 1 addition & 1 deletion src/js/Inputs/Textbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const component: React.FC<Props> = ({
}
}
if (type === VALIDATE_OPTION_TYPE_LIST[1]) {
if (!validator[type](internalValue)) {
if (!validator[type](internalValue, null, null)) {
handleCheckEnd(true, msg.invalid(nameText));
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/js/Inputs/validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const empty = (v: string) => (v.replace(/\s/g, '').length ? false : true);
const number = (v: number, min: number = 0, max: number = 999999999999) => {
const number = (v: number, min: any, max: any) => {
if (min === null && max === null){
return true
}
if (!isNumeric(v)) {
return false;
}
Expand Down

0 comments on commit 03f7662

Please sign in to comment.