2022-09-25 19:44:40 +03:00
|
|
|
import string from '@/helpers/string-helper'
|
2019-02-10 15:26:50 +03:00
|
|
|
|
|
|
|
describe('string helper', () => {
|
|
|
|
describe('pnr()', () => {
|
|
|
|
test('replaces substring to a string defined in an object', () => {
|
2022-09-25 19:44:40 +03:00
|
|
|
expect(StringHelper.pnr('Hello %name%', { '%name%': 'Leon' })).toBe(
|
2022-09-03 14:12:41 +03:00
|
|
|
'Hello Leon'
|
|
|
|
)
|
2019-02-10 15:26:50 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('ucfirst()', () => {
|
|
|
|
test('transforms first letter to uppercase', () => {
|
2022-09-25 19:44:40 +03:00
|
|
|
expect(StringHelper.ucfirst('leon')).toBe('Leon')
|
2019-02-10 15:26:50 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-05-11 14:39:38 +03:00
|
|
|
describe('snakeToPascalCase()', () => {
|
|
|
|
test('transforms snake_case string to PascalCase', () => {
|
2022-09-25 19:44:40 +03:00
|
|
|
expect(StringHelper.snakeToPascalCase('leon')).toBe('Leon')
|
|
|
|
expect(StringHelper.snakeToPascalCase('this_is_leon')).toBe('ThisIsLeon')
|
2019-05-11 14:39:38 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-02-10 15:26:50 +03:00
|
|
|
describe('random()', () => {
|
|
|
|
test('generates a random string with a length defined by a given number', () => {
|
2022-09-25 19:44:40 +03:00
|
|
|
const s = StringHelper.random(6)
|
2019-02-10 15:26:50 +03:00
|
|
|
expect(typeof s).toBe('string')
|
|
|
|
expect(s.length).toBe(6)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('removeAccents()', () => {
|
|
|
|
test('removes accents', () => {
|
2022-09-25 19:44:40 +03:00
|
|
|
expect(StringHelper.removeAccents('àâèéêëîïôöûüùÛÜç')).toBe(
|
|
|
|
'aaeeeeiioouuuUUc'
|
|
|
|
)
|
2019-02-10 15:26:50 +03:00
|
|
|
})
|
|
|
|
})
|
2019-05-11 14:39:38 +03:00
|
|
|
|
|
|
|
describe('removeEndPunctuation()', () => {
|
|
|
|
test('removes end-punctuation', () => {
|
2022-09-25 19:44:40 +03:00
|
|
|
expect(StringHelper.removeEndPunctuation('Who are you?')).toBe(
|
|
|
|
'Who are you'
|
|
|
|
)
|
|
|
|
expect(StringHelper.removeEndPunctuation('This is great.')).toBe(
|
2022-09-03 14:12:41 +03:00
|
|
|
'This is great'
|
|
|
|
)
|
|
|
|
expect(
|
2022-09-25 19:44:40 +03:00
|
|
|
StringHelper.removeEndPunctuation('This string has no punctuation')
|
2022-09-03 14:12:41 +03:00
|
|
|
).toBe('This string has no punctuation')
|
2019-05-11 14:39:38 +03:00
|
|
|
})
|
|
|
|
})
|
2019-02-10 15:26:50 +03:00
|
|
|
})
|