Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into DEVPROD-1975
Browse files Browse the repository at this point in the history
  • Loading branch information
khelif96 committed Feb 28, 2024
2 parents 435e567 + 588a9a7 commit 1bbd708
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/components/SpruceForm/customFormats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
validateJira,
validateJiraURL,
validateNoSpecialCharacters,
validateNoStartingOrTrailingWhitespace,
validatePercentage,
validateRegexp,
validateSlack,
Expand All @@ -17,6 +18,7 @@ export const customFormats = (jiraHost: string) => ({
noSpecialCharacters: validateNoSpecialCharacters,
// Permit empty string but disallow whitespace
noSpaces: /^$|^\S+$/,
noStartingOrTrailingWhitespace: validateNoStartingOrTrailingWhitespace,
validDuration: validateDuration,
validEmail: validateEmail,
validJiraTicket: validateJira,
Expand Down
5 changes: 5 additions & 0 deletions src/components/SpruceForm/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export const transformErrors = (errors: AjvError[]) =>
...error,
message: "Value should not contain spaces.",
};
case "noStartingOrTrailingWhitespace":
return {
...error,
message: "Value should not start or end with whitespace.",
};
case "validDuration":
return {
...error,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/projectSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const ProjectSettings: React.FC = () => {
projectData?.projectSettings?.projectRef?.repoRefId || identifier;

// Assign project type in order to show/hide elements that should only appear for repos, attached projects, etc.
let projectType;
let projectType: ProjectType;
if (isRepo) {
projectType = ProjectType.Repo;
} else if (projectData?.projectSettings?.projectRef?.repoRefId) {
Expand Down
1 change: 1 addition & 0 deletions src/pages/projectSettings/tabs/AccessTab/getFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const getFormSchema = (
title: "Username",
default: "",
minLength: 1,
format: "noStartingOrTrailingWhitespace",
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions src/pages/projectSettings/tabs/GeneralTab/getFormSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const getFormSchema = (
branch: {
type: "string" as "string",
title: "Branch Name",
format: "noStartingOrTrailingWhitespace",
},
}),
other: {
Expand All @@ -75,6 +76,7 @@ export const getFormSchema = (
displayName: {
type: "string" as "string",
title: "Display Name",
format: "noStartingOrTrailingWhitespace",
},
...(projectType !== ProjectType.Repo && {
identifier: {
Expand All @@ -96,10 +98,12 @@ export const getFormSchema = (
remotePath: {
type: "string" as "string",
title: "Config File",
format: "noStartingOrTrailingWhitespace",
},
spawnHostScriptPath: {
type: "string" as "string",
title: "Spawn Host Script Path",
format: "noStartingOrTrailingWhitespace",
},
versionControlEnabled: {
type: ["boolean", "null"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const getFormSchema = (
title: "Username",
default: "",
minLength: 1,
format: "noStartingOrTrailingWhitespace",
},
},
),
Expand All @@ -168,6 +169,7 @@ export const getFormSchema = (
title: "Team",
default: "",
minLength: 1,
format: "noStartingOrTrailingWhitespace",
},
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ export const getFormSchema = (
title: "Alias",
default: "",
minLength: 1,
format: "noStartingOrTrailingWhitespace",
},
childProjectIdentifier: {
type: "string" as "string",
title: "Project",
default: "",
minLength: 1,
format: "noStartingOrTrailingWhitespace",
},
parentAsModule: {
type: "string" as "string",
title: "Module",
format: "noStartingOrTrailingWhitespace",
},
status: {
type: "string" as "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const getFormSchema = (
title: "Config File",
minLength: 1,
default: "",
format: "noStartingOrTrailingWhitespace",
},
alias: {
type: "string" as "string",
Expand Down
2 changes: 2 additions & 0 deletions src/pages/projectSettings/tabs/PluginsTab/getFormSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const getFormSchema = (
createProject: {
type: "string" as "string",
title: "",
format: "noStartingOrTrailingWhitespace",
},
},
},
Expand Down Expand Up @@ -204,6 +205,7 @@ export const getFormSchema = (
default: "",
minLength: 1,
maxLength: 40,
format: "noStartingOrTrailingWhitespace",
},
urlTemplate: {
type: "string" as "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export const getFormSchema = (
title: "Project",
default: "",
minLength: 1,
format: "noStartingOrTrailingWhitespace",
},
configFile: {
type: "string" as "string",
title: "Config File",
default: "",
minLength: 1,
format: "noStartingOrTrailingWhitespace",
},
level: {
type: "string" as "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const getFormSchema = (
title: "Variable Name",
default: "",
minLength: 1,
format: "noStartingOrTrailingWhitespace",
},
varValue: {
type: "string" as "string",
Expand Down
11 changes: 11 additions & 0 deletions src/utils/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,24 @@ const validateNoSpecialCharacters = (str: string): boolean => {
return noSpecialCharacters.test(str);
};

/**
* `validateNoStartingOrTrailingWhitespace` tests if a provided string contains no starting or trailing whitespace
* @param str - The string to test.
* @returns - true if the string has no starting or trailing whitespace and false otherwise
*/
const validateNoStartingOrTrailingWhitespace = (str: string): boolean => {
const noStartingOrTrailingWhitespaceRegex = /^(?! ).*(?<! )$/;
return noStartingOrTrailingWhitespaceRegex.test(str);
};

export {
allowedSymbols,
validateDuration,
validateEmail,
validateJira,
validateJiraURL,
validateNoSpecialCharacters,
validateNoStartingOrTrailingWhitespace,
validateObjectId,
validatePercentage,
validateRegexp,
Expand Down
15 changes: 15 additions & 0 deletions src/utils/validators/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
validateJira,
validateJiraURL,
validateNoSpecialCharacters,
validateNoStartingOrTrailingWhitespace,
validateObjectId,
validateRegexp,
validateSlack,
Expand All @@ -24,6 +25,20 @@ describe("validateNoSpecialCharacters", () => {
});
});

describe("validateNoStartingOrTrailingWhitespace", () => {
it("returns true if string has no starting or trailing whitespace", () => {
expect(validateNoStartingOrTrailingWhitespace("")).toBe(true);
expect(validateNoStartingOrTrailingWhitespace("a")).toBe(true);
expect(validateNoStartingOrTrailingWhitespace("helloworld")).toBe(true);
expect(validateNoStartingOrTrailingWhitespace(" helloWorld123")).toBe(
false,
);
expect(validateNoStartingOrTrailingWhitespace("helloWorld123 ")).toBe(
false,
);
});
});

describe("validateObjectId", () => {
it("validates object ids", () => {
expect(validateObjectId("5f74d99ab2373627c047c5e5")).toBeTruthy();
Expand Down

0 comments on commit 1bbd708

Please sign in to comment.