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

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

Loading…
Cancel
Save