src: Cleanup import modal on close
This commit is contained in:
parent
c385417e93
commit
22c9b0c106
4 changed files with 65 additions and 96 deletions
|
|
@ -23,7 +23,7 @@ const BLUEPRINT_JSON = `{
|
|||
"name": "Crustless New York Cheesecake 1"
|
||||
}`;
|
||||
|
||||
const INVALID_BLUEPRINT_WITH_SUBSCRIPTION = `{
|
||||
const IGNORE_SUBSCRIPTION_BLUEPRINT = `{
|
||||
"customizations": {
|
||||
"files": [
|
||||
],
|
||||
|
|
@ -63,7 +63,7 @@ const INVALID_BLUEPRINT_WITH_SUBSCRIPTION = `{
|
|||
"name": "Blueprint test"
|
||||
}`;
|
||||
|
||||
const INVALID_BLUEPRINT_WITH_TARGETS = `{
|
||||
const IGNORE_TARGETS_BLUEPRINT = `{
|
||||
"customizations": {
|
||||
"files": [
|
||||
],
|
||||
|
|
@ -121,55 +121,6 @@ const INVALID_JSON = `{
|
|||
"name": "Blueprint test"
|
||||
}`;
|
||||
|
||||
const INVALID_IMAGE_TYPE_JSON = `{
|
||||
"customizations": {
|
||||
"files": [
|
||||
],
|
||||
"kernel": {
|
||||
},
|
||||
"openscap": {
|
||||
},
|
||||
"packages": [
|
||||
"aide",
|
||||
"sudo",
|
||||
"audit",
|
||||
"rsyslog",
|
||||
"firewalld",
|
||||
"nftables",
|
||||
"libselinux"
|
||||
],
|
||||
"services": {
|
||||
"enabled": [
|
||||
"crond",
|
||||
"firewalld",
|
||||
"systemd-journald",
|
||||
"rsyslog",
|
||||
"auditd"
|
||||
]
|
||||
},
|
||||
"subscription": {
|
||||
}
|
||||
},
|
||||
"description": "Tested blueprint",
|
||||
"distribution": "rhel-93",
|
||||
"id": "052bf998-7955-45ad-952d-49ce3573e0b7",
|
||||
"image_requests": [
|
||||
{
|
||||
"architecture": "aaaaa",
|
||||
"image_type": "aws",
|
||||
"upload_request": {
|
||||
"options": {
|
||||
"share_with_sources": [
|
||||
"473980"
|
||||
]
|
||||
},
|
||||
"type": "aws"
|
||||
}
|
||||
}
|
||||
],
|
||||
"name": "Blueprint test"
|
||||
}`;
|
||||
|
||||
const uploadFile = async (filename: string, content: string): Promise<void> => {
|
||||
const user = userEvent.setup();
|
||||
const fileInput: HTMLElement | null =
|
||||
|
|
@ -182,7 +133,7 @@ const uploadFile = async (filename: string, content: string): Promise<void> => {
|
|||
}
|
||||
};
|
||||
|
||||
describe('Import model', () => {
|
||||
describe('Import modal', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
|
@ -218,37 +169,32 @@ describe('Import model', () => {
|
|||
await waitFor(() => expect(helperText).toBeInTheDocument());
|
||||
});
|
||||
|
||||
test('should show alert on invalid blueprint with targets', async () => {
|
||||
test('should enable button and ignore targets in blueprint file', async () => {
|
||||
await setUp();
|
||||
await uploadFile(`blueprints.json`, INVALID_BLUEPRINT_WITH_TARGETS);
|
||||
await uploadFile(`blueprints.json`, IGNORE_TARGETS_BLUEPRINT);
|
||||
const reviewButton = screen.getByTestId('import-blueprint-finish');
|
||||
expect(reviewButton).toHaveClass('pf-m-disabled');
|
||||
const helperText = await screen.findByText(
|
||||
/not compatible with the blueprints format\./i
|
||||
await waitFor(() => expect(reviewButton).not.toHaveClass('pf-m-disabled'));
|
||||
user.click(reviewButton);
|
||||
|
||||
await waitFor(async () =>
|
||||
expect(
|
||||
await screen.findByText('Image output', { selector: 'h1' })
|
||||
).toBeInTheDocument()
|
||||
);
|
||||
await waitFor(() => expect(helperText).toBeInTheDocument());
|
||||
});
|
||||
|
||||
test('should show alert on invalid blueprint with subscription', async () => {
|
||||
test('should enable button and ignore subscription in blueprint file', async () => {
|
||||
await setUp();
|
||||
await uploadFile(`blueprints.json`, INVALID_BLUEPRINT_WITH_SUBSCRIPTION);
|
||||
await uploadFile(`blueprints.json`, IGNORE_SUBSCRIPTION_BLUEPRINT);
|
||||
const reviewButton = screen.getByTestId('import-blueprint-finish');
|
||||
expect(reviewButton).toHaveClass('pf-m-disabled');
|
||||
const helperText = await screen.findByText(
|
||||
/not compatible with the blueprints format\./i
|
||||
);
|
||||
await waitFor(() => expect(helperText).toBeInTheDocument());
|
||||
});
|
||||
await waitFor(() => expect(reviewButton).not.toHaveClass('pf-m-disabled'));
|
||||
user.click(reviewButton);
|
||||
|
||||
test('should show alert on invalid blueprint incorrect image type', async () => {
|
||||
await setUp();
|
||||
await uploadFile(`blueprints.json`, INVALID_IMAGE_TYPE_JSON);
|
||||
const reviewButton = screen.getByTestId('import-blueprint-finish');
|
||||
expect(reviewButton).toHaveClass('pf-m-disabled');
|
||||
const helperText = await screen.findByText(
|
||||
/not compatible with the blueprints format\./i
|
||||
await waitFor(async () =>
|
||||
expect(
|
||||
await screen.findByText('Image output', { selector: 'h1' })
|
||||
).toBeInTheDocument()
|
||||
);
|
||||
await waitFor(() => expect(helperText).toBeInTheDocument());
|
||||
});
|
||||
|
||||
test('should enable button on correct blueprint and go to wizard', async () => {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ export const ImportBlueprintModal: React.FunctionComponent<
|
|||
> = ({ setShowImportModal, isOpen }: ImportBlueprintModalProps) => {
|
||||
const onImportClose = () => {
|
||||
setShowImportModal(false);
|
||||
setFilename('');
|
||||
setJsonContent('');
|
||||
setIsRejected(false);
|
||||
setIsInvalidFormat(false);
|
||||
};
|
||||
const [jsonContent, setJsonContent] = React.useState('');
|
||||
const [importedBlueprint, setImportedBlueprint] =
|
||||
|
|
|
|||
|
|
@ -146,18 +146,10 @@ function commonRequestToState(
|
|||
request: BlueprintResponse | BlueprintExportResponse
|
||||
) {
|
||||
return {
|
||||
details: {
|
||||
blueprintName: request.name,
|
||||
blueprintDescription: request.description,
|
||||
},
|
||||
openScap: {
|
||||
profile: request.customizations.openscap
|
||||
?.profile_id as DistributionProfileItem,
|
||||
},
|
||||
fileSystem: request.customizations.filesystem
|
||||
fileSystem: request.customizations?.filesystem
|
||||
? {
|
||||
mode: 'manual' as FileSystemConfigurationType,
|
||||
partitions: request.customizations.filesystem.map((fs) =>
|
||||
partitions: request.customizations?.filesystem.map((fs) =>
|
||||
convertFilesystemToPartition(fs)
|
||||
),
|
||||
}
|
||||
|
|
@ -165,17 +157,13 @@ function commonRequestToState(
|
|||
mode: 'automatic' as FileSystemConfigurationType,
|
||||
partitions: [],
|
||||
},
|
||||
firstBoot: {
|
||||
script: getFirstBootScript(request.customizations.files),
|
||||
},
|
||||
distribution: getLatestRelease(request.distribution),
|
||||
repositories: {
|
||||
customRepositories: request.customizations.custom_repositories || [],
|
||||
payloadRepositories: request.customizations.payload_repositories || [],
|
||||
customRepositories: request.customizations?.custom_repositories || [],
|
||||
payloadRepositories: request.customizations?.payload_repositories || [],
|
||||
recommendedRepositories: [],
|
||||
},
|
||||
packages:
|
||||
request.customizations.packages
|
||||
request.customizations?.packages
|
||||
?.filter((pkg) => !pkg.startsWith('@'))
|
||||
.map((pkg) => ({
|
||||
name: pkg,
|
||||
|
|
@ -183,7 +171,7 @@ function commonRequestToState(
|
|||
repository: '' as PackageRepository,
|
||||
})) || [],
|
||||
groups:
|
||||
request.customizations.packages
|
||||
request.customizations?.packages
|
||||
?.filter((grp) => grp.startsWith('@'))
|
||||
.map((grp) => ({
|
||||
name: grp.substr(1),
|
||||
|
|
@ -232,11 +220,16 @@ export const mapRequestToState = (request: BlueprintResponse): wizardState => {
|
|||
return {
|
||||
wizardMode,
|
||||
blueprintId: request.id,
|
||||
details: {
|
||||
blueprintName: request.name,
|
||||
blueprintDescription: request.description,
|
||||
},
|
||||
env: {
|
||||
serverUrl: request.customizations.subscription?.['server-url'] || '',
|
||||
baseUrl: request.customizations.subscription?.['base-url'] || '',
|
||||
},
|
||||
architecture: arch,
|
||||
distribution: getLatestRelease(request.distribution),
|
||||
imageTypes: request.image_requests.map((image) => image.image_type),
|
||||
azure: {
|
||||
shareMethod: azureUploadOptions?.source_id ? 'sources' : 'manual',
|
||||
|
|
@ -272,6 +265,13 @@ export const mapRequestToState = (request: BlueprintResponse): wizardState => {
|
|||
: 'register-later',
|
||||
activationKey: request.customizations.subscription?.['activation-key'],
|
||||
},
|
||||
openScap: {
|
||||
profile: request.customizations.openscap
|
||||
?.profile_id as DistributionProfileItem,
|
||||
},
|
||||
firstBoot: {
|
||||
script: getFirstBootScript(request.customizations.files),
|
||||
},
|
||||
...commonRequestToState(request),
|
||||
};
|
||||
};
|
||||
|
|
@ -288,18 +288,35 @@ export const mapExportRequestToState = (
|
|||
|
||||
return {
|
||||
wizardMode,
|
||||
details: {
|
||||
blueprintName: request.name || '',
|
||||
blueprintDescription: request.description || '',
|
||||
},
|
||||
metadata: {
|
||||
parent_id: request.metadata.parent_id || '',
|
||||
exported_at: request.metadata.exported_at,
|
||||
parent_id: request.metadata?.parent_id || '',
|
||||
exported_at: request.metadata?.exported_at || '',
|
||||
},
|
||||
env: initialState.env,
|
||||
gcp: initialState.gcp,
|
||||
aws: initialState.aws,
|
||||
azure: initialState.azure,
|
||||
architecture: initialState.architecture,
|
||||
distribution:
|
||||
getLatestRelease(request.distribution) || initialState.distribution,
|
||||
imageTypes: initialState.imageTypes,
|
||||
snapshotting: initialState.snapshotting,
|
||||
registration: initialState.registration,
|
||||
openScap: request.customizations
|
||||
? {
|
||||
profile: request.customizations.openscap
|
||||
?.profile_id as DistributionProfileItem,
|
||||
}
|
||||
: initialState.openScap,
|
||||
firstBoot: request.customizations
|
||||
? {
|
||||
script: getFirstBootScript(request.customizations.files),
|
||||
}
|
||||
: initialState.firstBoot,
|
||||
...commonRequestToState(request),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -338,8 +338,10 @@ describe('Blueprints', () => {
|
|||
renderCustomRoutesWithReduxRouter();
|
||||
|
||||
await selectBlueprintById(blueprintIdWithComposes);
|
||||
const toggleButton = screen.getByTestId('blueprint-action-menu-toggle');
|
||||
await user.click(toggleButton);
|
||||
const toggleButton = await screen.findByTestId(
|
||||
'blueprint-action-menu-toggle'
|
||||
);
|
||||
await waitFor(() => user.click(toggleButton));
|
||||
|
||||
const downloadButton = screen.getByRole('menuitem', {
|
||||
name: /download blueprint \(\.json\) preview/i,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue