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

100% Statements 9/9
100% Branches 3/3
100% Functions 1/1
100% Lines 9/9

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 353x   3x 3x 3x                   3x                   6x   6x 4x       2x      
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
 
import { BasketView } from 'ish-core/models/basket/basket.model';
import { PaymentMethod } from 'ish-core/models/payment-method/payment-method.model';
import { PriceItemHelper } from 'ish-core/models/price-item/price-item.helper';
 
/**
 * Component for displaying payment costs and payment restriction information.
 */
@Component({
  selector: 'ish-basket-payment-cost-info',
  templateUrl: './basket-payment-cost-info.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BasketPaymentCostInfoComponent {
  @Input({ required: true }) paymentMethod: PaymentMethod;
  @Input({ required: true }) basket: BasketView;
  @Input({ required: true }) priceType: 'gross' | 'net';
 
  /**
   * Determine whether payment cost threshold has been reached
   * for usage in template
   */
  paymentCostThresholdReached(paymentMethod: PaymentMethod): boolean {
    const basketTotalPrice = PriceItemHelper.selectType(this.basket.totals.total, this.priceType);
 
    if (paymentMethod.paymentCostsThreshold && basketTotalPrice) {
      return (
        PriceItemHelper.selectType(paymentMethod.paymentCostsThreshold, this.priceType)?.value <= basketTotalPrice.value
      );
    }
    return false;
  }
}