Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ describe('WhereModifierGroup should', () => {
expect(handler).toHaveBeenCalled();
});

it('not emit event when criteria is multi and input ends with comma and optional space', () => {
modifierGroup.condition = {
field: { fieldName: 'foo' },
operator: 'IN',
values: [{ type: 'string', value: '' }]
};
modifierGroup.sobjectMetadata = {
fields: [{ name: 'foo', type: 'string' }]
};
const handler = jest.fn();
modifierGroup.addEventListener('modifiergroupselection', handler);
document.body.appendChild(modifierGroup);

const { criteriaInputEl } = getModifierElements();
criteriaInputEl.value = "'peach', 'banana', ";
criteriaInputEl.dispatchEvent(new Event('input'));

expect(handler).not.toBeCalled;

criteriaInputEl.value = "'peach', 'banana', 'mango'";
criteriaInputEl.dispatchEvent(new Event('input'));
expect(handler).toBeCalled;
});

it('not emit event when SOME modfiers have no value', () => {
document.body.appendChild(modifierGroup);
const handler = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,25 @@ export default class WhereModifierGroup extends LightningElement {
operator: opModelValue
};
if (isMultiInput) {
const rawValues = splitMultiInputValues(normalizedInput);
const values = rawValues.map((value) => {
return {
type: critType,
value
const endsWithCommaAndOptionalSpaceRegex = /,\s*$/; // matches ',' or ', ' or ', '
if (
normalizedInput &&
!endsWithCommaAndOptionalSpaceRegex.test(normalizedInput)
) {
const rawValues = splitMultiInputValues(normalizedInput);
const values = rawValues.map((value) => {
return {
type: critType,
value
};
});
this.condition = {
...conditionTemplate,
values
};
});
this.condition = {
...conditionTemplate,
values
};
} else {
// Do not trigger update. User is still typing or not finished their input.
}
} else {
this.condition = {
...conditionTemplate,
Expand Down