Skip to content

Commit

Permalink
chore: add option for given value in NumberItem (podman-desktop#10355)
Browse files Browse the repository at this point in the history
* chore: add option for given value in NumberItem
Signed-off-by: Sonia Sandler <[email protected]>

* chore: update check to function
Signed-off-by: Sonia Sandler <[email protected]>
  • Loading branch information
SoniaSandler authored Dec 17, 2024
1 parent 0fd1a14 commit dba9052
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,34 @@ test('Expect a text input when record is type number and enableSlider is false',
type: 'number',
minimum: 1,
maximum: 34,
default: 20,
};
await awaitRender(record, {});
const input = screen.getByLabelText('record-description');
expect(input).toBeInTheDocument();
expect(input instanceof HTMLInputElement).toBe(true);
expect((input as HTMLInputElement).type).toBe('text');
expect((input as HTMLInputElement).name).toBe('record');
expect((input as HTMLInputElement).value).toBe('20');
});

test('Expect record with type number and enableSlider false to use given value if available', async () => {
const record: IConfigurationPropertyRecordedSchema = {
id: 'record',
title: 'record',
parentId: 'parent.record',
description: 'record-description',
type: 'number',
minimum: 1,
maximum: 34,
};
await awaitRender(record, { givenValue: 5 });
const input = screen.getByLabelText('record-description');
expect(input).toBeInTheDocument();
expect(input instanceof HTMLInputElement).toBe(true);
expect((input as HTMLInputElement).type).toBe('text');
expect((input as HTMLInputElement).name).toBe('record');
expect((input as HTMLInputElement).value).toBe('5');
});

test('Expect a fileinput when record is type string and format file', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ async function onChange(recordId: string, value: boolean | string | number): Pro
// auto save
return await autoSave();
}
function numberItemValue(): number {
if (givenValue && typeof givenValue === 'number') {
return givenValue;
} else if (recordValue && typeof recordValue === 'number') {
return recordValue;
}
return getNormalizedDefaultNumberValue(record);
}
</script>

<div class="flex flex-row mb-1 pt-2 text-start items-center justify-start">
Expand All @@ -167,7 +176,7 @@ async function onChange(recordId: string, value: boolean | string | number): Pro
{:else}
<NumberItem
record={record}
value={typeof recordValue === 'number' ? recordValue : getNormalizedDefaultNumberValue(record)}
value={numberItemValue()}
onChange={onChange}
invalidRecord={invalidRecord} />
{/if}
Expand Down

0 comments on commit dba9052

Please sign in to comment.