Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 03c876c

Browse files
committed
Getting status of input to be valid or not
1 parent e27f17c commit 03c876c

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-nice-input-password",
3-
"version": "2.0.3",
3+
"version": "2.1.0",
44
"description": "React input password component",
55
"main": "dist/react-nice-input-password.js",
66
"style": "dist/react-nice-input-password.css",

src/NiceInputPassword.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class NiceInputPassword extends React.Component {
7878
this.props.onChange({
7979
name: this.props.name,
8080
value: target.value,
81+
isValid: this.state.levels.filter(level => level.isValid).length > 0,
8182
});
8283

8384
this.setState({

src/NiceInputPassword.test.jsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,43 @@ describe('components', () => {
309309
expect(markers[0].className).toBe('green');
310310
});
311311

312-
it('calls onChange handler', () => {
312+
it('calls onChange handler and return valid', () => {
313313
const onChange = jest.fn();
314314
const div = document.createElement('div');
315315
render(<NiceInputPassword
316316
label="myLabel"
317317
name="myName"
318-
value=""
318+
value="a"
319+
securityLevels={[
320+
{
321+
descriptionLabel: 'Sample 1',
322+
validator: () => true,
323+
},
324+
]}
325+
onChange={onChange}
326+
/>, div);
327+
328+
const input = div.querySelector('#myName');
329+
input.value = 'newValue';
330+
ReactTestUtils.Simulate.change(input);
331+
332+
expect(onChange).toHaveBeenCalled();
333+
expect(onChange.mock.calls[0][0].isValid).toBe(true);
334+
});
335+
336+
it('calls onChange handler and return not valid', () => {
337+
const onChange = jest.fn();
338+
const div = document.createElement('div');
339+
render(<NiceInputPassword
340+
label="myLabel"
341+
name="myName"
342+
value="a"
343+
securityLevels={[
344+
{
345+
descriptionLabel: 'Sample 1',
346+
validator: () => false,
347+
},
348+
]}
319349
onChange={onChange}
320350
/>, div);
321351

@@ -324,6 +354,7 @@ describe('components', () => {
324354
ReactTestUtils.Simulate.change(input);
325355

326356
expect(onChange).toHaveBeenCalled();
357+
expect(onChange.mock.calls[0][0].isValid).toBe(false);
327358
});
328359
});
329360
});

0 commit comments

Comments
 (0)