All files / src/app/shared/components/basket/basket-cost-summary basket-cost-summary.component.ts

100% Statements 17/17
62.5% Branches 10/16
100% Functions 5/5
100% Lines 16/16

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 55 56 57 5810x   10x   10x 10x 10x 10x 10x                               10x       5x   5x     5x                     5x     5x 5x         5x 5x      
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
 
import { AccountFacade } from 'ish-core/facades/account.facade';
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
import { BasketTotal } from 'ish-core/models/basket-total/basket-total.model';
import { PriceItemHelper } from 'ish-core/models/price-item/price-item.helper';
import { PriceHelper } from 'ish-core/models/price/price.model';
import { PaypalPageType } from 'ish-core/utils/paypal-config/paypal-config.service';
 
/**
 * The Cost Summary Component displays a detailed summary of basket or order costs, respectively.
 *
 * @example
 * <ish-basket-cost-summary
 *   [totals]="basket.totals"
 * ></ish-basket-cost-summary>
 */
@Component({
  selector: 'ish-basket-cost-summary',
  templateUrl: './basket-cost-summary.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BasketCostSummaryComponent implements OnInit {
  @Input({ required: true }) totals: BasketTotal;
 
  taxTranslation$: Observable<string>;
  invert = PriceHelper.invert;
 
  showPaypalMessages$: Observable<{ type: PaypalPageType; preference: string }> =
    this.checkoutFacade.checkoutStep$.pipe(
      map(step =>
        step === 3
          ? {
              type: 'checkout',
              preference: 'preferences.PayPalCheckoutPreferences.PayLaterMessagingPaymentEnabled',
            }
          : step === undefined
          ? { type: 'cart', preference: 'preferences.PayPalCheckoutPreferences.PayLaterMessagingCartEnabled' }
          : undefined
      )
    );
 
  constructor(private accountFacade: AccountFacade, private checkoutFacade: CheckoutFacade) {}
 
  ngOnInit() {
    this.taxTranslation$ = this.accountFacade.userPriceDisplayType$.pipe(
      map(type => (type === 'net' ? 'checkout.tax.text' : 'checkout.tax.TaxesLabel.TotalOrderVat'))
    );
  }
 
  get hasPaymentCostsTotal(): boolean {
    const paymentCosts = PriceItemHelper.selectType(this.totals?.paymentCostsTotal, 'gross');
    return !!paymentCosts && !!paymentCosts.value;
  }
}