Use NumberInput instead of input (#3961)

This commit is contained in:
Erik Jan de Wit 2022-12-14 02:45:13 -05:00 committed by GitHub
parent bd1e62a1ef
commit a40deb7073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 39 deletions

View file

@ -34,9 +34,12 @@ describe("SAML identity provider test", () => {
describe("SAML identity provider creation", () => { describe("SAML identity provider creation", () => {
const samlProviderName = "saml"; const samlProviderName = "saml";
beforeEach(() => { before(() => {
keycloakBefore(); keycloakBefore();
loginPage.logIn(); loginPage.logIn();
});
beforeEach(() => {
sidebarPage.goToIdentityProviders(); sidebarPage.goToIdentityProviders();
}); });

View file

@ -224,15 +224,15 @@ export default class ProviderSAMLSettings extends PageObject {
public assertTextFields() { public assertTextFields() {
cy.findByTestId(this.allowedClockSkew) cy.findByTestId(this.allowedClockSkew)
.click() .find("input")
.type("not a number") .should("have.value", 0)
.should("be.empty") .clear()
.type("111"); .type("111");
cy.findByTestId(this.attributeConsumingServiceIndex) cy.findByTestId(this.attributeConsumingServiceIndex)
.click() .find("input")
.type("not a number") .should("have.value", 0)
.should("be.empty") .clear()
.type("111"); .type("111");
cy.findByTestId(this.attributeConsumingServiceName).click().type("name"); cy.findByTestId(this.attributeConsumingServiceName).click().type("name");

View file

@ -4,6 +4,7 @@ import { Controller, useFormContext, useWatch } from "react-hook-form";
import { import {
ExpandableSection, ExpandableSection,
FormGroup, FormGroup,
NumberInput,
Select, Select,
SelectOption, SelectOption,
SelectVariant, SelectVariant,
@ -472,15 +473,31 @@ const Fields = ({ readOnly }: DescriptorSettingsProps) => {
fieldId="allowedClockSkew" fieldId="allowedClockSkew"
helperTextInvalid={t("common:required")} helperTextInvalid={t("common:required")}
> >
<KeycloakTextInput <Controller
type="number"
min="0"
max="2147483"
id="allowedClockSkew"
data-testid="allowedClockSkew"
name="config.allowedClockSkew" name="config.allowedClockSkew"
ref={register} defaultValue={0}
isReadOnly={readOnly} control={control}
render={({ onChange, value }) => {
const v = Number(value);
return (
<NumberInput
data-testid="allowedClockSkew"
inputName="allowedClockSkew"
min={0}
max={2147483}
value={v}
readOnly
onPlus={() => onChange(v + 1)}
onMinus={() => onChange(v - 1)}
onChange={(event) => {
const value = Number(
(event.target as HTMLInputElement).value
);
onChange(value < 0 ? 0 : value);
}}
/>
);
}}
/> />
</FormGroup> </FormGroup>
@ -495,15 +512,31 @@ const Fields = ({ readOnly }: DescriptorSettingsProps) => {
fieldId="attributeConsumingServiceIndex" fieldId="attributeConsumingServiceIndex"
helperTextInvalid={t("common:required")} helperTextInvalid={t("common:required")}
> >
<KeycloakTextInput <Controller
type="number"
min="0"
max="65535"
id="attributeConsumingServiceIndex"
data-testid="attributeConsumingServiceIndex"
name="config.attributeConsumingServiceIndex" name="config.attributeConsumingServiceIndex"
ref={register} defaultValue={0}
isReadOnly={readOnly} control={control}
render={({ onChange, value }) => {
const v = Number(value);
return (
<NumberInput
data-testid="attributeConsumingServiceIndex"
inputName="attributeConsumingServiceIndex"
min={0}
max={2147483}
value={v}
readOnly
onPlus={() => onChange(v + 1)}
onMinus={() => onChange(v - 1)}
onChange={(event) => {
const value = Number(
(event.target as HTMLInputElement).value
);
onChange(value < 0 ? 0 : value);
}}
/>
);
}}
/> />
</FormGroup> </FormGroup>

View file

@ -91,23 +91,29 @@ export const ExtendedNonDiscoverySettings = () => {
> >
<Controller <Controller
name="config.allowedClockSkew" name="config.allowedClockSkew"
control={control}
defaultValue={0} defaultValue={0}
render={({ onChange, value }) => ( control={control}
<NumberInput render={({ onChange, value }) => {
value={value} const v = Number(value);
data-testid="allowedClockSkew" return (
onMinus={() => onChange(value - 1)} <NumberInput
onChange={onChange} data-testid="allowedClockSkew"
onPlus={() => onChange(value + 1)} inputName="allowedClockSkew"
inputName="input" min={0}
inputAriaLabel={t("allowedClockSkew")} max={2147483}
minusBtnAriaLabel={t("common:minus")} value={v}
plusBtnAriaLabel={t("common:plus")} readOnly
min={0} onPlus={() => onChange(v + 1)}
unit={t("common:times.seconds")} onMinus={() => onChange(v - 1)}
/> onChange={(event) => {
)} const value = Number(
(event.target as HTMLInputElement).value
);
onChange(value < 0 ? 0 : value);
}}
/>
);
}}
/> />
</FormGroup> </FormGroup>
<TextField field="config.forwardParameters" label="forwardParameters" /> <TextField field="config.forwardParameters" label="forwardParameters" />