fix(striker-ui): add append data to input tests

main
Tsu-ba-me 2 years ago
parent 87160b67df
commit 9e88a44894
  1. 12
      striker-ui/lib/test_input/testInput.ts
  2. 20
      striker-ui/types/TestInputFunction.ts

@ -2,6 +2,7 @@ import {
InputTest,
InputTestBatches,
InputTestInputs,
CallbackAppendArgs,
TestInputFunction,
} from '../../types/TestInputFunction';
@ -49,7 +50,7 @@ const testInput: TestInputFunction = ({
Object.keys(testsToRun).every((id: string) => {
const {
defaults: {
compare: dCompare = null,
compare: dCompare = [],
displayMax: dDisplayMax,
displayMin: dDisplayMin,
getCompare: dGetCompare,
@ -81,7 +82,9 @@ const testInput: TestInputFunction = ({
onSuccess = dOnSuccess,
test,
}) => {
const append: CallbackAppendArgs['append'] = {};
const singleResult: boolean = test({
append,
compare,
max,
min,
@ -99,6 +102,7 @@ const testInput: TestInputFunction = ({
allResult = singleResult;
cbFailure?.call(null, {
append,
compare,
displayMax,
displayMin,
@ -116,6 +120,12 @@ const testInput: TestInputFunction = ({
const requiredTestsResult = requiredTests.every(runTest);
// console.log(
// `[${requiredTestsResult ? 'PASS' : 'FAILED'}]id=${id},getValue=${
// getValue !== undefined
// },value=${value}`,
// );
cbFinishBatch?.call(null);
return requiredTestsResult || isContinueOnFailure;

@ -1,10 +1,10 @@
export type InputTestValue = bigint | number | null | string | undefined;
export type InputTestArgs = {
compare?: InputTestValue;
compare?: InputTestValue[];
displayMax?: string;
displayMin?: string;
getCompare?: () => InputTestValue;
getCompare?: () => InputTestValue[];
getValue?: () => InputTestValue;
max?: bigint | number;
min?: bigint | number;
@ -15,10 +15,18 @@ export type MinimalInputTestArgs = Required<
Omit<InputTestArgs, 'displayMax' | 'displayMin' | 'getCompare' | 'getValue'>
>;
export type CallbackAppendArgs = {
append: {
[arg: string]: InputTestValue;
};
};
export type InputTestSuccessCallback = () => void;
export type InputTest = {
onFailure?: (args: InputTestArgs) => void;
onSuccess?: () => void;
test: (args: MinimalInputTestArgs) => boolean;
onFailure?: (args: InputTestArgs & CallbackAppendArgs) => void;
onSuccess?: InputTestSuccessCallback;
test: (args: MinimalInputTestArgs & CallbackAppendArgs) => boolean;
};
export type InputTestInputs = {
@ -28,7 +36,7 @@ export type InputTestInputs = {
export type InputTestBatches = {
[id: string]: {
defaults?: InputTestArgs & {
onSuccess?: () => void;
onSuccess?: InputTestSuccessCallback;
};
onFinishBatch?: () => void;
optionalTests?: Array<InputTest>;

Loading…
Cancel
Save