diff --git a/apps/datahub/src/app/search/search-header/search-header.component.html b/apps/datahub/src/app/search/search-header/search-header.component.html
index a90f232a00..367e1659cc 100644
--- a/apps/datahub/src/app/search/search-header/search-header.component.html
+++ b/apps/datahub/src/app/search/search-header/search-header.component.html
@@ -8,7 +8,7 @@
record.metadata.updatedOn
diff --git a/libs/ui/inputs/src/lib/autocomplete/autocomplete.component.spec.ts b/libs/ui/inputs/src/lib/autocomplete/autocomplete.component.spec.ts index bf413d036f..f6218ab5c5 100644 --- a/libs/ui/inputs/src/lib/autocomplete/autocomplete.component.spec.ts +++ b/libs/ui/inputs/src/lib/autocomplete/autocomplete.component.spec.ts @@ -117,14 +117,19 @@ describe('AutocompleteComponent', () => { }) }) - describe('initial value', () => { + describe('@Input() value', () => { let anyEmitted describe('when set', () => { beforeEach(() => { - component.initialValue = { title: 'hello' } - component.displayWithFn = (item) => item.title + const simpleChanges: any = { + value: { + previousValue: undefined, + currentValue: { title: 'hello' }, + }, + } + component.displayWithFn = (item) => item?.title component.inputSubmited.subscribe((event) => (anyEmitted = event)) - fixture.detectChanges() + component.ngOnChanges(simpleChanges) }) it('set control value', () => { expect(component.control.value).toEqual({ title: 'hello' }) @@ -133,10 +138,56 @@ describe('AutocompleteComponent', () => { expect(anyEmitted).toEqual('hello') }) }) - describe('when not set', () => { + describe('when changed', () => { beforeEach(() => { + const simpleChanges: any = { + value: { + previousValue: { title: 'hello' }, + currentValue: { title: 'good bye' }, + }, + } + component.displayWithFn = (item) => item?.title component.inputSubmited.subscribe((event) => (anyEmitted = event)) - fixture.detectChanges() + component.ngOnChanges(simpleChanges) + }) + it('set control value', () => { + expect(component.control.value).toEqual({ title: 'good bye' }) + }) + it('emits any string', () => { + expect(anyEmitted).toEqual('good bye') + }) + }) + describe('when ref changed but same text', () => { + let anyEmitted + beforeEach(() => { + const simpleChanges: any = { + value: { + previousValue: { title: 'good bye' }, + currentValue: { title: 'good bye' }, + }, + } + component.displayWithFn = (item) => item?.title + component.inputSubmited.subscribe((event) => (anyEmitted = event)) + component.ngOnChanges(simpleChanges) + }) + it('does not set control value', () => { + expect(component.control.value).toBeNull() + }) + it('does not emit any value', () => { + expect(anyEmitted).toBeUndefined() + }) + }) + describe('when not set on init (firstChange == true)', () => { + beforeEach(() => { + component.inputSubmited.subscribe((event) => (anyEmitted = event)) + const simpleChanges: any = { + value: { + firstChange: true, + previousValue: undefined, + currentValue: null, + }, + } + component.ngOnChanges(simpleChanges) }) it('does not set control value', () => { expect(component.control.value).toEqual(null) diff --git a/libs/ui/inputs/src/lib/autocomplete/autocomplete.component.ts b/libs/ui/inputs/src/lib/autocomplete/autocomplete.component.ts index 002ab24c17..2b4a87420d 100644 --- a/libs/ui/inputs/src/lib/autocomplete/autocomplete.component.ts +++ b/libs/ui/inputs/src/lib/autocomplete/autocomplete.component.ts @@ -5,9 +5,11 @@ import { ElementRef, EventEmitter, Input, + OnChanges, OnDestroy, OnInit, Output, + SimpleChanges, ViewChild, } from '@angular/core' import { FormControl } from '@angular/forms' @@ -16,7 +18,7 @@ import { MatAutocompleteSelectedEvent, MatAutocompleteTrigger, } from '@angular/material/autocomplete' -import { BehaviorSubject, Observable, ReplaySubject, Subscription } from 'rxjs' +import { Observable, ReplaySubject, Subscription } from 'rxjs' import { debounceTime, distinctUntilChanged, @@ -36,10 +38,12 @@ export type AutcompleteItem = unknown styleUrls: ['./autocomplete.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class AutocompleteComponent implements OnInit, AfterViewInit, OnDestroy { +export class AutocompleteComponent + implements OnInit, AfterViewInit, OnDestroy, OnChanges +{ @Input() placeholder: string @Input() action: (value: string) => Observable