From 5fe0ec06cf7fc7de3e4dd3de33f24b1201bbd669 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 13 May 2022 14:43:21 -0400 Subject: [PATCH] fix(striker-ui): optional default max and min in input test args --- striker-ui/lib/test_input/testInput.ts | 11 +++++------ striker-ui/lib/test_input/testMax.ts | 5 +++-- striker-ui/lib/test_input/testNotBlank.ts | 4 ++-- striker-ui/lib/test_input/testRange.ts | 9 ++++++--- striker-ui/types/TestInputFunction.ts | 10 +++++++--- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/striker-ui/lib/test_input/testInput.ts b/striker-ui/lib/test_input/testInput.ts index 27f06290..9f73ea1b 100644 --- a/striker-ui/lib/test_input/testInput.ts +++ b/striker-ui/lib/test_input/testInput.ts @@ -51,10 +51,10 @@ const testInput: TestInputFunction = ({ defaults: { displayMax: dDisplayMax, displayMin: dDisplayMin, - max: dMax, - min: dMin, + max: dMax = 0, + min: dMin = 0, onSuccess: dOnSuccess, - value: dValue, + value: dValue = null, }, onFinishBatch, optionalTests, @@ -75,8 +75,7 @@ const testInput: TestInputFunction = ({ onSuccess = dOnSuccess, test, }) => { - const args = { displayMax, displayMin, max, min, value }; - const singleResult: boolean = test(args); + const singleResult: boolean = test({ max, min, value }); const { cbFailure, cbSuccess } = setSingleCallback({ onFailure, @@ -88,7 +87,7 @@ const testInput: TestInputFunction = ({ } else { allResult = singleResult; - cbFailure?.call(null, args); + cbFailure?.call(null, { displayMax, displayMin, max, min, value }); } return singleResult; diff --git a/striker-ui/lib/test_input/testMax.ts b/striker-ui/lib/test_input/testMax.ts index e86ee2f7..3047e74e 100644 --- a/striker-ui/lib/test_input/testMax.ts +++ b/striker-ui/lib/test_input/testMax.ts @@ -1,5 +1,6 @@ -import { InputTestArgs } from '../../types/TestInputFunction'; +import { MinimalInputTestArgs } from '../../types/TestInputFunction'; -const testMax: (args: InputTestArgs) => boolean = ({ max, min }) => max >= min; +const testMax: (args: MinimalInputTestArgs) => boolean = ({ max, min }) => + max >= min; export default testMax; diff --git a/striker-ui/lib/test_input/testNotBlank.ts b/striker-ui/lib/test_input/testNotBlank.ts index 943171f7..7f3d67d5 100644 --- a/striker-ui/lib/test_input/testNotBlank.ts +++ b/striker-ui/lib/test_input/testNotBlank.ts @@ -1,6 +1,6 @@ -import { InputTestArgs } from '../../types/TestInputFunction'; +import { MinimalInputTestArgs } from '../../types/TestInputFunction'; -const testNotBlank: (args: InputTestArgs) => boolean = ({ value }) => +const testNotBlank: (args: MinimalInputTestArgs) => boolean = ({ value }) => value ? String(value).length > 0 : false; export default testNotBlank; diff --git a/striker-ui/lib/test_input/testRange.ts b/striker-ui/lib/test_input/testRange.ts index 52d6b810..e21003f7 100644 --- a/striker-ui/lib/test_input/testRange.ts +++ b/striker-ui/lib/test_input/testRange.ts @@ -1,6 +1,9 @@ -import { InputTestArgs } from '../../types/TestInputFunction'; +import { MinimalInputTestArgs } from '../../types/TestInputFunction'; -const testRange: (args: InputTestArgs) => boolean = ({ max, min, value }) => - value ? value >= min && value <= max : false; +const testRange: (args: MinimalInputTestArgs) => boolean = ({ + max, + min, + value, +}) => (value ? value >= min && value <= max : false); export default testRange; diff --git a/striker-ui/types/TestInputFunction.ts b/striker-ui/types/TestInputFunction.ts index 67ff8906..fe59aa89 100644 --- a/striker-ui/types/TestInputFunction.ts +++ b/striker-ui/types/TestInputFunction.ts @@ -1,15 +1,19 @@ export type InputTestArgs = { displayMax?: string; displayMin?: string; - max: bigint | number; - min: bigint | number; + max?: bigint | number; + min?: bigint | number; value?: bigint | number | null | string; }; +export type MinimalInputTestArgs = Required< + Omit +>; + export type InputTest = { onFailure?: (args: InputTestArgs) => void; onSuccess?: () => void; - test: (args: InputTestArgs) => boolean; + test: (args: MinimalInputTestArgs) => boolean; }; export type InputTestBatches = {