Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add max walk interval validation, fix clicking on group names, add max group name length validation #47

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function GroupsList() {

const groupsList = groups.map((group) => (
<SingleGroup data-test="sc4snmp:group" onClick={(event) => (clickGroupHandler(event, group._id, group.groupName, 1))} style={{ backgroundColor: (selectedGroup[group._id]) ? "#E1E6EB" : "#FFFFF" }} key={createDOMID()}>
<P>
<P onClick={(event) => (clickGroupHandler(event, group._id, group.groupName, 1))}>
{group.groupName}
</P>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const validateInventoryAndGroup = (validationObj) => {
errors.groupName.push("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.");
}
if (validationObj.groupName.length > 22){
isValid = false;
errors.groupName.push("Group name can have maximum length of 22 characters.");
}
}

// Validate address
Expand Down Expand Up @@ -96,9 +100,9 @@ const validateInventoryAndGroup = (validationObj) => {

// Validate Walk Interval
if ("walkInterval" in validationObj){
if (!(Number.isInteger(validationObj.walkInterval) && validationObj.walkInterval >= 1800)){
if (!(Number.isInteger(validationObj.walkInterval)) || (validationObj.walkInterval < 1800 || validationObj.walkInterval > 604800)){
isValid = false;
errors.walkInterval.push("Walk Interval number must be an integer greater than or equal 1800");
errors.walkInterval.push("Walk Interval number must be an integer in range 1800-604800.");
}
}

Expand Down
10 changes: 10 additions & 0 deletions frontend/packages/manager/src/tests/AddGroupModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ describe("AddGroupModal", () => {
"numbers and two special characters: '-' and '_'. No spaces are allowed. Group name can't start with a number.")).toBeInTheDocument();
})

it("Test too long 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: "group1111111aaaaaaaaaaaa"}})
fireEvent.click(submitButton);
expect(screen.queryByText("Group name can have maximum length of 22 characters.")).toBeInTheDocument();
})

it("Test no group name provided", () => {
renderModal();
const submitButton = screen.getByDataTest("sc4snmp:form:submit-form-button");
Expand Down
21 changes: 19 additions & 2 deletions frontend/packages/manager/src/tests/AddInventoryModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,38 @@ describe("AddInventoryModal", () => {
fireEvent.click(submitButton);
await sleep(10);
expect(screen.queryByText("Address or host name is required")).not.toBeInTheDocument();
expect(screen.queryByText("Walk Interval number must be an integer greater than or equal 1800")).toBeInTheDocument();
expect(screen.queryByText("Walk Interval number must be an integer in range 1800-604800.")).toBeInTheDocument();

fireEvent.change(addressInput, {target: {value: ""}})
fireEvent.change(walkIntervalInput, {target: {value: 1900}});
fireEvent.click(submitButton);
await sleep(10);
expect(screen.queryByText("Address or host name is required")).toBeInTheDocument();
expect(screen.queryByText("Walk Interval number must be an integer greater than or equal 1800")).not.toBeInTheDocument();
expect(screen.queryByText("Walk Interval number must be an integer in range 1800-604800.")).not.toBeInTheDocument();

fireEvent.click(groupButton)
fireEvent.click(submitButton);
await sleep(10);
expect(screen.queryByText("Group is required")).toBeInTheDocument();
})

it("Test walk interval above 604800", async () => {
axios.get.mockResolvedValueOnce({data:[]});
await act( async () => renderModal());
const submitButton = screen.getByDataTest("sc4snmp:form:submit-form-button");
const hostButton = screen.getByDataTest("sc4snmp:form:inventory-type-host");
const groupButton = screen.getByDataTest("sc4snmp:form:inventory-type-group");
const addressInput = screen.getByDataTest('sc4snmp:form:group-ip-input').querySelector("input");
const walkIntervalInput = screen.getByDataTest('sc4snmp:form:walk-interval-input').querySelector("input");

fireEvent.change(addressInput, {target: {value: "group1"}})
fireEvent.change(walkIntervalInput, {target: {value: 604801}});
fireEvent.click(hostButton);
fireEvent.click(submitButton);
await sleep(10);
expect(screen.queryByText("Walk Interval number must be an integer in range 1800-604800.")).toBeInTheDocument();
})

it("Test wrong group name, no port and wrong port", async () => {
axios.get.mockResolvedValueOnce({data:[]});
await act( async () => renderModal());
Expand Down
Loading