Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(filter-field): Fixes an issue where options set on an async autoc…
Browse files Browse the repository at this point in the history
…omplete are shown.
  • Loading branch information
thomaspink committed Feb 7, 2020
1 parent 7faee84 commit 90e2428
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ export function clickOption(
const controller = testController || t;

return controller
.click(filterField)
.wait(150)
.click(option(nth));
.click(filterField, { speed: 0.3 })
.click(option(nth), { speed: 0.3 });
}

/** Focus the input of the filter field to send key events to it. */
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/src/filter-field/testdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const TEST_DATA = {
name: 'DE (async)',
async: true,
distinct: false,
autocomplete: [],
autocomplete: [{ name: 'Berlin' }],
},
{
name: 'DE (async, distinct)',
Expand Down
24 changes: 23 additions & 1 deletion components/filter-field/src/filter-field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ const TEST_DATA = {
suggestions: [],
validators: [],
},
{
name: 'DE (async)',
async: true,
autocomplete: [{ name: 'Berlin' }],
},
],
};

Expand Down Expand Up @@ -317,7 +322,7 @@ describe('DtFilterField', () => {

const options = getOptions(overlayContainerElement);
const optionGroups = getOptionGroups(overlayContainerElement);
expect(options.length).toBe(3);
expect(options.length).toBe(4);
expect(optionGroups.length).toBe(0);
expect(options[0].textContent).toContain('AUT');
expect(options[1].textContent).toContain('USA');
Expand Down Expand Up @@ -745,6 +750,23 @@ describe('DtFilterField', () => {
expect(document.activeElement).toBe(input);
expect(trigger.panelOpen).toBe(false);
}));

it('should not show options if the autocomplete is marked as async', fakeAsync(() => {
filterField.focus();
zone.simulateMicrotasksEmpty();
zone.simulateZoneExit();
fixture.detectChanges();

let options = getOptions(overlayContainerElement);
const asyncOption = options[3];
asyncOption.click();
zone.simulateMicrotasksEmpty();
fixture.detectChanges();

options = getOptions(overlayContainerElement);

expect(options.length).toBe(0);
}));
});

describe('with range option', () => {
Expand Down
5 changes: 4 additions & 1 deletion components/filter-field/src/filter-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,10 @@ export class DtFilterField<T> implements AfterViewInit, OnDestroy, OnChanges {
private _updateAutocompleteOptionsOrGroups(): void {
const currentDef = this._currentDef;

if (isDtAutocompleteDef(currentDef)) {
if (
isDtAutocompleteDef(currentDef) &&
!isAsyncDtAutocompleteDef(currentDef)
) {
const def = filterAutocompleteDef(
currentDef,
this._getSelectedOptionIds(),
Expand Down

0 comments on commit 90e2428

Please sign in to comment.