Skip to content

Commit

Permalink
fix: support multiple scopes on create/edit configurations (podman-de…
Browse files Browse the repository at this point in the history
…sktop#7659)

* fix: allow getting disk/memory/cpu values from default scope

Signed-off-by: lstocchi <[email protected]>

* fix: add test

Signed-off-by: lstocchi <[email protected]>

* Update packages/renderer/src/lib/preferences/PreferencesConnectionCreationOrEditRendering.spec.ts

Co-authored-by: Jeff MAURY <[email protected]>
Signed-off-by: Luca Stocchi <[email protected]>

---------

Signed-off-by: lstocchi <[email protected]>
Signed-off-by: Luca Stocchi <[email protected]>
Co-authored-by: Jeff MAURY <[email protected]>
  • Loading branch information
lstocchi and jeffmaury authored Jun 26, 2024
1 parent 914b0bc commit e9fdfb6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,66 @@ test(`Expect create with unchecked and checked checkboxes`, async () => {
undefined,
);
});

test(`Expect create with unchecked and checked checkboxes having multiple scopes`, async () => {
let providedKeyLogger: ((key: symbol, eventName: LoggerEventName, args: string[]) => void) | undefined;
const taskId = 4;
const callback = mockCallback(async keyLogger => {
providedKeyLogger = keyLogger;
});

const booleanProperties: IConfigurationPropertyRecordedSchema[] = [
{
title: 'unchecked checkbox',
parentId: '',
scope: ['ContainerProviderConnectionFactory', 'DEFAULT'],
id: 'test.unchecked',
type: 'boolean',
description: 'should be unchecked / false',
},
{
title: 'checked checkbox',
parentId: '',
scope: ['ContainerProviderConnectionFactory', 'DEFAULT'],
id: 'test.checked',
type: 'boolean',
default: true,
description: 'should be checked / true',
},
{
title: 'FactoryProperty',
parentId: '',
scope: ['ContainerProviderConnectionFactory', 'DEFAULT'],
id: 'test.factoryProperty',
type: 'number',
description: 'test.factoryProperty',
},
];

// eslint-disable-next-line @typescript-eslint/await-thenable
render(PreferencesConnectionCreationOrEditRendering, {
properties: booleanProperties,
providerInfo,
connectionInfo: undefined,
propertyScope,
callback,
pageIsLoading: false,
taskId,
});
await vi.waitUntil(() => screen.queryByRole('textbox', { name: 'test.factoryProperty' }));
await vi.waitUntil(() => screen.getByRole('checkbox', { name: 'should be unchecked / false' }));
await vi.waitUntil(() => screen.getByRole('checkbox', { name: 'should be checked / true' }));

const createButton = screen.getByRole('button', { name: 'Create' });
expect(createButton).toBeInTheDocument();
// click on the button
await fireEvent.click(createButton);

expect(callback).toBeCalledWith(
'test',
{ 'test.factoryProperty': '0', 'test.checked': true, 'test.unchecked': false },
expect.anything(),
eventCollect,
undefined,
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ onMount(async () => {
}
configurationKeys = properties
.filter(property => property.scope === propertyScope)
.filter(property =>
Array.isArray(property.scope) ? property.scope.find(s => s === propertyScope) : property.scope === propertyScope,
)
.filter(property => property.id?.startsWith(providerInfo.id))
.filter(property => isPropertyValidInContext(property.when, globalContext))
.map(property => {
Expand Down Expand Up @@ -250,7 +252,9 @@ async function getConfigurationValue(configurationKey: IConfigurationPropertyRec
internalSetConfigurationValue(configurationKey.id, false, value as string);
return value;
}
return getInitialValue(configurationKey);
const initialValue = await getInitialValue(configurationKey);
internalSetConfigurationValue(configurationKey.id, false, initialValue as string);
return initialValue;
}
}
Expand Down

0 comments on commit e9fdfb6

Please sign in to comment.