From 6f8c4d4ac0d5d34210d1a644e9efc377cc04536a Mon Sep 17 00:00:00 2001 From: Danny Martini Date: Mon, 17 Jun 2024 14:20:00 +0200 Subject: [PATCH] add test and handle edge cases --- .../src/components/N8nMenuItem/MenuItem.vue | 11 +------ .../N8nMenuItem/__tests__/labelUtil.spec.ts | 29 +++++++++++++++++++ .../src/components/N8nMenuItem/labelUtil.ts | 25 ++++++++++++++++ 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 packages/design-system/src/components/N8nMenuItem/__tests__/labelUtil.spec.ts create mode 100644 packages/design-system/src/components/N8nMenuItem/labelUtil.ts diff --git a/packages/design-system/src/components/N8nMenuItem/MenuItem.vue b/packages/design-system/src/components/N8nMenuItem/MenuItem.vue index 8ef00aad1f60c8..f29fad87f9928a 100644 --- a/packages/design-system/src/components/N8nMenuItem/MenuItem.vue +++ b/packages/design-system/src/components/N8nMenuItem/MenuItem.vue @@ -97,6 +97,7 @@ import N8nIcon from '../N8nIcon'; import ConditionalRouterLink from '../ConditionalRouterLink'; import type { IMenuItem } from '../../types'; import { doesMenuItemMatchCurrentRoute } from './routerUtil'; +import { getInitials } from './labelUtil'; interface MenuItemProps { item: IMenuItem; @@ -149,16 +150,6 @@ const isItemActive = (item: IMenuItem): boolean => { Array.isArray(item.children) && item.children.some((child) => isActive(child)); return isActive(item) || hasActiveChild; }; - -const getInitials = (label: string): string => { - const words = label.split(' ').map((word) => [...new Intl.Segmenter().segment(word)]); - - if (words.length === 1) { - return words[0][0].segment + words[0][1].segment; - } else { - return words[0][0].segment + words[1][0].segment; - } -};