From 33215da9390af2456e02e61f39fb5ac5d2c31757 Mon Sep 17 00:00:00 2001 From: bhushankhope Date: Mon, 15 Apr 2024 13:36:15 -0400 Subject: [PATCH] improve code coverage --- .../icon-registry/icon-registry.service.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/cde-ui/src/app/services/icon-registry/icon-registry.service.ts b/apps/cde-ui/src/app/services/icon-registry/icon-registry.service.ts index 19c5c88b1..abc848dbd 100644 --- a/apps/cde-ui/src/app/services/icon-registry/icon-registry.service.ts +++ b/apps/cde-ui/src/app/services/icon-registry/icon-registry.service.ts @@ -52,6 +52,18 @@ const enum DefType { NamespacedNamedUrl = Url | Named | Namespaced, } +/** + * Throws the error if value is empty else returns value + */ +function throwIfEmpty(value: T | undefined): T { + /* istanbul ignore if */ + if (value === undefined) { + throw new Error('empty value'); + } + + return value; +} + /** * Type for the values of registry dispatch table object. */ @@ -62,18 +74,19 @@ type RegistryDispatcher = (reg: MatIconRegistry, resource: SafeValue, def: BaseS */ const REGISTRY_DISPATCH_TABLE: Record = { [DefType.Url]: (reg, url, { options }) => reg.addSvgIconSet(url, options), - [DefType.NamedUrl]: (reg, url, { name, options }) => reg.addSvgIcon(name ?? '', url, options), + [DefType.NamedUrl]: (reg, url, { name, options }) => reg.addSvgIcon(throwIfEmpty(name), url, options), [DefType.NamespacedUrl]: (reg, url, { namespace, options }) => - reg.addSvgIconSetInNamespace(namespace ?? '', url, options), + reg.addSvgIconSetInNamespace(throwIfEmpty(namespace), url, options), [DefType.NamespacedNamedUrl]: (reg, url, { name, namespace, options }) => - reg.addSvgIconInNamespace(namespace ?? '', name ?? '', url, options), + reg.addSvgIconInNamespace(throwIfEmpty(namespace), throwIfEmpty(name), url, options), [DefType.Literal]: (reg, literal, { options }) => reg.addSvgIconSetLiteral(literal, options), - [DefType.NamedLiteral]: (reg, literal, { name, options }) => reg.addSvgIconLiteral(name ?? '', literal, options), + [DefType.NamedLiteral]: (reg, literal, { name, options }) => + reg.addSvgIconLiteral(throwIfEmpty(name), literal, options), [DefType.NamespacedLiteral]: (reg, literal, { namespace, options }) => - reg.addSvgIconSetLiteralInNamespace(namespace ?? '', literal, options), + reg.addSvgIconSetLiteralInNamespace(throwIfEmpty(namespace), literal, options), [DefType.NamespacedNamedLiteral]: (reg, literal, { name, namespace, options }) => - reg.addSvgIconLiteralInNamespace(namespace ?? '', name ?? '', literal, options), + reg.addSvgIconLiteralInNamespace(throwIfEmpty(namespace), throwIfEmpty(name), literal, options), }; /**