forked from stakwork/sphinx-tribes-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request stakwork#234 from saithsab877/Incorrect-check-for-…
…enabling-Next-button Fix Incorrect Next Button Enablement for Zero Value in Price (Sats)
- Loading branch information
Showing
3 changed files
with
147 additions
and
7 deletions.
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
127 changes: 127 additions & 0 deletions
127
src/components/form/inputs/__tests__/NumberSatsInput.spec.tsx
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,127 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { convertLocaleToNumber } from '../../../../helpers'; | ||
import NumberInputNew from '../NumberSatsInput.tsx'; | ||
|
||
describe('NumberInputNew Component', () => { | ||
test('accepts numbers greater than or equal to 1', () => { | ||
render( | ||
<NumberInputNew | ||
error={''} | ||
label="Test Label" | ||
name="testInput" | ||
value="" | ||
handleChange={() => { | ||
(''); | ||
}} | ||
handleBlur={() => { | ||
(''); | ||
}} | ||
handleFocus={() => { | ||
(''); | ||
}} | ||
readOnly | ||
/> | ||
); | ||
const inputElement = screen.getByPlaceholderText('1') as HTMLInputElement; | ||
fireEvent.change(inputElement, { target: { value: '123' } }); | ||
expect(convertLocaleToNumber(inputElement.value)).toBeGreaterThanOrEqual(1); | ||
}); | ||
|
||
test('does not accept symbols', () => { | ||
render( | ||
<NumberInputNew | ||
error={''} | ||
label="Test Label" | ||
name="testInput" | ||
value="" | ||
handleChange={() => { | ||
(''); | ||
}} | ||
handleBlur={() => { | ||
(''); | ||
}} | ||
handleFocus={() => { | ||
(''); | ||
}} | ||
readOnly | ||
/> | ||
); | ||
const inputElement = screen.getByPlaceholderText('1') as HTMLInputElement; | ||
fireEvent.change(inputElement, { target: { value: '@#$' } }); | ||
expect(inputElement.value).toBe(''); //component clears the input for invalid values | ||
}); | ||
|
||
test('does not accept text', () => { | ||
render( | ||
<NumberInputNew | ||
error={''} | ||
label="Test Label" | ||
name="testInput" | ||
value="" | ||
handleChange={() => { | ||
(''); | ||
}} | ||
handleBlur={() => { | ||
(''); | ||
}} | ||
handleFocus={() => { | ||
(''); | ||
}} | ||
readOnly | ||
/> | ||
); | ||
const inputElement = screen.getByPlaceholderText('1') as HTMLInputElement; | ||
fireEvent.change(inputElement, { target: { value: 'text' } }); | ||
expect(inputElement.value).toBe(''); | ||
}); | ||
|
||
test('does not accept negative numbers', () => { | ||
render( | ||
<NumberInputNew | ||
error={''} | ||
label="Test Label" | ||
name="testInput" | ||
value="" | ||
handleChange={() => { | ||
(''); | ||
}} | ||
handleBlur={() => { | ||
(''); | ||
}} | ||
handleFocus={() => { | ||
(''); | ||
}} | ||
readOnly | ||
/> | ||
); | ||
const inputElement = screen.getByPlaceholderText('1') as HTMLInputElement; | ||
fireEvent.change(inputElement, { target: { value: '-123' } }); | ||
expect(inputElement.value).toBe(''); | ||
}); | ||
|
||
test('does not accept numbers less than to 0', () => { | ||
render( | ||
<NumberInputNew | ||
error={''} | ||
label="Test Label" | ||
name="testInput" | ||
value="" | ||
handleChange={() => { | ||
(''); | ||
}} | ||
handleBlur={() => { | ||
(''); | ||
}} | ||
handleFocus={() => { | ||
(''); | ||
}} | ||
readOnly | ||
/> | ||
); | ||
const inputElement = screen.getByPlaceholderText('1') as HTMLInputElement; | ||
fireEvent.change(inputElement, { target: { value: '0' } }); | ||
expect(inputElement.value).toBe(''); | ||
}); | ||
}); |
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