All files / src/app/shell/header/sub-category-navigation sub-category-navigation.component.ts

78.57% Statements 11/14
50% Branches 5/10
60% Functions 3/5
84.61% Lines 11/13

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 49 50 511x     1x 1x   1x                   1x     2x   2x         2x   2x       2x             5x                      
import { ChangeDetectionStrategy, Component, Inject, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
 
import { MAIN_NAVIGATION_MAX_SUB_CATEGORIES_DEPTH } from 'ish-core/configurations/injection-keys';
import { ShoppingFacade } from 'ish-core/facades/shopping.facade';
import { NavigationCategory } from 'ish-core/models/navigation-category/navigation-category.model';
import { InjectSingle } from 'ish-core/utils/injection';
 
/**
 * The Sub Category Navigation Component displays second level category navigation.
 */
@Component({
  selector: 'ish-sub-category-navigation',
  templateUrl: './sub-category-navigation.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SubCategoryNavigationComponent implements OnInit {
  @Input({ required: true }) categoryUniqueId: string;
  @Input({ required: true }) subCategoriesDepth: number;
  @Input() view = 'auto';
 
  private openedCategories: string[] = [];
 
  navigationCategories$: Observable<NavigationCategory[]>;
 
  constructor(
    private shoppingFacade: ShoppingFacade,
    @Inject(MAIN_NAVIGATION_MAX_SUB_CATEGORIES_DEPTH)
    public mainNavigationMaxSubCategoriesDepth: InjectSingle<typeof MAIN_NAVIGATION_MAX_SUB_CATEGORIES_DEPTH>
  ) {}
 
  ngOnInit() {
    this.navigationCategories$ = this.shoppingFacade.navigationCategories$(this.categoryUniqueId);
  }
 
  /**
   * Indicate if specific category is expanded.
   */
  isOpened(uniqueId: string): boolean {
    return this.openedCategories.includes(uniqueId);
  }
 
  /**
   * Toggle category open state.
   */
  toggleOpen(uniqueId: string) {
    const index = this.openedCategories.findIndex(id => id === uniqueId);
    index > -1 ? this.openedCategories.splice(index, 1) : this.openedCategories.push(uniqueId);
  }
}