Skip to content

Commit

Permalink
fix: group name can't start with a number (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekzyla authored Aug 10, 2023
1 parent 9edebff commit 2fc2ee6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function ProfilesList() {
.then(function (response) {
if ('message' in response.data){
ErrCtx.setOpen(true);
ErrCtx.setErrorType("error");
ErrCtx.setErrorType("info");
ErrCtx.setMessage(response.data.message);
}
ProfCtx.makeProfilesChange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const validateInventoryAndGroup = (validationObj) => {
if (validationObj.groupName.length === 0){
errors.groupName.push("Group name is required");
isValid = false;
}else if (!validationObj.groupName.match(/^[a-zA-Z0-9_-]+$/)){
}else if (!validationObj.groupName.match(/^[a-zA-Z0-9_-]+$/) || validationObj.groupName.match(/^[0-9].*$/)){
isValid = false;
errors.groupName.push("Group name can consist only of upper and lower english letters, " +
"numbers and two special characters: '-' and '_'. No spaces are allowed.");
"numbers and two special characters: '-' and '_'. No spaces are allowed. Group name can't start with a number.");
}
}

Expand Down
11 changes: 9 additions & 2 deletions frontend/packages/manager/src/tests/AddGroupModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ function renderModal(){
)
}

const sleep = ms => new Promise(r => setTimeout(r, ms));

describe("AddGroupModal", () => {
it("Test wrong group name", () => {
it("Test wrong group name", async () => {
renderModal();
const submitButton = screen.getByDataTest("sc4snmp:form:submit-form-button");
const groupNameInput = screen.getByDataTest('sc4snmp:form:group-name-input').querySelector("input");

fireEvent.change(groupNameInput, {target: {value: "gro?up1"}})
fireEvent.click(submitButton);
expect(screen.queryByText("Group name can consist only of upper and lower english letters, " +
"numbers and two special characters: '-' and '_'. No spaces are allowed.")).toBeInTheDocument();
"numbers and two special characters: '-' and '_'. No spaces are allowed. Group name can't start with a number.")).toBeInTheDocument();

await sleep(5);
fireEvent.change(groupNameInput, {target: {value: "1group1"}})
fireEvent.click(submitButton);
expect(screen.queryByText("Group name can consist only of upper and lower english letters, " +
"numbers and two special characters: '-' and '_'. No spaces are allowed. Group name can't start with a number.")).toBeInTheDocument();
})

it("Test no group name provided", () => {
Expand Down

0 comments on commit 2fc2ee6

Please sign in to comment.