Skip to content

Commit

Permalink
run validation with updated resource values
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed Saud committed Jul 18, 2022
1 parent da444ef commit 2b6e9cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions integration-tests/support/pages/ComponentsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ComponentPage extends AbstractWizardPage {

setCpuByButton(value: number, unit: CPUUnit) {
cy.contains(`.pf-c-dropdown__toggle-text`, 'cores').parent().click();
cy.contains('li', new RegExp(`^${unit}$`)).click();
cy.contains('li', new RegExp(`^${unit}$`)).trigger('click');

cy.get(ComponentsPagePO.cpuInput).then(($cpu) => {
const diff = value - Number($cpu.val());
Expand All @@ -44,7 +44,7 @@ export class ComponentPage extends AbstractWizardPage {
const button = diff > 0 ? ComponentsPagePO.cpuPlusButton : ComponentsPagePO.cpuMinusButton;

for (let i = 0; i < Math.abs(diff); i++) {
cy.get(button).click();
cy.get(button).trigger('click');
}
});

Expand Down
5 changes: 4 additions & 1 deletion src/shared/components/formik-fields/ResourceLimitField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { FormGroup } from '@patternfly/react-core';
import { useField, useFormikContext, FormikValues } from 'formik';
import { set } from 'lodash-es';
import { RequestSizeInput } from '../../utils';
import { ResourceLimitFieldProps } from './field-types';
import { getFieldId } from './field-utils';
Expand All @@ -14,7 +15,7 @@ const ResourceLimitField: React.FC<ResourceLimitFieldProps> = ({
}) => {
const [field, { touched, error }] = useField(props.name);
const [fieldUnit] = useField(unitName);
const { setFieldValue, setFieldTouched } = useFormikContext<FormikValues>();
const { setFieldValue, setFieldTouched, values, validateForm } = useFormikContext<FormikValues>();
const fieldId = getFieldId(props.name, 'resource-limit');
const isValid = !(touched && error);
const errorMessage = !isValid ? error : '';
Expand All @@ -34,6 +35,8 @@ const ResourceLimitField: React.FC<ResourceLimitFieldProps> = ({
setFieldValue(props.name, val.value);
setFieldTouched(props.name, true);
setFieldValue(unitName, val.unit);
// run validation manually so that formik uses the latest value
validateForm(set(values, props.name, val.value));
}}
dropdownUnits={unitOptions}
defaultRequestSizeUnit={fieldUnit.value}
Expand Down

0 comments on commit 2b6e9cc

Please sign in to comment.