All files / src/app/shared/components/basket/basket-error-message basket-error-message.component.ts

75% Statements 9/12
0% Branches 0/1
33.33% Functions 1/3
80% Lines 8/10

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 326x 6x   6x                     6x   3x     3x   3x   3x                
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { ReplaySubject, asyncScheduler, scheduled, switchMap } from 'rxjs';
 
import { HttpError } from 'ish-core/models/http-error/http-error.model';
 
/**
 * Displays basket-related HTTP error messages and automatically scrolls
 * the message into view whenever the error input changes.
 */
@Component({
  selector: 'ish-basket-error-message',
  templateUrl: './basket-error-message.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BasketErrorMessageComponent implements OnChanges {
  @Input({ required: true }) error: HttpError;
  @Input() cssClass = 'alert alert-danger';
 
  // default values to control scrolling behavior
  scrollSpacing = 64;
 
  private scrollTrigger$ = new ReplaySubject<void>(1);
  // Emits false, then true asynchronously to ensure the directive's ngOnChanges is triggered
  scrollToMessage$ = this.scrollTrigger$.pipe(switchMap(() => scheduled([false, true], asyncScheduler)));
 
  ngOnChanges() {
    Iif (this.error) {
      this.scrollTrigger$.next();
    }
  }
}