All files / src/app/shared/components/search/suggest-search-terms suggest-search-terms.component.ts

92.3% Statements 12/13
75% Branches 3/4
75% Functions 3/4
92.3% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 355x 5x 5x 5x   5x 5x                 5x   3x 3x       3x     3x 3x                
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { Observable, ReplaySubject, map } from 'rxjs';
 
import { ShoppingFacade } from 'ish-core/facades/shopping.facade';
import { PipesModule } from 'ish-core/pipes.module';
 
@Component({
  selector: 'ish-suggest-search-terms',
  templateUrl: './suggest-search-terms.component.html',
  standalone: true,
  imports: [CommonModule, PipesModule, TranslateModule],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SuggestSearchTermsComponent implements OnInit {
  @Input() maxRecentlySearchedWords: number;
  @Input() inputTerms$ = new ReplaySubject<string>(1);
  @Output() submitSearch = new EventEmitter<string>();
 
  searchTerms$: Observable<string[]>;
 
  constructor(private shoppingFacade: ShoppingFacade) {}
 
  ngOnInit() {
    this.searchTerms$ = this.shoppingFacade.recentSearchTerms$.pipe(
      map(terms => terms.slice(0, this.maxRecentlySearchedWords))
    );
  }
 
  submit(term: string) {
    this.submitSearch.emit(term);
  }
}