2022-11-17 04:16:49 +00:00
|
|
|
import { REP_PEACEFUL_STRING } from '../consts/REG_EXP_PATTERNS';
|
|
|
|
|
2023-04-04 03:25:23 +00:00
|
|
|
import testNotBlank from './testNotBlank';
|
2022-11-16 04:15:53 +00:00
|
|
|
import { InlineMonoText } from '../../components/Text';
|
|
|
|
|
|
|
|
const buildPeacefulStringTestBatch: BuildInputTestBatchFunction = (
|
|
|
|
inputName,
|
|
|
|
onSuccess,
|
2023-03-04 00:28:48 +00:00
|
|
|
{ isRequired, onFinishBatch, ...defaults } = {},
|
2022-11-16 04:15:53 +00:00
|
|
|
onTestPeacefulStringFailureAppend,
|
|
|
|
) => ({
|
2022-11-25 04:56:46 +00:00
|
|
|
defaults: { ...defaults, onSuccess },
|
2023-03-04 00:28:48 +00:00
|
|
|
isRequired,
|
2022-11-25 04:56:46 +00:00
|
|
|
onFinishBatch,
|
2022-11-16 04:15:53 +00:00
|
|
|
tests: [
|
2023-04-04 03:25:23 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Not-blank test ensures no unnecessary error message is provided when
|
|
|
|
* input is not (yet) filled.
|
|
|
|
*/
|
|
|
|
test: testNotBlank,
|
|
|
|
},
|
2022-11-16 04:15:53 +00:00
|
|
|
{
|
|
|
|
onFailure: (...args) => {
|
|
|
|
onTestPeacefulStringFailureAppend(
|
|
|
|
<>
|
|
|
|
{inputName} cannot contain single-quote (
|
2023-04-05 21:18:51 +00:00
|
|
|
<InlineMonoText inheritColour text="'" />
|
|
|
|
), double-quote (<InlineMonoText inheritColour text='"' />
|
|
|
|
), slash (<InlineMonoText inheritColour text="/" />
|
|
|
|
), backslash (<InlineMonoText inheritColour text="\" />
|
|
|
|
), angle brackets (<InlineMonoText inheritColour text="<>" />
|
|
|
|
), curly brackets (<InlineMonoText inheritColour text="{}" />
|
2022-11-16 04:15:53 +00:00
|
|
|
).
|
|
|
|
</>,
|
|
|
|
...args,
|
|
|
|
);
|
|
|
|
},
|
2022-11-17 04:16:49 +00:00
|
|
|
test: ({ value }) => REP_PEACEFUL_STRING.test(value as string),
|
2022-11-16 04:15:53 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
export default buildPeacefulStringTestBatch;
|