From dba905215f82fa5c729b64b8a6aa075e754d4505 Mon Sep 17 00:00:00 2001 From: Sonia Sandler <66797193+SoniaSandler@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:10:34 -0500 Subject: [PATCH] chore: add option for given value in NumberItem (#10355) * chore: add option for given value in NumberItem Signed-off-by: Sonia Sandler * chore: update check to function Signed-off-by: Sonia Sandler --- .../PreferencesRenderingItemFormat.spec.ts | 21 +++++++++++++++++++ .../PreferencesRenderingItemFormat.svelte | 11 +++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.spec.ts b/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.spec.ts index d0dff82eca460..63b5cf2f2e012 100644 --- a/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.spec.ts +++ b/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.spec.ts @@ -153,6 +153,7 @@ 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'); @@ -160,6 +161,26 @@ test('Expect a text input when record is type number and enableSlider is false', 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 () => { diff --git a/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.svelte b/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.svelte index 685ebb5aa42c0..5f4b21f708cf2 100644 --- a/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.svelte +++ b/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.svelte @@ -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); +}
@@ -167,7 +176,7 @@ async function onChange(recordId: string, value: boolean | string | number): Pro {:else} {/if}