All files / src/app/extensions/quoting/shared/quote-line-item-list quote-line-item-list.component.ts

100% Statements 12/12
83.33% Branches 5/6
100% Functions 4/4
100% Lines 12/12

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 381x 1x 1x       1x               1x           3x     3x 3x     3x 3x   3x       2x      
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable, combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
 
import { Price } from 'ish-core/models/price/price.model';
 
import { QuoteContextFacade } from '../../facades/quote-context.facade';
import { QuoteRequestItem } from '../../models/quoting/quoting.model';
 
@Component({
  selector: 'ish-quote-line-item-list',
  templateUrl: './quote-line-item-list.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class QuoteLineItemListComponent implements OnInit {
  total$: Observable<Price>;
  lineItems$: Observable<Pick<QuoteRequestItem, 'productSKU' | 'quantity'>[]>;
  editable$: Observable<boolean>;
  displayTotal$: Observable<boolean>;
 
  constructor(private context: QuoteContextFacade) {}
 
  ngOnInit() {
    this.total$ = this.context.select('entity', 'total');
    this.lineItems$ = this.context.select('entity', 'items') as Observable<
      Pick<QuoteRequestItem, 'productSKU' | 'quantity'>[]
    >;
    this.displayTotal$ = combineLatest([this.total$, this.lineItems$]).pipe(
      map(([total, items]) => !!total && !!items?.length)
    );
    this.editable$ = this.context.select('editable');
  }
 
  trackByFn(_: number, item: Pick<QuoteRequestItem, 'productSKU' | 'quantity'>) {
    return item.productSKU;
  }
}