mirror of
https://github.com/langgenius/dify.git
synced 2026-11-11 05:41:09 +08:00
fix(web): preserve zero and false in opening statements (#44833)
This commit is contained in:
1 parent
80265fcfe1
commit
60429fd39f
2 files changed
+20
-1
No files matched your search
@@ -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'),
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user