All files / src/app/shared/components/product/product-item-variations product-item-variations.component.ts

100% Statements 16/16
80% Branches 8/10
100% Functions 3/3
100% Lines 15/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 403x 3x 3x   3x 3x 3x             3x             26x     26x   26x     26x     9x   26x 26x   26x      
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable, combineLatest } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
 
import { AppFacade } from 'ish-core/facades/app.facade';
import { ProductContextFacade } from 'ish-core/facades/product-context.facade';
import { ProductHelper } from 'ish-core/models/product/product.helper';
 
@Component({
  selector: 'ish-product-item-variations',
  templateUrl: './product-item-variations.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ProductItemVariationsComponent implements OnInit {
  visible$: Observable<boolean>;
  readOnly$: Observable<boolean>;
  variationCount$: Observable<number>;
  isMasterProduct$: Observable<boolean>;
  isVariationProduct$: Observable<boolean>;
 
  constructor(private context: ProductContextFacade, private appFacade: AppFacade) {}
 
  ngOnInit() {
    this.visible$ = this.context.select('displayProperties', 'variations');
 
    const advancedVariationHandling$ = this.appFacade.serverSetting$<boolean>(
      'preferences.ChannelPreferences.EnableAdvancedVariationHandling'
    );
    this.readOnly$ = combineLatest([
      this.context.select('displayProperties', 'readOnly').pipe(startWith(false)),
      advancedVariationHandling$,
    ]).pipe(map(([readOnly, advancedVariationHandling]) => readOnly || advancedVariationHandling));
 
    this.isMasterProduct$ = this.context.select('product').pipe(map(ProductHelper.isMasterProduct));
    this.isVariationProduct$ = this.context.select('product').pipe(map(ProductHelper.isVariationProduct));
 
    this.variationCount$ = this.context.select('variationCount');
  }
}