fix(striker-ui): optional default max and min in input test args

main
Tsu-ba-me 3 years ago
parent 737c8598d3
commit 5fe0ec06cf
  1. 11
      striker-ui/lib/test_input/testInput.ts
  2. 5
      striker-ui/lib/test_input/testMax.ts
  3. 4
      striker-ui/lib/test_input/testNotBlank.ts
  4. 9
      striker-ui/lib/test_input/testRange.ts
  5. 10
      striker-ui/types/TestInputFunction.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;

@ -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;

@ -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;

@ -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;

@ -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<InputTestArgs, 'displayMax' | 'displayMin'>
>;
export type InputTest = {
onFailure?: (args: InputTestArgs) => void;
onSuccess?: () => void;
test: (args: InputTestArgs) => boolean;
test: (args: MinimalInputTestArgs) => boolean;
};
export type InputTestBatches = {

Loading…
Cancel
Save