All files / src/app/extensions/geo/shared/product-geo product-geo.component.ts

100% Statements 21/21
75% Branches 3/4
100% Functions 8/8
100% Lines 20/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 49 50 51 52 53 54 55 561x 1x   1x 1x 1x   1x 1x   1x                         1x           6x     6x 3x     3x   3x 3x     3x 3x     3x   3x 3x            
import { ChangeDetectionStrategy, Component, Input, OnInit, inject } from '@angular/core';
import { Observable, map, shareReplay } from 'rxjs';
 
import { ProductContextFacade } from 'ish-core/facades/product-context.facade';
import { AttributeGroupTypes, GeoAttributes } from 'ish-core/models/attribute-group/attribute-group.types';
import { AttributeHelper } from 'ish-core/models/attribute/attribute.helper';
import { Attribute } from 'ish-core/models/attribute/attribute.model';
import { ProductHelper } from 'ish-core/models/product/product.helper';
import { GenerateLazyComponent } from 'ish-core/utils/module-loader/generate-lazy-component.decorator';
 
import { GeoHelper } from '../../models/geo/geo.helper';
import { FaqEntry, SchemaHowTo } from '../../models/geo/geo.model';
 
type ProductGeoType = 'faq' | 'howto';
 
@Component({
  selector: 'ish-product-geo',
  standalone: false,
  templateUrl: './product-geo.component.html',
  styleUrls: ['./product-geo.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
@GenerateLazyComponent()
export class ProductGeoComponent implements OnInit {
  @Input({ required: true }) type: ProductGeoType;
 
  faq$: Observable<FaqEntry[]>;
  howTo$: Observable<SchemaHowTo | undefined>;
 
  private context = inject(ProductContextFacade);
 
  ngOnInit() {
    if (this.type === 'faq') {
      this.faq$ = this.context.select('product').pipe(
        map(
          product =>
            ProductHelper.getAttributesOfGroup(product, AttributeGroupTypes.ProductGeoAttributes) as Attribute<string>[]
        ),
        map(geo => AttributeHelper.getAttributeByAttributeName(geo, GeoAttributes.GeoFaq)?.value as string),
        map(geoFaq => GeoHelper.parseFaq(geoFaq)),
        shareReplay(1)
      );
    } else Eif (this.type === 'howto') {
      this.howTo$ = this.context.select('product').pipe(
        map(
          product =>
            ProductHelper.getAttributesOfGroup(product, AttributeGroupTypes.ProductGeoAttributes) as Attribute<string>[]
        ),
        map(geo => AttributeHelper.getAttributeByAttributeName(geo, GeoAttributes.GeoHowTo)?.value as string),
        map(geoHowTo => GeoHelper.parseGeoAttribute<SchemaHowTo>(geoHowTo)),
        shareReplay(1)
      );
    }
  }
}