diff --git a/web/app/components/base/chat/chat/__tests__/utils.spec.ts b/web/app/components/base/chat/chat/__tests__/utils.spec.ts index 385991d885c..78b3f337acd 100644 --- a/web/app/components/base/chat/chat/__tests__/utils.spec.ts +++ b/web/app/components/base/chat/chat/__tests__/utils.spec.ts @@ -21,6 +21,25 @@ describe('chat/chat/utils.ts', () => { expect(result).toBe('Hello Alice') }) + it.each([ + { value: 0, type: InputVarType.number, expected: '0' }, + { value: false, type: InputVarType.checkbox, expected: 'false' }, + ])('replaces a $type variable with $expected', ({ value, type, expected }) => { + const result = processOpeningStatement('Value: {{value}}', { value }, [ + inputForm('value', type, 'Value Label'), + ]) + + expect(result).toBe(`Value: ${expected}`) + }) + + it('keeps the label placeholder for an empty input value', () => { + const result = processOpeningStatement('Hello {{name}}', { name: '' }, [ + inputForm('name', InputVarType.textInput, 'Name Label'), + ]) + + expect(result).toBe('Hello {{Name Label}}') + }) + it('replaces variables with labels when input value is not available but form has variable', () => { const result = processOpeningStatement('Hello {{user_name}}', {}, [ inputForm('user_name', InputVarType.textInput, 'Name Label'), diff --git a/web/app/components/base/chat/chat/utils.ts b/web/app/components/base/chat/chat/utils.ts index 840ed386d34..f61d0bcf7cb 100644 --- a/web/app/components/base/chat/chat/utils.ts +++ b/web/app/components/base/chat/chat/utils.ts @@ -11,7 +11,7 @@ export const processOpeningStatement = ( return openingStatement.replace(/\{\{([^}]+)\}\}/g, (match, key) => { const name = inputs[key] - if (name) { + if (name !== undefined && name !== null && name !== '') { // has set value return name }