mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45: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 = {
|
||||
config: Config,
|
||||
showNotification: boolean,
|
||||
loginAttemptError: boolean
|
||||
error: {
|
||||
loginAttemptLimitTimeout: boolean,
|
||||
loginAttemptLimit: boolean
|
||||
}
|
||||
};
|
||||
|
||||
class ConfigForm extends React.Component<Props, State> {
|
||||
@@ -54,7 +57,10 @@ class ConfigForm extends React.Component<Props, State> {
|
||||
_links: {}
|
||||
},
|
||||
showNotification: false,
|
||||
loginAttemptError: true
|
||||
error: {
|
||||
loginAttemptLimitTimeout: false,
|
||||
loginAttemptLimit: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -151,25 +157,40 @@ class ConfigForm extends React.Component<Props, State> {
|
||||
<SubmitButton
|
||||
loading={loading}
|
||||
label={t("config-form.submit")}
|
||||
disabled={!configUpdatePermission || !this.isValid()}
|
||||
disabled={!configUpdatePermission || this.hasError()}
|
||||
/>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
onChange = (isValid: boolean, changedValue: any, name: string) => {
|
||||
this.setState({
|
||||
...this.state,
|
||||
config: {
|
||||
...this.state.config,
|
||||
[name]: changedValue
|
||||
},
|
||||
error: {
|
||||
...this.state.error,
|
||||
[name]: !isValid
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
isValid = () => {
|
||||
return this.state.loginAttemptError;
|
||||
hasError = () => {
|
||||
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 = () => {
|
||||
|
||||
@@ -64,7 +64,11 @@ class LoginAttempt extends React.Component<Props, State> {
|
||||
...this.state,
|
||||
loginAttemptLimitError: !validator.isNumberValid(value)
|
||||
});
|
||||
this.props.onChange(this.loginAttemptIsValid(), value, "loginAttemptLimit");
|
||||
this.props.onChange(
|
||||
validator.isNumberValid(value),
|
||||
value,
|
||||
"loginAttemptLimit"
|
||||
);
|
||||
};
|
||||
|
||||
handleLoginAttemptLimitTimeoutChange = (value: string) => {
|
||||
@@ -73,18 +77,11 @@ class LoginAttempt extends React.Component<Props, State> {
|
||||
loginAttemptLimitTimeoutError: !validator.isNumberValid(value)
|
||||
});
|
||||
this.props.onChange(
|
||||
this.loginAttemptIsValid(),
|
||||
validator.isNumberValid(value),
|
||||
value,
|
||||
"loginAttemptLimitTimeout"
|
||||
);
|
||||
};
|
||||
|
||||
loginAttemptIsValid = () => {
|
||||
return (
|
||||
this.state.loginAttemptLimitError ||
|
||||
this.state.loginAttemptLimitTimeoutError
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default translate("config")(LoginAttempt);
|
||||
|
||||
Reference in New Issue
Block a user