Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/components/hyper-table-v2/manage-columns.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div
class={{concat "field-category" (if (eq this.activeColumnCategory category) " field-category--active")}}
role="button"
data-control-name={{concat "field_category_toggle_" category}}
data-control-name={{concat "field_category_toggle_" (normalize-category-name category)}}
{{on "click" (fn this.setFieldCategory category)}}
>
<div>{{category}}</div>
Expand Down
2 changes: 1 addition & 1 deletion addon/components/hyper-table/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
{{#each this._fieldCategories as |category|}}
<div
class="field-category {{if (eq this._activeFieldCategory category.key) 'field-category--active'}}"
data-control-name={{concat "field_category_toggle_" category.key}}
data-control-name={{concat "field_category_toggle_" (normalize-category-name category.key)}}
{{action "setFieldCategory" category.key}}
>
<div>{{category.label}}</div>
Expand Down
8 changes: 8 additions & 0 deletions addon/helpers/normalize-category-name.ts
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions app/helpers/normalize-category-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, normalizeCategoryNameHelper } from '@upfluence/hypertable/helpers/normalize-category-name';
41 changes: 41 additions & 0 deletions tests/integration/helpers/normalize-category-name-test.ts
Original file line number Diff line number Diff line change
@@ -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`<span>{{normalize-category-name this.category}}</span>`);

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`<span>{{normalize-category-name this.category}}</span>`);

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`<span>{{normalize-category-name this.category}}</span>`);

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`<span>{{normalize-category-name this.category}}</span>`);

assert.dom('span').hasText('already_normalized');
});
});
Loading