All files / src/app/shared/components/line-item/line-item-warranty line-item-warranty.component.ts

100% Statements 12/12
75% Branches 6/8
100% Functions 4/4
100% Lines 11/11

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 422x 2x   2x 2x     2x                             2x   4x   4x         3x   3x         1x      
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { Observable, map } from 'rxjs';
 
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
import { ProductContextFacade } from 'ish-core/facades/product-context.facade';
import { LineItemView } from 'ish-core/models/line-item/line-item.model';
import { OrderLineItem } from 'ish-core/models/order/order.model';
import { whenTruthy } from 'ish-core/utils/operators';
 
/**
 * The Line Item Warranty Component displays the selected warranty. If the parameter editable is true a select box is shown and the user can selects a warranty. Otherwise only the warranty name is displayed.
 *
 * @example
 * <ish-line-item-warranty
 *    [pli]=pli
 *    [editable]="true' />
 */
@Component({
  selector: 'ish-line-item-warranty',
  templateUrl: './line-item-warranty.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LineItemWarrantyComponent implements OnInit {
  @Input({ required: true }) pli: Partial<LineItemView & OrderLineItem>;
  @Input() editable = false;
 
  constructor(private context: ProductContextFacade, private checkoutFacade: CheckoutFacade) {}
 
  productHasWarranties$: Observable<boolean>;
 
  ngOnInit() {
    this.productHasWarranties$ = this.context.select('product').pipe(
      whenTruthy(),
      map(product => !!product.availableWarranties?.length)
    );
  }
 
  updateLineItemWarranty(warrantySku: string) {
    this.checkoutFacade.updateBasketItemWarranty(this.pli.id, warrantySku);
  }
}