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

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

Loading…
Cancel
Save