This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Initial FreeformInputWidget #48
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7ba4d3b
WIP: FreeformInputWidget
pelusanchez fac15e0
WIP: Testing.
pelusanchez dafe2d3
FreeformInputWidget first working version.
pelusanchez bb6413c
Unit testing float / int validation.
pelusanchez 4a6c7e2
Formatter pass.
pelusanchez d8a820f
Drop constraints.
pelusanchez edda311
Unnecessary prop drop
pelusanchez 667e176
Added tests for FreeformInputWidget
pelusanchez 931c14b
Formatting fixes.
pelusanchez 4f170cd
v7.0.0-0
pelusanchez 0453242
Precommit lint.
pelusanchez f4ea5f3
Fix error show.
pelusanchez 6a85a48
Fix value and added aria-invalid.
pelusanchez 0fbd246
Handle clearAll and fix classNames.
pelusanchez a6a7a92
v7.0.0-1
pelusanchez d5cf11f
v7.0.0
pelusanchez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Unit tests for FreeformInputWidget validation: string, integer and float values. | ||
*/ | ||
import { expect } from '@jest/globals' | ||
|
||
import { isDigitKey, isInteger, isFloat, keyDownHandler } from '../../src' | ||
|
||
const asEvent = (key: string): React.KeyboardEvent<HTMLInputElement> => { | ||
return { | ||
key, | ||
preventDefault: jest.fn(), | ||
stopPropagation: jest.fn() | ||
} as unknown as React.KeyboardEvent<HTMLInputElement> | ||
} | ||
|
||
describe('<FreeformInputWidget/>', () => { | ||
describe('Validation', () => { | ||
describe('Input validation', () => { | ||
it('accepts digit input', () => { | ||
expect(isDigitKey('1')).toBeTruthy() | ||
expect(isDigitKey('0')).toBeTruthy() | ||
expect(isDigitKey('9')).toBeTruthy() | ||
}) | ||
|
||
it('accepts float input', () => { | ||
expect(isFloat('Delete')).toBeTruthy() | ||
expect(isFloat('Backspace')).toBeTruthy() | ||
expect(isFloat('ArrowLeft')).toBeTruthy() | ||
expect(isFloat('ArrowRight')).toBeTruthy() | ||
expect(isFloat('ArrowUp')).toBeTruthy() | ||
expect(isFloat('ArrowDown')).toBeTruthy() | ||
|
||
expect(isFloat('.')).toBeTruthy() | ||
expect(isFloat('0')).toBeTruthy() | ||
expect(isFloat('1')).toBeTruthy() | ||
expect(isFloat('9')).toBeTruthy() | ||
}) | ||
|
||
it('accepts integer input', () => { | ||
expect(isInteger('Delete')).toBeTruthy() | ||
expect(isInteger('Backspace')).toBeTruthy() | ||
expect(isInteger('ArrowLeft')).toBeTruthy() | ||
expect(isInteger('ArrowRight')).toBeTruthy() | ||
expect(isInteger('ArrowUp')).toBeTruthy() | ||
expect(isInteger('ArrowDown')).toBeTruthy() | ||
|
||
expect(isInteger('1')).toBeTruthy() | ||
expect(isInteger('0')).toBeTruthy() | ||
expect(isInteger('9')).toBeTruthy() | ||
}) | ||
|
||
it('rejects digit input', () => { | ||
expect(isDigitKey('a')).toBeFalsy() | ||
expect(isDigitKey('b')).toBeFalsy() | ||
expect(isDigitKey('A')).toBeFalsy() | ||
}) | ||
|
||
it('rejects not int input', () => { | ||
expect(isInteger('.')).toBeFalsy() | ||
expect(isInteger('a')).toBeFalsy() | ||
expect(isInteger('_')).toBeFalsy() | ||
}) | ||
|
||
it('rejects not float input', () => { | ||
expect(isFloat('a')).toBeFalsy() | ||
expect(isFloat('_')).toBeFalsy() | ||
}) | ||
|
||
it('keyDownHandler works as expected', () => { | ||
const validator = keyDownHandler(isFloat) | ||
let ev = asEvent('A') | ||
expect(validator(ev)) | ||
expect(ev.preventDefault).toBeCalled() | ||
|
||
ev = asEvent('2') | ||
expect(validator(ev)) | ||
expect(ev.preventDefault).not.toBeCalled() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, update the
CHANGELOG
as well.