From 0bdc5dd44e1b2c7cd2e59a56404f71c016200a10 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 3 Apr 2023 23:25:23 -0400 Subject: [PATCH] fix(striker-ui): re-add not-blank tests to test batch builders --- striker-ui/lib/test_input/buildDomainTestBatch.tsx | 4 ++++ striker-ui/lib/test_input/buildIPAddressTestBatch.tsx | 7 ++++++- striker-ui/lib/test_input/buildIpCsvTestBatch.tsx | 10 +++++++++- .../lib/test_input/buildPeacefulStringTestBatch.tsx | 8 ++++++++ striker-ui/lib/test_input/buildUUIDTestBatch.tsx | 7 ++++++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/striker-ui/lib/test_input/buildDomainTestBatch.tsx b/striker-ui/lib/test_input/buildDomainTestBatch.tsx index ebf96c71..9ed17475 100644 --- a/striker-ui/lib/test_input/buildDomainTestBatch.tsx +++ b/striker-ui/lib/test_input/buildDomainTestBatch.tsx @@ -1,5 +1,6 @@ import { REP_DOMAIN } from '../consts/REG_EXP_PATTERNS'; +import testNotBlank from './testNotBlank'; import { InlineMonoText } from '../../components/Text'; const buildDomainTestBatch: BuildInputTestBatchFunction = ( @@ -12,6 +13,9 @@ const buildDomainTestBatch: BuildInputTestBatchFunction = ( isRequired, onFinishBatch, tests: [ + { + test: testNotBlank, + }, { onFailure: (...args) => { onDomainTestFailure( diff --git a/striker-ui/lib/test_input/buildIPAddressTestBatch.tsx b/striker-ui/lib/test_input/buildIPAddressTestBatch.tsx index ed4b26e6..9d80b8be 100644 --- a/striker-ui/lib/test_input/buildIPAddressTestBatch.tsx +++ b/striker-ui/lib/test_input/buildIPAddressTestBatch.tsx @@ -1,5 +1,7 @@ import { REP_IPV4 } from '../consts/REG_EXP_PATTERNS'; +import testNotBlank from './testNotBlank'; + const buildIPAddressTestBatch: BuildInputTestBatchFunction = ( inputName, onSuccess, @@ -10,10 +12,13 @@ const buildIPAddressTestBatch: BuildInputTestBatchFunction = ( isRequired, onFinishBatch, tests: [ + { + test: testNotBlank, + }, { onFailure: (...args) => { onIPv4TestFailure( - `${inputName} should be a valid IPv4 address.`, + <>{inputName} should be a valid IPv4 address., ...args, ); }, diff --git a/striker-ui/lib/test_input/buildIpCsvTestBatch.tsx b/striker-ui/lib/test_input/buildIpCsvTestBatch.tsx index 0aeec9d2..19cbb9cf 100644 --- a/striker-ui/lib/test_input/buildIpCsvTestBatch.tsx +++ b/striker-ui/lib/test_input/buildIpCsvTestBatch.tsx @@ -1,5 +1,7 @@ import { REP_IPV4_CSV } from '../consts/REG_EXP_PATTERNS'; +import testNotBlank from './testNotBlank'; + const buildIpCsvTestBatch: BuildInputTestBatchFunction = ( inputName, onSuccess, @@ -10,10 +12,16 @@ const buildIpCsvTestBatch: BuildInputTestBatchFunction = ( isRequired, onFinishBatch, tests: [ + { + test: testNotBlank, + }, { onFailure: (...args) => { onIpCsvTestFailure( - `${inputName} must be one or more valid IPv4 addresses separated by comma; without trailing comma.`, + <> + {inputName} must be one or more valid IPv4 addresses separated by + comma(s); without trailing comma. + , ...args, ); }, diff --git a/striker-ui/lib/test_input/buildPeacefulStringTestBatch.tsx b/striker-ui/lib/test_input/buildPeacefulStringTestBatch.tsx index 27efbc1c..e05e0fa2 100644 --- a/striker-ui/lib/test_input/buildPeacefulStringTestBatch.tsx +++ b/striker-ui/lib/test_input/buildPeacefulStringTestBatch.tsx @@ -1,5 +1,6 @@ import { REP_PEACEFUL_STRING } from '../consts/REG_EXP_PATTERNS'; +import testNotBlank from './testNotBlank'; import { InlineMonoText } from '../../components/Text'; const buildPeacefulStringTestBatch: BuildInputTestBatchFunction = ( @@ -12,6 +13,13 @@ const buildPeacefulStringTestBatch: BuildInputTestBatchFunction = ( isRequired, onFinishBatch, tests: [ + { + /** + * Not-blank test ensures no unnecessary error message is provided when + * input is not (yet) filled. + */ + test: testNotBlank, + }, { onFailure: (...args) => { onTestPeacefulStringFailureAppend( diff --git a/striker-ui/lib/test_input/buildUUIDTestBatch.tsx b/striker-ui/lib/test_input/buildUUIDTestBatch.tsx index 36cdc85f..2779f113 100644 --- a/striker-ui/lib/test_input/buildUUIDTestBatch.tsx +++ b/striker-ui/lib/test_input/buildUUIDTestBatch.tsx @@ -1,5 +1,7 @@ import { REP_UUID } from '../consts/REG_EXP_PATTERNS'; +import testNotBlank from './testNotBlank'; + const buildUUIDTestBatch: BuildInputTestBatchFunction = ( inputName, onSuccess, @@ -10,9 +12,12 @@ const buildUUIDTestBatch: BuildInputTestBatchFunction = ( isRequired, onFinishBatch, tests: [ + { + test: testNotBlank, + }, { onFailure: (...args) => { - onUUIDTestFailure(`${inputName} must be a valid UUID.`, ...args); + onUUIDTestFailure(<>{inputName} must be a valid UUID., ...args); }, test: ({ value }) => REP_UUID.test(value as string), },