fix(striker-ui): add testLength() and make test defaults optional

main
Tsu-ba-me 2 years ago
parent c4a04ddbae
commit 2d6766f096
  1. 2
      striker-ui/lib/test_input/testInput.ts
  2. 23
      striker-ui/lib/test_input/testLength.ts
  3. 4
      striker-ui/types/TestInputFunction.ts

@ -55,7 +55,7 @@ const testInput: TestInputFunction = ({
min: dMin = 0,
onSuccess: dOnSuccess,
value: dValue = null,
},
} = {},
onFinishBatch,
optionalTests,
tests: requiredTests,

@ -0,0 +1,23 @@
import { MinimalInputTestArgs } from '../../types/TestInputFunction';
const testLength: (
args: Pick<MinimalInputTestArgs, 'value'> &
Partial<Pick<MinimalInputTestArgs, 'max' | 'min'>>,
) => boolean = ({ max, min, value }) => {
const { length } = String(value);
let isGEMin = true;
let isLEMax = true;
if (min) {
isGEMin = length >= min;
}
if (max) {
isLEMax = length <= max;
}
return isGEMin && isLEMax;
};
export default testLength;

@ -18,8 +18,8 @@ export type InputTest = {
export type InputTestBatches = {
[id: string]: {
defaults: InputTestArgs & {
onSuccess: () => void;
defaults?: InputTestArgs & {
onSuccess?: () => void;
};
onFinishBatch?: () => void;
optionalTests?: Array<InputTest>;

Loading…
Cancel
Save