Wizard: Fix kernel validation
Kernel validation worked only for one invalid field on the step. Now it is able to validate both.
This commit is contained in:
parent
3a85341dbf
commit
5eef2b3f9a
4 changed files with 26 additions and 20 deletions
|
|
@ -23,6 +23,7 @@ import {
|
||||||
selectKernel,
|
selectKernel,
|
||||||
} from '../../../../../store/wizardSlice';
|
} from '../../../../../store/wizardSlice';
|
||||||
import { useKernelValidation } from '../../../utilities/useValidation';
|
import { useKernelValidation } from '../../../utilities/useValidation';
|
||||||
|
import { isKernelNameValid } from '../../../validators';
|
||||||
|
|
||||||
const initialOptions = ['kernel', 'kernel-debug'];
|
const initialOptions = ['kernel', 'kernel-debug'];
|
||||||
let kernelOptions = initialOptions;
|
let kernelOptions = initialOptions;
|
||||||
|
|
@ -48,7 +49,9 @@ const KernelName = () => {
|
||||||
if (!filteredKernelPkgs.some((kernel) => kernel === filterValue)) {
|
if (!filteredKernelPkgs.some((kernel) => kernel === filterValue)) {
|
||||||
filteredKernelPkgs = [
|
filteredKernelPkgs = [
|
||||||
...filteredKernelPkgs,
|
...filteredKernelPkgs,
|
||||||
`Custom kernel package "${filterValue}"`,
|
isKernelNameValid(filterValue)
|
||||||
|
? `Custom kernel package "${filterValue}"`
|
||||||
|
: `"${filterValue}" is not a valid kernel package name`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
|
|
@ -165,7 +168,11 @@ const KernelName = () => {
|
||||||
>
|
>
|
||||||
<SelectList>
|
<SelectList>
|
||||||
{selectOptions.map((option) => (
|
{selectOptions.map((option) => (
|
||||||
<SelectOption key={option} value={option}>
|
<SelectOption
|
||||||
|
key={option}
|
||||||
|
value={option}
|
||||||
|
isDisabled={/not a valid kernel package name/i.test(option)}
|
||||||
|
>
|
||||||
{option}
|
{option}
|
||||||
</SelectOption>
|
</SelectOption>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
|
|
@ -262,14 +262,10 @@ export function useHostnameValidation(): StepValidation {
|
||||||
|
|
||||||
export function useKernelValidation(): StepValidation {
|
export function useKernelValidation(): StepValidation {
|
||||||
const kernel = useAppSelector(selectKernel);
|
const kernel = useAppSelector(selectKernel);
|
||||||
|
const errors = {};
|
||||||
|
|
||||||
if (!isKernelNameValid(kernel.name)) {
|
if (!isKernelNameValid(kernel.name)) {
|
||||||
return {
|
Object.assign(errors, { kernel: 'Invalid format.' });
|
||||||
errors: {
|
|
||||||
kernel: 'Invalid format.',
|
|
||||||
},
|
|
||||||
disabledNext: true,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kernel.append.length > 0) {
|
if (kernel.append.length > 0) {
|
||||||
|
|
@ -282,14 +278,16 @@ export function useKernelValidation(): StepValidation {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invalidArgs.length > 0) {
|
if (invalidArgs.length > 0) {
|
||||||
return {
|
Object.assign(errors, {
|
||||||
errors: { kernelAppend: `Invalid kernel arguments: ${invalidArgs}` },
|
kernelAppend: `Invalid kernel arguments: ${invalidArgs}`,
|
||||||
disabledNext: true,
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { errors: {}, disabledNext: false };
|
return {
|
||||||
|
errors: errors,
|
||||||
|
disabledNext: 'kernel' in errors || 'kernelAppend' in errors,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useFirewallValidation(): StepValidation {
|
export function useFirewallValidation(): StepValidation {
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,8 @@ export const isKernelNameValid = (kernelName: string) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
kernelName.length < 65 &&
|
kernelName.length < 65 &&
|
||||||
/^[a-z0-9]|[a-z0-9][a-z0-9-_.+]*[a-z0-9]$/.test(kernelName)
|
/^([a-z0-9]|[a-z0-9][a-z0-9-_.+]*)[a-z0-9]$/.test(kernelName) &&
|
||||||
|
/[a-zA-Z]+/.test(kernelName) // contains at least one letter
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import {
|
||||||
clickBack,
|
clickBack,
|
||||||
clickNext,
|
clickNext,
|
||||||
enterBlueprintName,
|
enterBlueprintName,
|
||||||
getNextButton,
|
|
||||||
interceptBlueprintRequest,
|
interceptBlueprintRequest,
|
||||||
interceptEditBlueprintRequest,
|
interceptEditBlueprintRequest,
|
||||||
openAndDismissSaveAndBuildModal,
|
openAndDismissSaveAndBuildModal,
|
||||||
|
|
@ -193,17 +192,18 @@ describe('Step Kernel', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('disable Next with invalid custom kernel name', async () => {
|
test('disable Next with invalid custom kernel name', async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
await renderCreateMode();
|
await renderCreateMode();
|
||||||
await goToKernelStep();
|
await goToKernelStep();
|
||||||
|
|
||||||
await selectCustomKernelName('-----------');
|
const kernelNameDropdown = await getKernelNameOptions();
|
||||||
await screen.findByText(/Invalid format/);
|
await openKernelNameOptions(kernelNameDropdown);
|
||||||
const nextButton = await getNextButton();
|
|
||||||
expect(nextButton).toBeDisabled();
|
await waitFor(() => user.type(kernelNameDropdown, '-----------'));
|
||||||
|
await screen.findByText(/"-----------" is not a valid kernel package name/);
|
||||||
|
|
||||||
await clearKernelName();
|
await clearKernelName();
|
||||||
expect(screen.queryByText(/Invalid format/)).not.toBeInTheDocument();
|
expect(screen.queryByText(/Invalid format/)).not.toBeInTheDocument();
|
||||||
expect(nextButton).toBeEnabled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('kernel argument can be added and removed', async () => {
|
test('kernel argument can be added and removed', async () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue