All files / src/app/extensions/wishlists/shared/wishlist-widget wishlist-widget.component.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 4/4
100% Lines 13/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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 551x 1x     1x 1x   1x                             1x           9x 9x   9x                 9x 9x               9x 8x        
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable, switchMap } from 'rxjs';
 
import { ProductContextDisplayProperties } from 'ish-core/facades/product-context.facade';
import { ShoppingFacade } from 'ish-core/facades/shopping.facade';
import { GenerateLazyComponent } from 'ish-core/utils/module-loader/generate-lazy-component.decorator';
 
import { WishlistsFacade } from '../../facades/wishlists.facade';
import { Wishlist } from '../../models/wishlist/wishlist.model';
 
/**
 * The Wishlist Widget Component displays wishlist products.
 * If a preferred wishlist exists, the products of the preferred wishlist are shown.
 * Otherwise the products of all wishlists are displayed.
 */
@Component({
  selector: 'ish-wishlist-widget',
  standalone: false,
  templateUrl: './wishlist-widget.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
@GenerateLazyComponent()
export class WishlistWidgetComponent implements OnInit {
  preferredWishlist$: Observable<Wishlist>;
  wishlistItemsSkus$: Observable<string[]>;
  tileConfiguration: Partial<ProductContextDisplayProperties>;
 
  constructor(
    private wishlistsFacade: WishlistsFacade,
    private shoppingFacade: ShoppingFacade
  ) {
    this.tileConfiguration = {
      addToWishlist: false,
      addToOrderTemplate: false,
      addToCompare: false,
      addToQuote: false,
    };
  }
 
  ngOnInit() {
    this.preferredWishlist$ = this.wishlistsFacade.preferredWishlist$;
    this.wishlistItemsSkus$ = this.shoppingFacade.excludeFailedProducts$(this.extractProductSkusFromWishlists$());
  }
 
  /**
   * Returns an observable of unique product SKUs to display.
   * If a preferred wishlist exists, only its products are shown, otherwise the products of all wishlists.
   */
  private extractProductSkusFromWishlists$(): Observable<string[]> {
    return this.wishlistsFacade.preferredWishlist$.pipe(
      switchMap(preferredWishlist => this.wishlistsFacade.wishlistItemsSkus$(preferredWishlist?.id))
    );
  }
}