mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
add tests for number validation
This commit is contained in:
@@ -85,3 +85,18 @@ describe("test mail validation", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("test number validation", () => {
|
||||||
|
it("should return false", () => {
|
||||||
|
const invalid = ["1a", "35gu", "dj6", "45,5", "test"];
|
||||||
|
for (let number of invalid) {
|
||||||
|
expect(validator.isNumberValid(number)).toBe(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("should return true", () => {
|
||||||
|
const valid = ["1", "35", "2", "235", "34.4"];
|
||||||
|
for (let number of valid) {
|
||||||
|
expect(validator.isNumberValid(number)).toBe(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ type Props = {
|
|||||||
type State = {
|
type State = {
|
||||||
config: Config,
|
config: Config,
|
||||||
showNotification: boolean,
|
showNotification: boolean,
|
||||||
loginAttemptError: boolean
|
error: {
|
||||||
|
loginAttemptLimitTimeout: boolean,
|
||||||
|
loginAttemptLimit: boolean
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigForm extends React.Component<Props, State> {
|
class ConfigForm extends React.Component<Props, State> {
|
||||||
@@ -54,7 +57,10 @@ class ConfigForm extends React.Component<Props, State> {
|
|||||||
_links: {}
|
_links: {}
|
||||||
},
|
},
|
||||||
showNotification: false,
|
showNotification: false,
|
||||||
loginAttemptError: true
|
error: {
|
||||||
|
loginAttemptLimitTimeout: false,
|
||||||
|
loginAttemptLimit: false
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,25 +157,40 @@ class ConfigForm extends React.Component<Props, State> {
|
|||||||
<SubmitButton
|
<SubmitButton
|
||||||
loading={loading}
|
loading={loading}
|
||||||
label={t("config-form.submit")}
|
label={t("config-form.submit")}
|
||||||
disabled={!configUpdatePermission || !this.isValid()}
|
disabled={!configUpdatePermission || this.hasError()}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
onChange = (isValid: boolean, changedValue: any, name: string) => {
|
onChange = (isValid: boolean, changedValue: any, name: string) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
...this.state,
|
...this.state,
|
||||||
config: {
|
config: {
|
||||||
...this.state.config,
|
...this.state.config,
|
||||||
[name]: changedValue
|
[name]: changedValue
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
...this.state.error,
|
||||||
|
[name]: !isValid
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
isValid = () => {
|
hasError = () => {
|
||||||
return this.state.loginAttemptError;
|
console.log("loginAttemtLimit " + this.state.error.loginAttemptLimit);
|
||||||
|
console.log(
|
||||||
|
"loginAttemtLimitTimeout " + this.state.error.loginAttemptLimitTimeout
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
this.state.error.loginAttemptLimit ||
|
||||||
|
this.state.error.loginAttemptLimitTimeout
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
this.state.error.loginAttemptLimit ||
|
||||||
|
this.state.error.loginAttemptLimitTimeout
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
onClose = () => {
|
onClose = () => {
|
||||||
|
|||||||
@@ -64,7 +64,11 @@ class LoginAttempt extends React.Component<Props, State> {
|
|||||||
...this.state,
|
...this.state,
|
||||||
loginAttemptLimitError: !validator.isNumberValid(value)
|
loginAttemptLimitError: !validator.isNumberValid(value)
|
||||||
});
|
});
|
||||||
this.props.onChange(this.loginAttemptIsValid(), value, "loginAttemptLimit");
|
this.props.onChange(
|
||||||
|
validator.isNumberValid(value),
|
||||||
|
value,
|
||||||
|
"loginAttemptLimit"
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleLoginAttemptLimitTimeoutChange = (value: string) => {
|
handleLoginAttemptLimitTimeoutChange = (value: string) => {
|
||||||
@@ -73,18 +77,11 @@ class LoginAttempt extends React.Component<Props, State> {
|
|||||||
loginAttemptLimitTimeoutError: !validator.isNumberValid(value)
|
loginAttemptLimitTimeoutError: !validator.isNumberValid(value)
|
||||||
});
|
});
|
||||||
this.props.onChange(
|
this.props.onChange(
|
||||||
this.loginAttemptIsValid(),
|
validator.isNumberValid(value),
|
||||||
value,
|
value,
|
||||||
"loginAttemptLimitTimeout"
|
"loginAttemptLimitTimeout"
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
loginAttemptIsValid = () => {
|
|
||||||
return (
|
|
||||||
this.state.loginAttemptLimitError ||
|
|
||||||
this.state.loginAttemptLimitTimeoutError
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default translate("config")(LoginAttempt);
|
export default translate("config")(LoginAttempt);
|
||||||
|
|||||||
Reference in New Issue
Block a user