All files / src/app/core/models/content-view content-view.helper.ts

100% Statements 6/6
75% Branches 3/4
100% Functions 2/2
100% Lines 6/6

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 314x       4x                   5x 5x                     9x 9x      
import { LinkParser } from 'ish-core/utils/link-parser';
 
import { ContentConfigurationParameterView } from './content-view.model';
 
export class ContentViewHelper {
  /**
   * get a routerLink for a given configuration parameter of the given configuration parameter container
   * the configuration parameter value may contain an ICM short link notation or an external URL
   * the default route is '/home'
   *
   * @param configParamView
   * @param configParam
   */
  static getRouterLink(configParamView: ContentConfigurationParameterView, configParam: string): string {
    const configParamValue = configParamView.stringParam(configParam);
    return LinkParser.parseLink(configParamValue) || '/home';
  }
 
  /**
   * determine whether the given configuration parameter of the given configuration parameter container
   * contains a link value that is supposed to be handled as a routerLink or not (external link)
   *
   * @param configParamView
   * @param configParam
   */
  static isRouterLink(configParamView: ContentConfigurationParameterView, configParam: string): boolean {
    const configParamValue = configParamView.stringParam(configParam);
    return configParamValue && !configParamValue.startsWith('http');
  }
}