|
| 1 | +import test from 'ava' |
| 2 | +import slugify from 'browser/lib/slugify' |
| 3 | + |
| 4 | +test('alphabet and digit', t => { |
| 5 | + const upperAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 6 | + const lowerAlphabet = 'abcdefghijklmnopqrstuvwxyz' |
| 7 | + const digit = '0123456789' |
| 8 | + const testCase = upperAlphabet + lowerAlphabet + digit |
| 9 | + const decodeSlug = decodeURI(slugify(testCase)) |
| 10 | + |
| 11 | + t.true(decodeSlug === testCase) |
| 12 | +}) |
| 13 | + |
| 14 | +test('should delete unavailable symbols', t => { |
| 15 | + const availableSymbols = '_-' |
| 16 | + const testCase = availableSymbols + '][!\'#$%&()*+,./:;<=>?@\\^{|}~`' |
| 17 | + const decodeSlug = decodeURI(slugify(testCase)) |
| 18 | + |
| 19 | + t.true(decodeSlug === availableSymbols) |
| 20 | +}) |
| 21 | + |
| 22 | +test('should convert from white spaces between words to hyphens', t => { |
| 23 | + const testCase = 'This is one' |
| 24 | + const expectedString = 'This-is-one' |
| 25 | + const decodeSlug = decodeURI(slugify(testCase)) |
| 26 | + |
| 27 | + t.true(decodeSlug === expectedString) |
| 28 | +}) |
| 29 | + |
| 30 | +test('should remove leading white spaces', t => { |
| 31 | + const testCase = ' This is one' |
| 32 | + const expectedString = 'This-is-one' |
| 33 | + const decodeSlug = decodeURI(slugify(testCase)) |
| 34 | + |
| 35 | + t.true(decodeSlug === expectedString) |
| 36 | +}) |
| 37 | + |
| 38 | +test('should remove trailing white spaces', t => { |
| 39 | + const testCase = 'This is one ' |
| 40 | + const expectedString = 'This-is-one' |
| 41 | + const decodeSlug = decodeURI(slugify(testCase)) |
| 42 | + |
| 43 | + t.true(decodeSlug === expectedString) |
| 44 | +}) |
| 45 | + |
| 46 | +test('2-byte charactor support', t => { |
| 47 | + const testCase = '菠萝芒果テストÀžƁƵ' |
| 48 | + const decodeSlug = decodeURI(slugify(testCase)) |
| 49 | + |
| 50 | + t.true(decodeSlug === testCase) |
| 51 | +}) |
| 52 | + |
| 53 | +test('emoji', t => { |
| 54 | + const testCase = '🌸' |
| 55 | + const decodeSlug = decodeURI(slugify(testCase)) |
| 56 | + |
| 57 | + t.true(decodeSlug === testCase) |
| 58 | +}) |
0 commit comments