Skip to content

Commit

Permalink
fix: ds-436 Add OCP default port in form logic (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolearagao authored Oct 16, 2024
1 parent 6a08ef7 commit c5c83b7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ exports[`SourceForm should render a basic component: basic 1`] = `
value=""
/>
<HelperText>
Default port is 443
Default port is
443
</HelperText>
</FormGroup>
</React.Fragment>
Expand Down Expand Up @@ -200,6 +201,59 @@ exports[`SourceForm should render a basic component: basic 1`] = `
</Form>
`;

exports[`SourceForm should render specifics to different source types: form, ansible 1`] = `
<div
class="pf-v5-c-helper-text"
>
Default port is
443
</div>
`;

exports[`SourceForm should render specifics to different source types: form, network 1`] = `
<div
class="pf-v5-c-helper-text"
>
Default port is 22
</div>
`;

exports[`SourceForm should render specifics to different source types: form, openshift 1`] = `
<div
class="pf-v5-c-helper-text"
>
Default port is
6443
</div>
`;

exports[`SourceForm should render specifics to different source types: form, rhacs 1`] = `
<div
class="pf-v5-c-helper-text"
>
Default port is
443
</div>
`;

exports[`SourceForm should render specifics to different source types: form, satellite 1`] = `
<div
class="pf-v5-c-helper-text"
>
Default port is
443
</div>
`;

exports[`SourceForm should render specifics to different source types: form, vcenter 1`] = `
<div
class="pf-v5-c-helper-text"
>
Default port is
443
</div>
`;

exports[`useSourceForm should allow editing a source: formData, edit 1`] = `
{
"credentials": [],
Expand Down
10 changes: 10 additions & 0 deletions src/views/sources/__tests__/addSourceModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,14 @@ describe('SourceForm', () => {
const component = await shallowComponent(<SourceForm />);
expect(component).toMatchSnapshot('basic');
});

it('should render specifics to different source types', async () => {
const sourceTypes = ['network', 'openshift', 'rhacs', 'ansible', 'satellite', 'vcenter'];
for (const type of sourceTypes) {
const component = await shallowComponent(<SourceForm sourceType={type} />);
const portFormGroup = component.querySelector('#source-port').closest('.pf-v5-c-form__group');
const portHelperText = portFormGroup.querySelector('.pf-v5-c-helper-text');
expect(portHelperText).toMatchSnapshot(`form, ${type}`);
}
});
});
13 changes: 9 additions & 4 deletions src/views/sources/addSourceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const useSourceForm = ({

const typeValue = source?.source_type || sourceType?.split(' ')?.shift()?.toLowerCase();
const isNetwork = typeValue === 'network';
const isOpenshift = typeValue === 'openshift';

// Edit props, reset state on unmount
useEffect(() => {
Expand Down Expand Up @@ -121,7 +122,7 @@ const useSourceForm = ({
name: name,
credentials: credentials?.map(c => Number(c)),
hosts: hosts?.split(','),
port: port || (isNetwork ? '22' : '443'),
port: port || (isOpenshift && '6443') || (isNetwork && '22') || '443',
options: !isNetwork
? {
ssl_cert_verify: sslProtocol !== 'Disable SSL' && sslVerify,
Expand All @@ -135,13 +136,14 @@ const useSourceForm = ({
...(source && { id: source.id })
};
},
[isNetwork, formData, source, typeValue]
[isNetwork, isOpenshift, formData, source, typeValue]
);

return {
credOptions,
formData,
isNetwork,
isOpenshift,
handleInputChange,
filterFormData,
typeValue
Expand All @@ -155,7 +157,10 @@ const SourceForm: React.FC<SourceFormProps> = ({
onSubmit = () => {},
useForm = useSourceForm
}) => {
const { formData, isNetwork, credOptions, handleInputChange, filterFormData } = useForm({ sourceType, source });
const { formData, isNetwork, isOpenshift, credOptions, handleInputChange, filterFormData } = useForm({
sourceType,
source
});
const onAdd = () => onSubmit(filterFormData());

return (
Expand Down Expand Up @@ -242,7 +247,7 @@ const SourceForm: React.FC<SourceFormProps> = ({
onChange={event => handleInputChange('port', (event.target as HTMLInputElement).value)}
ouiaId="port"
/>
<HelperText>Default port is 443</HelperText>
<HelperText>Default port is {isOpenshift ? '6443' : '443'}</HelperText>
</FormGroup>
</React.Fragment>
)}
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/code.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ exports[`General code checks should only have specific console.[warn|log|info|er
"hooks/useSourceApi.ts:191: console.error(error);",
"hooks/useSourceApi.ts:255: console.error(error);",
"views/scans/showScansModal.tsx:79: console.log({ aValue, bValue });",
"views/sources/addSourceModal.tsx:105: console.error(err);",
"views/sources/addSourceModal.tsx:106: console.error(err);",
]
`;

0 comments on commit c5c83b7

Please sign in to comment.