2017-11-13 04:11:54 -05:00
|
|
|
import * as textUtils from '~/lib/utils/text_utility';
|
2016-12-14 15:37:17 -05:00
|
|
|
|
2017-04-10 21:02:55 -04:00
|
|
|
describe('text_utility', () => {
|
2017-11-13 04:11:54 -05:00
|
|
|
describe('addDelimiter', () => {
|
|
|
|
it('should add a delimiter to the given string', () => {
|
|
|
|
expect(textUtils.addDelimiter('1234')).toEqual('1,234');
|
|
|
|
expect(textUtils.addDelimiter('222222')).toEqual('222,222');
|
2017-04-10 21:02:55 -04:00
|
|
|
});
|
2016-12-14 15:37:17 -05:00
|
|
|
|
2017-11-13 04:11:54 -05:00
|
|
|
it('should not add a delimiter if string contains no numbers', () => {
|
|
|
|
expect(textUtils.addDelimiter('aaaa')).toEqual('aaaa');
|
2017-02-01 10:23:01 -05:00
|
|
|
});
|
2017-04-10 21:02:55 -04:00
|
|
|
});
|
2017-02-21 14:21:49 -05:00
|
|
|
|
2017-10-10 03:47:42 -04:00
|
|
|
describe('highCountTrim', () => {
|
2017-04-10 21:02:55 -04:00
|
|
|
it('returns 99+ for count >= 100', () => {
|
2017-11-13 04:11:54 -05:00
|
|
|
expect(textUtils.highCountTrim(105)).toBe('99+');
|
|
|
|
expect(textUtils.highCountTrim(100)).toBe('99+');
|
2017-04-10 21:02:55 -04:00
|
|
|
});
|
2017-02-21 14:21:49 -05:00
|
|
|
|
2017-04-10 21:02:55 -04:00
|
|
|
it('returns exact number for count < 100', () => {
|
2017-11-13 04:11:54 -05:00
|
|
|
expect(textUtils.highCountTrim(45)).toBe(45);
|
2017-11-10 18:41:04 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('capitalizeFirstCharacter', () => {
|
|
|
|
it('returns string with first letter capitalized', () => {
|
2017-11-13 14:21:16 -05:00
|
|
|
expect(textUtils.capitalizeFirstCharacter('gitlab')).toEqual('Gitlab');
|
|
|
|
expect(textUtils.highCountTrim(105)).toBe('99+');
|
|
|
|
expect(textUtils.highCountTrim(100)).toBe('99+');
|
2017-02-21 14:21:49 -05:00
|
|
|
});
|
2017-04-10 21:02:55 -04:00
|
|
|
});
|
2017-02-22 14:58:24 -05:00
|
|
|
|
2017-11-13 04:11:54 -05:00
|
|
|
describe('humanize', () => {
|
|
|
|
it('should remove underscores and uppercase the first letter', () => {
|
|
|
|
expect(textUtils.humanize('foo_bar')).toEqual('Foo bar');
|
2017-04-10 21:02:55 -04:00
|
|
|
});
|
2017-11-13 04:11:54 -05:00
|
|
|
});
|
2017-02-22 14:58:24 -05:00
|
|
|
|
2017-11-13 04:11:54 -05:00
|
|
|
describe('pluralize', () => {
|
|
|
|
it('should pluralize given string', () => {
|
|
|
|
expect(textUtils.pluralize('test', 2)).toBe('tests');
|
2017-04-10 21:02:55 -04:00
|
|
|
});
|
2017-02-22 14:58:24 -05:00
|
|
|
|
2017-11-13 04:11:54 -05:00
|
|
|
it('should pluralize when count is 0', () => {
|
|
|
|
expect(textUtils.pluralize('test', 0)).toBe('tests');
|
|
|
|
});
|
2017-02-22 14:58:24 -05:00
|
|
|
|
2017-11-13 04:11:54 -05:00
|
|
|
it('should not pluralize when count is 1', () => {
|
|
|
|
expect(textUtils.pluralize('test', 1)).toBe('test');
|
|
|
|
});
|
|
|
|
});
|
2017-02-22 14:58:24 -05:00
|
|
|
|
2017-11-13 04:11:54 -05:00
|
|
|
describe('dasherize', () => {
|
|
|
|
it('should replace underscores with dashes', () => {
|
|
|
|
expect(textUtils.dasherize('foo_bar_foo')).toEqual('foo-bar-foo');
|
|
|
|
});
|
|
|
|
});
|
2017-02-22 14:58:24 -05:00
|
|
|
|
2017-11-13 04:11:54 -05:00
|
|
|
describe('slugify', () => {
|
|
|
|
it('should remove accents and convert to lower case', () => {
|
|
|
|
expect(textUtils.slugify('João')).toEqual('joão');
|
2017-02-22 14:58:24 -05:00
|
|
|
});
|
2016-12-14 15:37:17 -05:00
|
|
|
});
|
2018-01-03 16:03:39 -05:00
|
|
|
|
2018-01-19 04:38:34 -05:00
|
|
|
describe('stripHtml', () => {
|
2018-01-03 16:03:39 -05:00
|
|
|
it('replaces html tag with the default replacement', () => {
|
2018-01-19 04:38:34 -05:00
|
|
|
expect(textUtils.stripHtml('This is a text with <p>html</p>.')).toEqual('This is a text with html.');
|
2018-01-03 16:03:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('replaces html tags with the provided replacement', () => {
|
2018-01-19 04:38:34 -05:00
|
|
|
expect(textUtils.stripHtml('This is a text with <p>html</p>.', ' ')).toEqual('This is a text with html .');
|
2018-01-03 16:03:39 -05:00
|
|
|
});
|
|
|
|
});
|
2018-02-07 07:57:44 -05:00
|
|
|
|
|
|
|
describe('convertToCamelCase', () => {
|
|
|
|
it('converts snake_case string to camelCase string', () => {
|
|
|
|
expect(textUtils.convertToCamelCase('snake_case')).toBe('snakeCase');
|
|
|
|
});
|
|
|
|
});
|
2017-04-10 21:02:55 -04:00
|
|
|
});
|