Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,53 @@ describe('useCheckInputsForms', () => {
)
})

describe('required number inputs', () => {
const inputsForm: InputForm[] = [
{
variable: 'count',
label: 'Count',
required: true,
type: InputVarType.number,
hide: false,
},
]

it.each([0, 1, -1, '0'])('should accept %j without a required-input error', (value) => {
const { result } = renderHook(() => useCheckInputsForms())

expect(result.current.checkInputsForm({ count: value }, inputsForm)).toBe(true)
expect(mockNotify).not.toHaveBeenCalled()
})

it.each([undefined, null, ''])('should reject an empty number value (%j)', (value) => {
const { result } = renderHook(() => useCheckInputsForms())

expect(result.current.checkInputsForm({ count: value }, inputsForm)).toBe(false)
expect(mockNotify).toHaveBeenCalledWith(
expect.objectContaining({
type: 'error',
message: expect.stringContaining('appDebug.errorMessage.valueOfVarRequired'),
}),
)
})
})

it('should allow an unchecked required checkbox without a notification', () => {
const { result } = renderHook(() => useCheckInputsForms())
const inputsForm: InputForm[] = [
{
variable: 'enabled',
label: 'Enabled',
required: true,
type: InputVarType.checkbox,
hide: false,
},
]

expect(result.current.checkInputsForm({ enabled: false }, inputsForm)).toBe(true)
expect(mockNotify).not.toHaveBeenCalled()
})

it('should ignore missing but not required inputs', () => {
const { result } = renderHook(() => useCheckInputsForms())
const inputsForm = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useCheckInputsForms = () => {
requiredVars.forEach(({ variable, label, type }) => {
if (hasEmptyInput) return
if (fileIsUploading) return
if (!inputs[variable]) hasEmptyInput = label as string
if (!inputs[variable] && inputs[variable] !== 0) hasEmptyInput = label as string
if (
(type === InputVarType.singleFile || type === InputVarType.multiFiles) &&
inputs[variable]
Expand Down
Loading