diff --git a/src/utils/validationUtils.js b/src/utils/validationUtils.js index cf17c6d..0b5ef92 100644 --- a/src/utils/validationUtils.js +++ b/src/utils/validationUtils.js @@ -10,8 +10,8 @@ const DISPLAY_NAME_REGEX = /^(?!.*\s{2,})[^\s](.{0,18}[^\s])?$|^$/; // Check if const CLASS_CODE_REGEX = /^[A-Z0-9]{6}$/; // Check if the class code is valid (exactly 6 characters, uppercase letters and numbers only) const CLASS_NAME_REGEX = /^(?!\s*$)[a-zA-Z0-9\s]{1,50}$/; // Check if the class name is valid (at least 1 character, alphanumeric characters and spaces only, cannot be empty or just spaces or symbols) const STUDENT_NAME_REGEX = /^(?!.*\s{2,})[^\s](.{0,18}[^\s])?$|^$/; // Check if the student name is valid (no more than 20 characters, no leading or trailing spaces, no consecutive spaces) -const TASK_NAME_REGEX = /^[a-zA-Z0-9\s]{1,50}$/; // Check if the task name is valid (at least 1 character, alphanumeric characters and spaces only) -const TASK_DESCRIPTION_REGEX = /^[a-zA-Z0-9\s]{1,500}$/; // Check if the task description is valid (at least 1 character, alphanumeric characters and spaces only) +const TASK_NAME_REGEX = /^(?!.*\s{2,})(?!\s)(.{2,50}?)(? { expect(validateTaskName("a".repeat(51))).toBe(false); }); - test("should return false for a task name with special characters", () => { - expect(validateTaskName("Task@Name!")).toBe(false); + test("should return false for a task name with leading spaces", () => { + expect(validateTaskName(" leading")).toBe(false); + }); + + test("should return false for a task name with consecutive spaces", () => { + expect(validateTaskName("consecutive spaces")).toBe(false); + }); + + test("should return true for a task name with special characters", () => { + expect(validateTaskName("Task-Name | 123")).toBe(true); }); test("should return true for a valid task name with alphanumeric characters", () => { @@ -419,8 +427,16 @@ describe("validateTaskDescription", () => { expect(validateTaskDescription("a".repeat(501))).toBe(false); }); - test("should return false for a task description with special characters", () => { - expect(validateTaskDescription("Task@Description!")).toBe(false); + test("should return false for a task description with leading spaces", () => { + expect(validateTaskDescription(" leading")).toBe(false); + }); + + test("should return false for a task description with consecutive spaces", () => { + expect(validateTaskDescription("consecutive spaces")).toBe(false); + }); + + test("should return true for a task description with special characters", () => { + expect(validateTaskDescription("Task@Description!")).toBe(true); }); test("should return true for a valid task description with alphanumeric characters", () => {