Skip to content

Commit

Permalink
Merge branch 'master' into MGMT-17121-cluster-name-not-shown-validati…
Browse files Browse the repository at this point in the history
…on-with-illegal-characters
  • Loading branch information
ammont82 authored Mar 8, 2024
2 parents 65c8267 + c34b6c7 commit 6dc1e66
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 28 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
@@ -1,12 +1,6 @@
import * as React from 'react';
import { useFormikContext } from 'formik';
import {
Checkbox,
FormGroup,
FormHelperText,
HelperText,
HelperTextItem,
} from '@patternfly/react-core';
import { Checkbox, FormGroup, HelperText, HelperTextItem } from '@patternfly/react-core';

import { RenderIf } from '../ui/RenderIf';
import { getFieldId, TextAreaField, trimSshPublicKey, ExternalLink } from '../ui';
Expand Down Expand Up @@ -46,11 +40,9 @@ const SecurityFields = ({
//clusterSshKey updating causes the textarea to disappear when the user clears it to edit it
const defaultShareSshKey = !!imageSshKey && (clusterSshKey === imageSshKey || !clusterSshKey);
const [shareSshKey, setShareSshKey] = React.useState(defaultShareSshKey);
const { values, setFieldValue, errors, touched } =
const { values, setFieldValue } =
useFormikContext<Pick<NetworkConfigurationValues, 'sshPublicKey'>>();

const errorMsg = errors.sshPublicKey;

const handleSshKeyBlur = () => {
if (values.sshPublicKey) {
setFieldValue('sshPublicKey', trimSshPublicKey(values.sshPublicKey));
Expand Down Expand Up @@ -90,15 +82,6 @@ const SecurityFields = ({
isDisabled={isDisabled}
/>
</RenderIf>
{errorMsg && (
<FormHelperText>
<HelperText>
<HelperTextItem variant={touched && errorMsg ? 'error' : 'default'}>
{errorMsg ? errorMsg : ''}
</HelperTextItem>
</HelperText>
</FormHelperText>
)}
</FormGroup>
</>
);
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 @@ -162,7 +162,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
11 changes: 9 additions & 2 deletions libs/ui-lib/lib/common/components/ui/formik/UploadField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ const UploadField: React.FC<UploadFieldProps> = ({
type="text"
value={field.value as string}
filename={filename}
onDataChange={(_event, file: string) => setValue(file)}
onTextChange={(_event, file: string) => setValue(file)}
onDataChange={(_event, file: string) => {
setValue(file);
setTouched(true);
}}
onTextChange={(_event, file: string) => {
setValue(file);
setTouched(true);
}}
onFileInputChange={(_event, file) => {
setFilename(file.name);
setTouched(true);
Expand Down Expand Up @@ -103,6 +109,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 6dc1e66

Please sign in to comment.