diff --git a/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts index 264969aed4..4dc9878c7c 100644 --- a/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts @@ -276,7 +276,8 @@ describe('CardViewSelectItemComponent', () => { }); it('should set initial value to autocompleteControl', () => { - component.ngOnChanges({}); + fixture.componentRef.setInput('property', component.property); + fixture.componentRef.setInput('editable', true); fixture.detectChanges(); expect(component.autocompleteControl.value).toBe('initial value'); @@ -393,6 +394,70 @@ describe('CardViewSelectItemComponent', () => { }); }); + describe('Numeric initial value', () => { + const priorityOptions = [ + { key: 0, label: 'PROCESS_EDITOR.PRIORITIES.NONE' }, + { key: 1, label: 'PROCESS_EDITOR.PRIORITIES.LOW' }, + { key: 2, label: 'PROCESS_EDITOR.PRIORITIES.MEDIUM' }, + { key: 3, label: 'PROCESS_EDITOR.PRIORITIES.HIGH' } + ]; + + const createNumericProperty = (config: { + autocompleteBased: boolean; + value: number; + label?: string; + displayNoneOption?: boolean; + options?: { key: number; label: string }[]; + }) => + new CardViewSelectItemModel({ + label: config.label ?? 'Priority', + value: config.value, + key: 'priority', + editable: true, + autocompleteBased: config.autocompleteBased, + displayNoneOption: config.displayNoneOption, + options$: of(config.options ?? priorityOptions) + }); + + const applyInputs = (property: CardViewSelectItemModel) => { + fixture.componentRef.setInput('property', property); + fixture.componentRef.setInput('editable', true); + fixture.detectChanges(); + }; + + it('should not throw when autocompleteBased and initial value is numeric', fakeAsync(() => { + const property = createNumericProperty({ + autocompleteBased: true, + value: 1, + options: [ + { key: 1, label: 'Option 1' }, + { key: 2, label: 'Option 2' } + ] + }); + const filterOptionsSpy = spyOn(component, 'filterOptions').and.callThrough(); + + applyInputs(property); + tick(50); + + expect(filterOptionsSpy).toHaveBeenCalled(); + })); + + it('should not call filterOptions when autocompleteBased is false and initial value is numeric', () => { + const property = createNumericProperty({ + autocompleteBased: false, + value: 0, + label: 'PROCESS_EDITOR.ELEMENT_PROPERTIES.PRIORITY', + displayNoneOption: false + }); + const filterOptionsSpy = spyOn(component, 'filterOptions'); + + applyInputs(property); + + expect(component.property.value).toBe(0); + expect(filterOptionsSpy).not.toHaveBeenCalled(); + }); + }); + describe('Multivalued select', () => { const multivaluedMockData = [ { key: 'one', label: 'One' }, diff --git a/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.ts b/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.ts index 78ff4feb5b..051bc414e9 100644 --- a/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.ts +++ b/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.ts @@ -91,7 +91,7 @@ export class CardViewSelectItemComponent extends BaseCardView textInputValue !== this.editedValue && textInputValue !== null && !Array.isArray(textInputValue)), @@ -126,7 +126,10 @@ export class CardViewSelectItemComponent extends BaseCardView - options.filter((option) => { + map((options) => { + const filterValue = String(this.editedValue ?? '').toLowerCase(); + return options.filter((option) => { const isSelected = this.property.multivalued ? this.property.value.some((val) => val === option.key) : this.property.value === option.key; - return !isSelected && option.label.toLowerCase().includes(this.editedValue.toLowerCase()); - }) - ) + return !isSelected && option.label.toLowerCase().includes(filterValue); + }); + }) ) .pipe(take(1)) .subscribe((options: CardViewSelectItemOption[]) => {