-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_slug.test.js
44 lines (37 loc) · 1.49 KB
/
generate_slug.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
const generateSlug = require('./generate_slug')
test('numbering works', () => {
const links = []
expect(generateSlug('foo bar', links)).toEqual('foo-bar')
expect(generateSlug('foo bar', links)).toEqual('foo-bar-1')
expect(generateSlug('foo bar', links)).toEqual('foo-bar-2')
})
test('strips extra whitespace', () => {
expect(generateSlug('foo bar')).toEqual('foo-bar')
expect(generateSlug(' foo bar ')).toEqual('foo-bar')
})
test('strips extra characters and html', () => {
expect(generateSlug('foo bar (wow)')).toEqual('foo-bar-wow')
expect(generateSlug('foo bar--wow -')).toEqual('foo-bar-wow')
expect(generateSlug('foo bar_wow ♥ф你-💣')).toEqual('foo-bar_wow')
expect(generateSlug("foo bar <wow&:[]'")).toEqual('foo-bar-wow')
expect(generateSlug('foo bar <wow>')).toEqual('foo-bar')
expect(generateSlug('foo bar <a>wow</a>')).toEqual('foo-bar-wow')
})
test('downcases', () => {
expect(generateSlug('fOo BAr')).toEqual('foo-bar')
})
test('generates aria label', () => {
expect(generateSlug.generateAriaLabel('foo bar <a>wow</a>')).toEqual(
'foo bar wow'
)
expect(generateSlug.generateAriaLabel('foo bar ((#wow))')).toEqual('foo bar')
})
test('removes anchor link aliases', () => {
expect(generateSlug('foo bar ((#wow))')).toEqual('foo-bar')
expect(generateSlug('foo bar ((#wow, #amaze))')).toEqual('foo-bar')
expect(generateSlug('foo bar ((wow))')).toEqual('foo-bar-wow')
})