debian-mirror-gitlab/spec/javascripts/lib/utils/grammar_spec.js
2019-03-02 22:35:43 +05:30

35 lines
1.1 KiB
JavaScript

import * as grammar from '~/lib/utils/grammar';
describe('utils/grammar', () => {
describe('toNounSeriesText', () => {
it('with empty items returns empty string', () => {
expect(grammar.toNounSeriesText([])).toBe('');
});
it('with single item returns item', () => {
const items = ['Lorem Ipsum'];
expect(grammar.toNounSeriesText(items)).toBe(items[0]);
});
it('with 2 items returns item1 and item2', () => {
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';
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';
expect(grammar.toNounSeriesText(items)).toBe(expected);
});
});
});