Skip to content

Commit

Permalink
MGMT-17130: Add correct id to <HelperItem> components when shown erro…
Browse files Browse the repository at this point in the history
…rs (#2517) (#2527)

* Add id to HelperItem components to indicate errors

* Add tests for validations in New cluster page

* Changing id in HelperItem components to show errors
  • Loading branch information
ammont82 authored Mar 20, 2024
1 parent c2b8b33 commit 71ab4fb
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe(`Assisted Installer Static IP Network wide Configuration`, () => {
staticIpPage.dualStackNetworking().click();

testIpv4AndIpv6Addresses.forEach((dnsEntry) => {
staticIpPage.networkWideDns().type(dnsEntry);
staticIpPage.networkWideDns().clear().type(dnsEntry);
commonActions.getDNSErrorMessage().should('not.exist');
staticIpPage.networkWideDns().clear();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { NewClusterPage } from '../../../views/pages/NewClusterPage';
import { ClusterDetailsForm } from '../../../views/forms/ClusterDetails/ClusterDetailsForm';
import { clusterDetailsPage } from '../../../views/clusterDetails';

describe('Create a new cluster and show correct validations for every field', () => {
const setTestStartSignal = (activeSignal: string) => {
cy.setTestEnvironment({
activeSignal,
activeScenario: 'AI_CREATE_MULTINODE',
});
};
before(() => setTestStartSignal(''));

beforeEach(() => {
setTestStartSignal('');
NewClusterPage.visit();
ClusterDetailsForm.init();
});

it('Base Name (Invalid)', () => {
const invalidDnsDomain = 'iamnotavaliddnsdomain-iamnotavaliddnsdomain-iamnotavaliddnsdomain';
clusterDetailsPage.inputClusterName();
clusterDetailsPage.inputBaseDnsDomain(invalidDnsDomain);
clusterDetailsPage.clickClusterDetailsBody();
clusterDetailsPage.validateInputDnsDomainFieldHelper(
`Every single host component in the base domain name cannot contain more than 63 characters and must not contain spaces.`,
);
});

it('Base Name (Field Not Empty)', () => {
const emptyDns = ' ';
clusterDetailsPage.inputBaseDnsDomain(emptyDns);
clusterDetailsPage.clickClusterDetailsBody();
clusterDetailsPage.validateInputDnsDomainFieldHelper(
`Every single host component in the base domain name cannot contain more than 63 characters and must not contain spaces.`,
);
});

it('Pull secret (Field not empty)', () => {
const emptyPullSecret = '{}';
let pullSecretError = 'Required.';
clusterDetailsPage.inputPullSecret(emptyPullSecret);
clusterDetailsPage.clearPullSecret();
clusterDetailsPage.validateInputPullSecretFieldHelper(pullSecretError);
});

it('Pull Secret (Malformed)', () => {
const malformedJsonPullSecret = '{{}}';
let pullSecretError =
"Invalid pull secret format. You must use your Red Hat account's pull secret";
clusterDetailsPage.inputPullSecret(malformedJsonPullSecret);
clusterDetailsPage.clickClusterDetailsBody();
clusterDetailsPage.validateInputPullSecretFieldHelper(pullSecretError);
});

it('Pull secret (Invalid entry)', () => {
const invalidPullSecret = '{"invalid": "pull-secret"}';
// Need to set valid name and DNS
clusterDetailsPage.inputClusterName();
clusterDetailsPage.inputBaseDnsDomain();
clusterDetailsPage.inputPullSecret(invalidPullSecret);

const errorSuffix = Cypress.env('OCM_USER')
? 'Learn more about pull secrets and view examples'
: "A Red Hat account's pull secret can be found in";
clusterDetailsPage.clickClusterDetailsBody();
clusterDetailsPage.validateInputPullSecretFieldHelper(
`Invalid pull secret format. You must use your Red Hat account's pull secret`,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ Cypress.env(
'staticIpNetworkConfigFieldId',
'#form-radio-hostsNetworkConfigurationType-static-field',
);
Cypress.env('baseDnsDomainFieldHelperErrorId', '#form-input-baseDnsDomain-field-helper-error');
Cypress.env('pullSecretFieldHelperErrorId', '#form-input-pullSecret-field-helper-error');
18 changes: 15 additions & 3 deletions libs/ui-lib-tests/cypress/views/clusterDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export const clusterDetailsPage = {
getPullSecretFieldHelper: () => {
return cy.get(Cypress.env('pullSecretFieldHelperId'));
},
inputPullSecret: () => {
inputPullSecret: (pullSecretValue = pullSecret) => {
clusterDetailsPage.getPullSecret().clear();
cy.pasteText(Cypress.env('pullSecretFieldId'), pullSecret);
clusterDetailsPage.getPullSecret().should('contain.text', pullSecret);
cy.pasteText(Cypress.env('pullSecretFieldId'), pullSecretValue);
clusterDetailsPage.getPullSecret().should('contain.text', pullSecretValue);
},
checkAiTechSupportLevel: () => {
cy.get(Cypress.env('assistedInstallerSupportLevel'))
Expand Down Expand Up @@ -126,4 +126,16 @@ export const clusterDetailsPage = {
getExternalPlatformIntegrationStaticField: () => {
return cy.get('#form-static-platform-field');
},
clickClusterDetailsBody: () => {
cy.get('.pf-v5-l-grid').click();
},
validateInputDnsDomainFieldHelper: (msg) => {
cy.get(Cypress.env('baseDnsDomainFieldHelperErrorId')).should('contain', msg);
},
clearPullSecret: () => {
cy.get(Cypress.env('pullSecretFieldId')).clear().blur();
},
validateInputPullSecretFieldHelper: (msg) => {
cy.get(Cypress.env('pullSecretFieldHelperErrorId')).should('contain', msg);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ const SecurityFields = ({
{errorMsg && (
<FormHelperText>
<HelperText>
<HelperTextItem variant={touched && errorMsg ? 'error' : 'default'}>
<HelperTextItem
variant={touched && errorMsg ? 'error' : 'default'}
id={errorMsg ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMsg ? errorMsg : ''}
</HelperTextItem>
</HelperText>
Expand Down
1 change: 1 addition & 0 deletions libs/ui-lib/lib/common/components/ui/StaticTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const StaticField: React.FC<StaticFieldProps> = ({
<HelperTextItem
icon={<ExclamationCircleIcon />}
variant={isValid ? 'default' : 'error'}
id={isValid ? `${fieldId}-helper` : `${fieldId}-helper-error`}
>
{isValid ? helperText : helperTextInvalid}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const CertificatesUploadField: React.FC<UploadFieldProps> = ({
<HelperTextItem
icon={errorMessage && <ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : helperText}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ const CheckboxField: React.FC<CheckboxFieldProps> = ({
{errorMessage && (
<FormHelperText>
<HelperText>
<HelperTextItem icon={<ExclamationCircleIcon />} variant="error">
<HelperTextItem
icon={<ExclamationCircleIcon />}
variant="error"
id={`${fieldId}-helper-error`}
>
{errorMessage}
</HelperTextItem>
</HelperText>
Expand Down
1 change: 1 addition & 0 deletions libs/ui-lib/lib/common/components/ui/formik/CodeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const CodeField = ({
<HelperTextItem
icon={errorMessage && <ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : helperText}
</HelperTextItem>
Expand Down
1 change: 1 addition & 0 deletions libs/ui-lib/lib/common/components/ui/formik/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const InputField: React.FC<
<HelperTextItem
icon={errorMessage && <ExclamationCircleIcon />}
variant={showErrorMessage ? 'error' : 'default'}
id={showErrorMessage && !isValid ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{showErrorMessage ? errorMessage : helperText}
</HelperTextItem>
Expand Down
1 change: 1 addition & 0 deletions libs/ui-lib/lib/common/components/ui/formik/LabelField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const LabelField: React.FC<LabelFieldProps> = ({
<HelperTextItem
icon={errorMessage && <ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : helperText}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const MultiSelectField: React.FC<MultiSelectFieldProps> = ({
<HelperTextItem
icon={<ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : hText}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const NumberInputField: React.FC<NumberInputFieldProps> = React.forwardRef(
<HelperTextItem
icon={errorMessage && <ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : helperText}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ const RichInputField: React.FC<RichInputFieldPropsProps> = React.forwardRef(
{helperText && (
<FormHelperText>
<HelperText>
<HelperTextItem variant={isValid ? 'default' : 'error'}>{helperText}</HelperTextItem>
<HelperTextItem
variant={isValid ? 'default' : 'error'}
id={isValid ? `${fieldId}-helper` : `${fieldId}-helper-error`}
>
{helperText}
</HelperTextItem>
</HelperText>
</FormHelperText>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const SelectField: React.FC<SelectFieldProps> = ({
<HelperTextItem
icon={<ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : hText}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const SwitchField: React.FC<SwitchFieldProps> = ({
<HelperTextItem
icon={<ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : hText}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const TextAreaField: React.FC<TextAreaFieldProps> = ({
<HelperTextItem
icon={errorMessage && <ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : helperText}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const UploadField: React.FC<UploadFieldProps> = ({
<HelperTextItem
icon={errorMessage && <ExclamationCircleIcon />}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : helperText}
</HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ const MachineNetwork: React.FC<{ fieldName: string; protocolVersion: ProtocolVer
const cidr = getMachineNetworkCidr(value);
return getHumanizedSubnetRange(getAddressObject(cidr, protocolVersion));
}, [value, protocolVersion, errorMessage]);
const fieldId = getFieldId(`${fieldName}`, 'input');
return (
<FormGroup
labelIcon={
<PopoverIcon noVerticalAlign bodyContent="The range of IP addresses of the hosts." />
}
label="Machine network"
fieldId={getFieldId(`${fieldName}`, 'input')}
fieldId={fieldId}
isRequired
className="machine-network"
>
Expand Down Expand Up @@ -118,6 +119,7 @@ const MachineNetwork: React.FC<{ fieldName: string; protocolVersion: ProtocolVer
<HelperTextItem
icon={errorMessage ? <ExclamationCircleIcon /> : null}
variant={errorMessage ? 'error' : 'default'}
id={errorMessage ? `${fieldId}-helper-error` : `${fieldId}-helper`}
>
{errorMessage ? errorMessage : machineNetworkHelptext}
</HelperTextItem>
Expand Down

0 comments on commit 71ab4fb

Please sign in to comment.