All files / src/app/extensions/quoting/shared/quoting-basket-line-items quoting-basket-line-items.component.ts

68.75% Statements 11/16
50% Branches 6/12
28.57% Functions 2/7
66.66% Lines 10/15

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 461x 1x 1x   1x   1x   1x               1x     1x     1x 1x                                            
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { groupBy } from 'lodash-es';
import { Observable, map } from 'rxjs';
 
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
import { LineItem } from 'ish-core/models/line-item/line-item.model';
import { GenerateLazyComponent } from 'ish-core/utils/module-loader/generate-lazy-component.decorator';
 
import { QuotingFacade } from '../../facades/quoting.facade';
 
@Component({
  selector: 'ish-quoting-basket-line-items',
  templateUrl: './quoting-basket-line-items.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
@GenerateLazyComponent()
export class QuotingBasketLineItemsComponent implements OnInit {
  lineItems$: Observable<[string, LineItem[]][]>;
 
  constructor(private checkoutFacade: CheckoutFacade, private quotingFacade: QuotingFacade) {}
 
  ngOnInit() {
    this.quotingFacade.loadQuoting();
    this.lineItems$ = this.checkoutFacade.basket$.pipe(
      map(basket =>
        Object.entries(groupBy(basket?.lineItems, 'quote')).sort((a, b) =>
          a[0] === 'undefined' ? -1 : b[0] === 'undefined' ? 1 : 0
        )
      )
    );
  }
 
  getName(quoteId: string) {
    return this.quotingFacade.name$(quoteId);
  }
 
  onDeleteQuote(quoteId: string) {
    this.quotingFacade.deleteQuoteFromBasket(quoteId);
  }
 
  trackByFn(_: number, element: [string, LineItem[]]) {
    // quoteId
    return element[0];
  }
}