diff --git a/scm-ui/src/components/validation.js b/scm-ui/src/components/validation.js new file mode 100644 index 0000000000..1893d7db8d --- /dev/null +++ b/scm-ui/src/components/validation.js @@ -0,0 +1,6 @@ +// @flow +const nameRegex = /^([A-z0-9.\-_@]|[^ ]([A-z0-9.\-_@ ]*[A-z0-9.\-_@]|[^\s])?)$/; + +export const isNameValid = (name: string) => { + return nameRegex.test(name); +}; diff --git a/scm-ui/src/components/validation.test.js b/scm-ui/src/components/validation.test.js new file mode 100644 index 0000000000..788ee4c5a5 --- /dev/null +++ b/scm-ui/src/components/validation.test.js @@ -0,0 +1,52 @@ +// @flow +import * as validator from "./validation"; + +describe("test name validation", () => { + it("should return false", () => { + // invalid names taken from ValidationUtilTest.java + const invalidNames = [ + " test 123", + " test 123 ", + "test 123 ", + "test/123", + "test%123", + "test:123", + "t ", + " t", + " t ", + "", + + " invalid_name", + "another%one", + "!!!", + "!_!" + ]; + for (let name of invalidNames) { + expect(validator.isNameValid(name)).toBe(false); + } + }); + + it("should return true", () => { + // valid names taken from ValidationUtilTest.java + const validNames = [ + "test", + "test.git", + "Test123.git", + "Test123-git", + "Test_user-123.git", + "test@scm-manager.de", + "test 123", + "tt", + "t", + + "valid_name", + "another1", + "stillValid", + "this.one_as-well", + "and@this" + ]; + for (let name of validNames) { + expect(validator.isNameValid(name)).toBe(true); + } + }); +}); diff --git a/scm-ui/src/groups/components/groupValidation.js b/scm-ui/src/groups/components/groupValidation.js index 05077358a0..bb76f86024 100644 --- a/scm-ui/src/groups/components/groupValidation.js +++ b/scm-ui/src/groups/components/groupValidation.js @@ -1,14 +1,8 @@ // @flow +import { isNameValid } from "../../components/validation"; -//TODO: How should a group be validated -//TODO: Tests! - -const nameRegex = /^([A-z0-9.\-_@]|[^ ]([A-z0-9.\-_@ ]*[A-z0-9.\-_@]|[^\s])?)$/; - -export const isNameValid = (name: string) => { - return nameRegex.test(name); -}; +export { isNameValid }; export const isMemberNameValid = (name: string) => { - return nameRegex.test(name); -} + return isNameValid(name); +}; diff --git a/scm-ui/src/groups/components/groupValidation.test.js b/scm-ui/src/groups/components/groupValidation.test.js deleted file mode 100644 index 1ae332d90f..0000000000 --- a/scm-ui/src/groups/components/groupValidation.test.js +++ /dev/null @@ -1,20 +0,0 @@ -//@flow -import * as validator from "./groupValidation"; - -describe("validator", () => { - it("should validate allowed names correctly", () => { - const validNames = ["valid_name", "another1", "stillValid", "this.one_as-well", "and@this"]; - - for (let validName of validNames) { - expect(validator.isNameValid(validName)).toBeTruthy(); - } - }); - - it("should reject invalid names", () => { - const invalidNames = [" invalid_name", "another%one", "!!!", "!_!"]; - - for (let invalidName of invalidNames) { - expect(validator.isNameValid(invalidName)).toBeFalsy(); - } - }) -}); diff --git a/scm-ui/src/users/components/userValidation.js b/scm-ui/src/users/components/userValidation.js index a5d592e4fb..583037c20c 100644 --- a/scm-ui/src/users/components/userValidation.js +++ b/scm-ui/src/users/components/userValidation.js @@ -1,10 +1,8 @@ // @flow -const nameRegex = /^([A-z0-9.\-_@]|[^ ]([A-z0-9.\-_@ ]*[A-z0-9.\-_@]|[^\s])?)$/; +import { isNameValid } from "../../components/validation"; -export const isNameValid = (name: string) => { - return nameRegex.test(name); -}; +export { isNameValid }; export const isDisplayNameValid = (displayName: string) => { if (displayName) { diff --git a/scm-ui/src/users/components/userValidation.test.js b/scm-ui/src/users/components/userValidation.test.js index 370247fe90..e97e5628c0 100644 --- a/scm-ui/src/users/components/userValidation.test.js +++ b/scm-ui/src/users/components/userValidation.test.js @@ -1,45 +1,6 @@ // @flow import * as validator from "./userValidation"; -describe("test name validation", () => { - it("should return false", () => { - // invalid names taken from ValidationUtilTest.java - const invalidNames = [ - " test 123", - " test 123 ", - "test 123 ", - "test/123", - "test%123", - "test:123", - "t ", - " t", - " t ", - "" - ]; - for (let name of invalidNames) { - expect(validator.isNameValid(name)).toBe(false); - } - }); - - it("should return true", () => { - // valid names taken from ValidationUtilTest.java - const validNames = [ - "test", - "test.git", - "Test123.git", - "Test123-git", - "Test_user-123.git", - "test@scm-manager.de", - "test 123", - "tt", - "t" - ]; - for (let name of validNames) { - expect(validator.isNameValid(name)).toBe(true); - } - }); -}); - describe("test displayName validation", () => { it("should return false", () => { expect(validator.isDisplayNameValid("")).toBe(false);