All files / src/app/core/facades selected-product-context.facade.ts

76.19% Statements 16/21
68.18% Branches 15/22
28.57% Functions 2/7
75% Lines 15/20

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 493x 3x 3x 3x   3x   3x 3x 3x     3x               42x 42x 42x 42x   42x                         42x                    
import { Injectable, Injector } from '@angular/core';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { concatMap, filter, map, skip, withLatestFrom } from 'rxjs/operators';
 
import { ProductVariationHelper } from 'ish-core/models/product-variation/product-variation.helper';
 
import { AppFacade } from './app.facade';
import { ProductContextFacade } from './product-context.facade';
import { ShoppingFacade } from './shopping.facade';
 
@Injectable()
export class SelectedProductContextFacade extends ProductContextFacade {
  constructor(
    shoppingFacade: ShoppingFacade,
    translate: TranslateService,
    injector: Injector,
    router: Router,
    appFacade: AppFacade
  ) {
    super(shoppingFacade, appFacade, translate, injector);
    this.set('requiredCompletenessLevel', () => true);
    this.connect('categoryId', shoppingFacade.selectedCategoryId$);
    this.connect('sku', shoppingFacade.selectedProductId$);
 
    this.connect(
      'sku',
      this.select('product').pipe(
        filter(ProductVariationHelper.hasDefaultVariation),
        concatMap(p =>
          appFacade.serverSetting$<boolean>('preferences.ChannelPreferences.EnableAdvancedVariationHandling').pipe(
            filter(advancedVariationHandling => advancedVariationHandling !== undefined && !advancedVariationHandling),
            map(() => p.defaultVariationSKU)
          )
        )
      )
    );
 
    this.hold(
      this.select('productURL').pipe(
        skip(1),
        withLatestFrom(appFacade.routingInProgress$),
        filter(([, progress]) => !progress)
      ),
      ([url]) => router.navigateByUrl(url)
    );
  }
}