All files / src/app/core/models/category category.helper.ts

100% Statements 9/9
100% Branches 5/5
100% Functions 3/3
100% Lines 9/9

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    197x 197x     197x 197x                 9x 2x   7x 7x             65x      
import { Category } from './category.model';
 
export enum CategoryCompletenessLevel {
  Max = 3,
}
 
export class CategoryHelper {
  static uniqueIdSeparator = '.';
 
  /**
   * Converts a given uniqueId of a category in a REST API category path.
   *
   * @example
   * 'A.B.C' -> 'A/B/C'
   */
  static getCategoryPath(uniqueId: string): string {
    if (!uniqueId) {
      return;
    }
    const regEx = new RegExp(`\\${CategoryHelper.uniqueIdSeparator}`, 'g');
    return uniqueId.replace(regEx, '/');
  }
 
  /**
   * check if a given category has the maximum completeness level
   */
  static isCategoryCompletelyLoaded(category: Category): boolean {
    return !!category && category.completenessLevel >= CategoryCompletenessLevel.Max;
  }
}