From 0b94b8bff663516375ffe06f98c5909b84f47280 Mon Sep 17 00:00:00 2001 From: Owen Coogan Date: Fri, 31 Jul 2026 15:13:19 +0200 Subject: [PATCH] feat: added normalize category name service for proper dcns --- .../hyper-table-v2/manage-columns.hbs | 2 +- addon/components/hyper-table/index.hbs | 2 +- addon/helpers/normalize-category-name.ts | 8 ++++ app/helpers/normalize-category-name.js | 1 + .../helpers/normalize-category-name-test.ts | 41 +++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 addon/helpers/normalize-category-name.ts create mode 100644 app/helpers/normalize-category-name.js create mode 100644 tests/integration/helpers/normalize-category-name-test.ts diff --git a/addon/components/hyper-table-v2/manage-columns.hbs b/addon/components/hyper-table-v2/manage-columns.hbs index a5eede67..8611a2c0 100644 --- a/addon/components/hyper-table-v2/manage-columns.hbs +++ b/addon/components/hyper-table-v2/manage-columns.hbs @@ -20,7 +20,7 @@
{{category}}
diff --git a/addon/components/hyper-table/index.hbs b/addon/components/hyper-table/index.hbs index 17e7eca3..75b9a17c 100644 --- a/addon/components/hyper-table/index.hbs +++ b/addon/components/hyper-table/index.hbs @@ -90,7 +90,7 @@ {{#each this._fieldCategories as |category|}}
{{category.label}}
diff --git a/addon/helpers/normalize-category-name.ts b/addon/helpers/normalize-category-name.ts new file mode 100644 index 00000000..a89e6bd2 --- /dev/null +++ b/addon/helpers/normalize-category-name.ts @@ -0,0 +1,8 @@ +import { helper } from '@ember/component/helper'; + +export function normalizeCategoryNameHelper(params: any[]) { + const [category] = params; + return category.toLowerCase().replace(/\s+/g, '_'); +} + +export default helper(normalizeCategoryNameHelper); diff --git a/app/helpers/normalize-category-name.js b/app/helpers/normalize-category-name.js new file mode 100644 index 00000000..2fb37c53 --- /dev/null +++ b/app/helpers/normalize-category-name.js @@ -0,0 +1 @@ +export { default, normalizeCategoryNameHelper } from '@upfluence/hypertable/helpers/normalize-category-name'; diff --git a/tests/integration/helpers/normalize-category-name-test.ts b/tests/integration/helpers/normalize-category-name-test.ts new file mode 100644 index 00000000..c31381fc --- /dev/null +++ b/tests/integration/helpers/normalize-category-name-test.ts @@ -0,0 +1,41 @@ +import { render, type TestContext } from '@ember/test-helpers'; + +import { setupRenderingTest } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; +import { module, test } from 'qunit'; + +module('Integration | Helper | normalize-category-name', function (hooks) { + setupRenderingTest(hooks); + + test('when the category has no spaces, it lowercases the value', async function (this: TestContext, assert) { + this.category = 'Sports'; + + await render(hbs`{{normalize-category-name this.category}}`); + + assert.dom('span').hasText('sports'); + }); + + test('when the category has spaces, it replaces them with underscores and lowercases', async function (this: TestContext, assert) { + this.category = 'Social Media'; + + await render(hbs`{{normalize-category-name this.category}}`); + + assert.dom('span').hasText('social_media'); + }); + + test('when the category has multiple consecutive spaces, it collapses them into a single underscore', async function (this: TestContext, assert) { + this.category = 'Health & Wellness'; + + await render(hbs`{{normalize-category-name this.category}}`); + + assert.dom('span').hasText('health_&_wellness'); + }); + + test('when the category is already lowercase with underscores, it returns it unchanged', async function (this: TestContext, assert) { + this.category = 'already_normalized'; + + await render(hbs`{{normalize-category-name this.category}}`); + + assert.dom('span').hasText('already_normalized'); + }); +});