mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[MNT-25412] Chip autocomplete set input value when preselected options change (#11350)
This commit is contained in:
+11
-1
@@ -21,7 +21,7 @@ import { By } from '@angular/platform-browser';
|
||||
import { Subject } from 'rxjs';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { SearchChipAutocompleteInputComponent } from './search-chip-autocomplete-input.component';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { DebugElement, SimpleChanges } from '@angular/core';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatChipHarness, MatChipGridHarness } from '@angular/material/chips/testing';
|
||||
@@ -128,6 +128,16 @@ describe('SearchChipAutocompleteInputComponent', () => {
|
||||
expect(component.selectedOptions).toEqual([{ value: 'option1' }]);
|
||||
});
|
||||
|
||||
it('should assign preselected values whenever they are changed', async () => {
|
||||
const preselectedOptionsChange: SimpleChanges = {
|
||||
preselectedOptions: { currentValue: [{ value: 'option1' }], previousValue: [], firstChange: false, isFirstChange: () => false }
|
||||
};
|
||||
component.ngOnChanges(preselectedOptionsChange);
|
||||
fixture.detectChanges();
|
||||
expect(component.selectedOptions).toEqual([{ value: 'option1' }]);
|
||||
expect(await getChipValue(0)).toBe('option1');
|
||||
});
|
||||
|
||||
it('should add new option only if value is predefined when allowOnlyPredefinedValues = true', async () => {
|
||||
addNewOption('test');
|
||||
addNewOption('option1');
|
||||
|
||||
+3
@@ -122,6 +122,9 @@ export class SearchChipAutocompleteInputComponent implements OnInit, OnChanges {
|
||||
? this.filter(changes.autocompleteOptions.currentValue, this.formCtrl.value)
|
||||
: [];
|
||||
}
|
||||
if (changes.preselectedOptions) {
|
||||
this.selectedOptions = changes.preselectedOptions.currentValue ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
add(event: MatChipInputEvent) {
|
||||
|
||||
Reference in New Issue
Block a user