Commit 544e281d authored by Justin Boyson's avatar Justin Boyson Committed by Martin Wortschack

Update toNounSeriesText to not escape text

Update tests and grammar.js to account for no escaping as well
parent a7974822
...@@ -20,18 +20,22 @@ export const toNounSeriesText = items => { ...@@ -20,18 +20,22 @@ export const toNounSeriesText = items => {
if (items.length === 0) { if (items.length === 0) {
return ''; return '';
} else if (items.length === 1) { } else if (items.length === 1) {
return items[0]; return sprintf(s__(`nounSeries|%{item}`), { item: items[0] }, false);
} else if (items.length === 2) { } else if (items.length === 2) {
return sprintf(s__('nounSeries|%{firstItem} and %{lastItem}'), { return sprintf(
firstItem: items[0], s__('nounSeries|%{firstItem} and %{lastItem}'),
lastItem: items[1], {
}); firstItem: items[0],
lastItem: items[1],
},
false,
);
} }
return items.reduce((item, nextItem, idx) => return items.reduce((item, nextItem, idx) =>
idx === items.length - 1 idx === items.length - 1
? sprintf(s__('nounSeries|%{item}, and %{lastItem}'), { item, lastItem: nextItem }) ? sprintf(s__('nounSeries|%{item}, and %{lastItem}'), { item, lastItem: nextItem }, false)
: sprintf(s__('nounSeries|%{item}, %{nextItem}'), { item, nextItem }), : sprintf(s__('nounSeries|%{item}, %{nextItem}'), { item, nextItem }, false),
); );
}; };
......
...@@ -48,6 +48,7 @@ export default { ...@@ -48,6 +48,7 @@ export default {
names: toNounSeriesText(this.rulesLeft), names: toNounSeriesText(this.rulesLeft),
count: this.approvalsLeft, count: this.approvalsLeft,
}, },
false,
); );
}, },
hasApprovers() { hasApprovers() {
......
---
title: Fix character escaping on approvals summary
merge_request: 35564
author:
type: fixed
...@@ -5,7 +5,7 @@ import { toNounSeriesText } from '~/lib/utils/grammar'; ...@@ -5,7 +5,7 @@ import { toNounSeriesText } from '~/lib/utils/grammar';
import UserAvatarList from '~/vue_shared/components/user_avatar/user_avatar_list.vue'; import UserAvatarList from '~/vue_shared/components/user_avatar/user_avatar_list.vue';
const testApprovers = () => Array.from({ length: 5 }, (_, i) => i).map(id => ({ id })); const testApprovers = () => Array.from({ length: 5 }, (_, i) => i).map(id => ({ id }));
const testRulesLeft = () => ['Lorem', 'Ipsum', 'dolar sit']; const testRulesLeft = () => ['Lorem', 'Ipsum', 'dolar & sit'];
const TEST_APPROVALS_LEFT = 3; const TEST_APPROVALS_LEFT = 3;
describe('EE MRWidget approvals summary', () => { describe('EE MRWidget approvals summary', () => {
......
...@@ -27740,6 +27740,9 @@ msgstr "" ...@@ -27740,6 +27740,9 @@ msgstr ""
msgid "nounSeries|%{firstItem} and %{lastItem}" msgid "nounSeries|%{firstItem} and %{lastItem}"
msgstr "" msgstr ""
msgid "nounSeries|%{item}"
msgstr ""
msgid "nounSeries|%{item}, %{nextItem}" msgid "nounSeries|%{item}, %{nextItem}"
msgstr "" msgstr ""
......
...@@ -7,27 +7,27 @@ describe('utils/grammar', () => { ...@@ -7,27 +7,27 @@ describe('utils/grammar', () => {
}); });
it('with single item returns item', () => { it('with single item returns item', () => {
const items = ['Lorem Ipsum']; const items = ['Lorem & Ipsum'];
expect(grammar.toNounSeriesText(items)).toBe(items[0]); expect(grammar.toNounSeriesText(items)).toBe(items[0]);
}); });
it('with 2 items returns item1 and item2', () => { it('with 2 items returns item1 and item2', () => {
const items = ['Dolar', 'Sit Amit']; const items = ['Dolar', 'Sit & Amit'];
expect(grammar.toNounSeriesText(items)).toBe(`${items[0]} and ${items[1]}`); expect(grammar.toNounSeriesText(items)).toBe(`${items[0]} and ${items[1]}`);
}); });
it('with 3 items returns comma separated series', () => { it('with 3 items returns comma separated series', () => {
const items = ['Lorem', 'Ipsum', 'dolar']; const items = ['Lorem', 'Ipsum', 'Sit & Amit'];
const expected = 'Lorem, Ipsum, and dolar'; const expected = 'Lorem, Ipsum, and Sit & Amit';
expect(grammar.toNounSeriesText(items)).toBe(expected); expect(grammar.toNounSeriesText(items)).toBe(expected);
}); });
it('with 6 items returns comma separated series', () => { it('with 6 items returns comma separated series', () => {
const items = ['Lorem', 'ipsum', 'dolar', 'sit', 'amit', 'consectetur']; const items = ['Lorem', 'ipsum', 'dolar', 'sit', 'amit', 'consectetur & adipiscing'];
const expected = 'Lorem, ipsum, dolar, sit, amit, and consectetur'; const expected = 'Lorem, ipsum, dolar, sit, amit, and consectetur & adipiscing';
expect(grammar.toNounSeriesText(items)).toBe(expected); expect(grammar.toNounSeriesText(items)).toBe(expected);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment