diff --git a/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.spec.ts b/packages/renderer/src/lib/preferences/PreferencesRenderingItemFormat.spec.ts index d0dff82ec..63b5cf2f2 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 685ebb5aa..5f4b21f70 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); +}