Skip to content

Commit

Permalink
Merge pull request #302 from l2hyunwoo/feature/fix-validation-empty-n…
Browse files Browse the repository at this point in the history
…ame-goal

🐛 Add Validation For Name & Goal
  • Loading branch information
awtkns authored Apr 21, 2023
2 parents 39306a9 + 0d8caf2 commit f730c66
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions __tests__/whitespace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { isEmptyOrBlank } from "../src/utils/whitespace";

describe("WhiteSpace and empty string should return true", () => {
test("Empty string should return true", () => {
const emptyString = "";
expect(isEmptyOrBlank(emptyString)).toEqual(true);
})
test("WhiteSpace string should return true", () => {
const whiteSpaceString = " ";
expect(isEmptyOrBlank(whiteSpaceString)).toEqual(true);
})
test("NewLine should return true", () => {
const newLineString = "\n\n";
expect(isEmptyOrBlank(newLineString)).toEqual(true);
})
})
3 changes: 2 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TaskWindow } from "../components/TaskWindow";
import { useAuth } from "../hooks/useAuth";
import type { Message } from "../types/agentTypes";
import { useAgent } from "../hooks/useAgent";
import { isEmptyOrBlank } from "../utils/whitespace";

const Home: NextPage = () => {
const { session, status } = useAuth();
Expand Down Expand Up @@ -71,7 +72,7 @@ const Home: NextPage = () => {

const tasks = messages.filter((message) => message.type === "task");

const disableDeployAgent = agent != null || name === "" || goalInput === ""
const disableDeployAgent = agent != null || isEmptyOrBlank(name) || isEmptyOrBlank(goalInput);

const handleNewGoal = () => {
const agent = new AutonomousAgent(
Expand Down
7 changes: 7 additions & 0 deletions src/utils/whitespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function regex() {
return /^[\s\f\n\r\t\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\x09\x0a\x0b\x0c\x0d\x20\xa0]+$/;
}

export function isEmptyOrBlank(value: string) {
return regex().test(value) || value === '';
}

1 comment on commit f730c66

@vercel
Copy link

@vercel vercel bot commented on f730c66 Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.