Skip to content

Commit 90afe48

Browse files
committed
dev: adds helper pluralize
1 parent 32682d6 commit 90afe48

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

app/components/branches-row.gts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
type Repository,
1010
type NotFoundResponse,
1111
} from 'dealfront/controllers/application';
12+
import pluralize from 'dealfront/helpers/pluralize';
1213

1314
interface BranchRowSignature {
1415
// The arguments accepted by the component
@@ -73,7 +74,10 @@ export default class BranchRow extends Component<BranchRowSignature> {
7374
>
7475
<td class="df-cell" colspan="4">
7576
{{#if this.branches.length}}
76-
<h4 class="branches-heading">{{this.branches.length}} Branches</h4>
77+
<h4 class="branches-heading">
78+
{{this.branches.length}}
79+
{{pluralize this.branches.length "branch"}}
80+
</h4>
7781
{{/if}}
7882
<p class="branches-paragraph">
7983
{{#if this.getRepoBranches.isRunning}}

app/helpers/pluralize.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { helper } from '@ember/component/helper';
2+
3+
export default helper(function pluralize([number, word]: [
4+
number,
5+
string,
6+
]): string {
7+
const isSingle = number.toString().endsWith('1');
8+
9+
return isSingle ? word : word + 'es';
10+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'dealfront/tests/helpers';
3+
import { render } from '@ember/test-helpers';
4+
import pluralize from 'dealfront/helpers/pluralize';
5+
6+
module('Integration | Helper | pluralize', function (hooks) {
7+
setupRenderingTest(hooks);
8+
9+
// TODO: Replace this with your real tests.
10+
test('it renders', async function (assert) {
11+
const inputValue = [
12+
{ number: 1, word: 'branch' },
13+
{ number: 12, word: 'branches' },
14+
{ number: 21, word: 'branch' },
15+
];
16+
17+
// await render(<template>{{pluralize inputValue[0] "branch"}}</template>);
18+
19+
for (const { number, word } of inputValue) {
20+
await render(<template>{{pluralize number "branch"}}</template>);
21+
assert.dom().hasText(word);
22+
}
23+
// assert.dom().hasText('12 branches');
24+
});
25+
});

0 commit comments

Comments
 (0)