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", () => {
const samlProviderName = "saml";
beforeEach(() => {
before(() => {
keycloakBefore();
loginPage.logIn();
});
beforeEach(() => {
sidebarPage.goToIdentityProviders();
});

View file

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

View file

@ -4,6 +4,7 @@ import { Controller, useFormContext, useWatch } from "react-hook-form";
import {
ExpandableSection,
FormGroup,
NumberInput,
Select,
SelectOption,
SelectVariant,
@ -472,15 +473,31 @@ const Fields = ({ readOnly }: DescriptorSettingsProps) => {
fieldId="allowedClockSkew"
helperTextInvalid={t("common:required")}
>
<KeycloakTextInput
type="number"
min="0"
max="2147483"
id="allowedClockSkew"
data-testid="allowedClockSkew"
<Controller
name="config.allowedClockSkew"
ref={register}
isReadOnly={readOnly}
defaultValue={0}
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>
@ -495,15 +512,31 @@ const Fields = ({ readOnly }: DescriptorSettingsProps) => {
fieldId="attributeConsumingServiceIndex"
helperTextInvalid={t("common:required")}
>
<KeycloakTextInput
type="number"
min="0"
max="65535"
id="attributeConsumingServiceIndex"
data-testid="attributeConsumingServiceIndex"
<Controller
name="config.attributeConsumingServiceIndex"
ref={register}
isReadOnly={readOnly}
defaultValue={0}
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>

View file

@ -91,23 +91,29 @@ export const ExtendedNonDiscoverySettings = () => {
>
<Controller
name="config.allowedClockSkew"
control={control}
defaultValue={0}
render={({ onChange, value }) => (
<NumberInput
value={value}
data-testid="allowedClockSkew"
onMinus={() => onChange(value - 1)}
onChange={onChange}
onPlus={() => onChange(value + 1)}
inputName="input"
inputAriaLabel={t("allowedClockSkew")}
minusBtnAriaLabel={t("common:minus")}
plusBtnAriaLabel={t("common:plus")}
min={0}
unit={t("common:times.seconds")}
/>
)}
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>
<TextField field="config.forwardParameters" label="forwardParameters" />