fix(striker-ui): allow input test to fetch value during run

main
Tsu-ba-me 2 years ago
parent 48a6f12256
commit 469df1b7c1
  1. 24
      striker-ui/lib/test_input/testInput.ts
  2. 10
      striker-ui/types/TestInputFunction.ts

@ -52,6 +52,8 @@ const testInput: TestInputFunction = ({
compare: dCompare = null, compare: dCompare = null,
displayMax: dDisplayMax, displayMax: dDisplayMax,
displayMin: dDisplayMin, displayMin: dDisplayMin,
getCompare: dGetCompare,
getValue: dGetValue,
max: dMax = 0, max: dMax = 0,
min: dMin = 0, min: dMin = 0,
onSuccess: dOnSuccess, onSuccess: dOnSuccess,
@ -62,10 +64,12 @@ const testInput: TestInputFunction = ({
tests: requiredTests, tests: requiredTests,
} = tests[id]; } = tests[id];
const { const {
compare = dCompare, getCompare = dGetCompare,
getValue = dGetValue,
max = dMax, max = dMax,
min = dMin, min = dMin,
value = dValue, compare = getCompare?.call(null) ?? dCompare,
value = getValue?.call(null) ?? dValue,
displayMax = dDisplayMax || String(max), displayMax = dDisplayMax || String(max),
displayMin = dDisplayMin || String(min), displayMin = dDisplayMin || String(min),
} = testsToRun[id]; } = testsToRun[id];
@ -77,7 +81,12 @@ const testInput: TestInputFunction = ({
onSuccess = dOnSuccess, onSuccess = dOnSuccess,
test, test,
}) => { }) => {
const singleResult: boolean = test({ compare, max, min, value }); const singleResult: boolean = test({
compare,
max,
min,
value,
});
const { cbFailure, cbSuccess } = setSingleCallback({ const { cbFailure, cbSuccess } = setSingleCallback({
onFailure, onFailure,
@ -89,7 +98,14 @@ const testInput: TestInputFunction = ({
} else { } else {
allResult = singleResult; allResult = singleResult;
cbFailure?.call(null, { displayMax, displayMin, max, min, value }); cbFailure?.call(null, {
compare,
displayMax,
displayMin,
max,
min,
value,
});
} }
return singleResult; return singleResult;

@ -1,14 +1,18 @@
export type InputTestValue = bigint | number | null | string | undefined;
export type InputTestArgs = { export type InputTestArgs = {
compare?: InputTestArgs['value']; compare?: InputTestValue;
displayMax?: string; displayMax?: string;
displayMin?: string; displayMin?: string;
getCompare?: () => InputTestValue;
getValue?: () => InputTestValue;
max?: bigint | number; max?: bigint | number;
min?: bigint | number; min?: bigint | number;
value?: bigint | number | null | string; value?: InputTestValue;
}; };
export type MinimalInputTestArgs = Required< export type MinimalInputTestArgs = Required<
Omit<InputTestArgs, 'displayMax' | 'displayMin'> Omit<InputTestArgs, 'displayMax' | 'displayMin' | 'getCompare' | 'getValue'>
>; >;
export type InputTest = { export type InputTest = {

Loading…
Cancel
Save