diff --git a/src/ScenarioUtils/ScenarioUtils.js b/src/ScenarioUtils/ScenarioUtils.js index 245cd30..b99a090 100644 --- a/src/ScenarioUtils/ScenarioUtils.js +++ b/src/ScenarioUtils/ScenarioUtils.js @@ -1,7 +1,5 @@ // Copyright (c) Cosmo Tech. // Licensed under the MIT license. -import { NAME_VALIDATOR } from './constants'; - const scenarioExistsInList = (scenarioName, scenarioList) => { scenarioName = scenarioName.trim(); return scenarioList.find((scenario) => scenario.name.trim() === scenarioName) !== undefined; @@ -21,15 +19,8 @@ const scenarioExistsInTree = (scenarioName, scenarioTree) => { const scenarioNameIsValid = (scenarioName, scenarioList) => { scenarioName = scenarioName.trimEnd(); - if (scenarioName.length === 0) { - return 'emptyScenarioName'; - } else { - if (scenarioName.match(NAME_VALIDATOR) === null) { - return 'forbiddenCharsInScenarioName'; - } else if (scenarioExistsInList(scenarioName, scenarioList)) { - return 'existingScenarioName'; - } - } + if (scenarioName.length === 0) return 'emptyScenarioName'; + if (scenarioExistsInList(scenarioName, scenarioList)) return 'existingScenarioName'; return null; }; diff --git a/src/ScenarioUtils/__test__/ScenarioUtils.spec.js b/src/ScenarioUtils/__test__/ScenarioUtils.spec.js index 1a90df1..2d72d3b 100644 --- a/src/ScenarioUtils/__test__/ScenarioUtils.spec.js +++ b/src/ScenarioUtils/__test__/ScenarioUtils.spec.js @@ -12,39 +12,19 @@ const scenarioList = [ describe('scenarioNameIsValid', () => { test.each` dataStr | expectedRes - ${' new scenario'} | ${'forbiddenCharsInScenarioName'} + ${'new scenario'} | ${null} + ${' new scenario '} | ${null} + ${'123 scenario'} | ${null} + ${'new scenario 132'} | ${null} + ${'new scenario *+,_&%§-.'} | ${null} + ${'new scenario 🚀'} | ${null} ${'existing scenario'} | ${'existingScenarioName'} ${'existing scenario '} | ${'existingScenarioName'} - ${'existing scenario '} | ${'existingScenarioName'} - ${'existing scenario '} | ${'existingScenarioName'} - ${' existing scenario '} | ${'forbiddenCharsInScenarioName'} - ${' existing scenario '} | ${'forbiddenCharsInScenarioName'} - ${' existing scenario '} | ${'forbiddenCharsInScenarioName'} - ${'new scenario *****'} | ${'forbiddenCharsInScenarioName'} - ${'new +scenario'} | ${'forbiddenCharsInScenarioName'} - ${'new ,scenario'} | ${'forbiddenCharsInScenarioName'} + ${' existing scenario '} | ${'existingScenarioName'} ${'existing scenario 2'} | ${'existingScenarioName'} - ${'new.scenario'} | ${null} - ${'new_scenario'} | ${null} - ${'new & scenario'} | ${'forbiddenCharsInScenarioName'} - ${'new % scenario *****'} | ${'forbiddenCharsInScenarioName'} - ${'new §scenario *****'} | ${'forbiddenCharsInScenarioName'} - ${'new scenario'} | ${null} - ${'new-scenario'} | ${null} - ${'new---scenario'} | ${null} ${'existing scenario 3'} | ${'existingScenarioName'} - ${'---new scenario'} | ${'forbiddenCharsInScenarioName'} - ${'_new scenario'} | ${'forbiddenCharsInScenarioName'} - ${'.new scenario'} | ${'forbiddenCharsInScenarioName'} - ${'new*scenario'} | ${'forbiddenCharsInScenarioName'} - ${'new=scenario'} | ${'forbiddenCharsInScenarioName'} - ${'new+scenario'} | ${'forbiddenCharsInScenarioName'} - ${'new scenario---'} | ${null} ${'existing scenario 4'} | ${'existingScenarioName'} - ${'123 scenario'} | ${null} - ${' new scenario '} | ${'forbiddenCharsInScenarioName'} - ${'new scenario 132'} | ${null} - `('for $dataStr must be $expectedRes', ({ dataStr, expectedRes }) => { + `('for "$dataStr" must be $expectedRes', ({ dataStr, expectedRes }) => { const res = ScenarioUtils.scenarioNameIsValid(dataStr, scenarioList); expect(res).toStrictEqual(expectedRes); }); diff --git a/src/ScenarioUtils/constants.js b/src/ScenarioUtils/constants.js deleted file mode 100644 index 4b2e738..0000000 --- a/src/ScenarioUtils/constants.js +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) Cosmo Tech. -// Licensed under the MIT license. - -export const NAME_VALIDATOR = /^[a-zA-Z0-9][\w\s.-]*$/;