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 => {
if (items.length === 0) {
return '';
} else if (items.length === 1) {
return items[0];
return sprintf(s__(`nounSeries|%{item}`), { item: items[0] }, false);
} else if (items.length === 2) {
return sprintf(s__('nounSeries|%{firstItem} and %{lastItem}'), {
firstItem: items[0],
lastItem: items[1],
});
return sprintf(
s__('nounSeries|%{firstItem} and %{lastItem}'),
{
firstItem: items[0],
lastItem: items[1],
},
false,
);
}
return items.reduce((item, nextItem, idx) =>
idx === items.length - 1
? sprintf(s__('nounSeries|%{item}, and %{lastItem}'), { item, lastItem: nextItem })
: sprintf(s__('nounSeries|%{item}, %{nextItem}'), { item, nextItem }),
? sprintf(s__('nounSeries|%{item}, and %{lastItem}'), { item, lastItem: nextItem }, false)
: sprintf(s__('nounSeries|%{item}, %{nextItem}'), { item, nextItem }, false),
);
};
......
......@@ -48,6 +48,7 @@ export default {
names: toNounSeriesText(this.rulesLeft),
count: this.approvalsLeft,
},
false,
);
},
hasApprovers() {
......
---
title: Fix character escaping on approvals summary
merge_request: 35564
author:
type: fixed
......@@ -5,7 +5,7 @@ import { toNounSeriesText } from '~/lib/utils/grammar';
import UserAvatarList from '~/vue_shared/components/user_avatar/user_avatar_list.vue';
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;
describe('EE MRWidget approvals summary', () => {
......
......@@ -27740,6 +27740,9 @@ msgstr ""
msgid "nounSeries|%{firstItem} and %{lastItem}"
msgstr ""
msgid "nounSeries|%{item}"
msgstr ""
msgid "nounSeries|%{item}, %{nextItem}"
msgstr ""
......
......@@ -7,27 +7,27 @@ describe('utils/grammar', () => {
});
it('with single item returns item', () => {
const items = ['Lorem Ipsum'];
const items = ['Lorem & Ipsum'];
expect(grammar.toNounSeriesText(items)).toBe(items[0]);
});
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]}`);
});
it('with 3 items returns comma separated series', () => {
const items = ['Lorem', 'Ipsum', 'dolar'];
const expected = 'Lorem, Ipsum, and dolar';
const items = ['Lorem', 'Ipsum', 'Sit & Amit'];
const expected = 'Lorem, Ipsum, and Sit & Amit';
expect(grammar.toNounSeriesText(items)).toBe(expected);
});
it('with 6 items returns comma separated series', () => {
const items = ['Lorem', 'ipsum', 'dolar', 'sit', 'amit', 'consectetur'];
const expected = 'Lorem, ipsum, dolar, sit, amit, and consectetur';
const items = ['Lorem', 'ipsum', 'dolar', 'sit', 'amit', 'consectetur & adipiscing'];
const expected = 'Lorem, ipsum, dolar, sit, amit, and consectetur & adipiscing';
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