-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.x] Fix hyphens in JS slugs (#10541)
Co-authored-by: Jason Varga <[email protected]>
- Loading branch information
1 parent
f4c8280
commit 8efcedc
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Slug from "../components/slugs/Slug"; | ||
|
||
let config = { | ||
asciiReplaceExtraSymbols: false, | ||
selectedSite: 'en', | ||
sites: [{handle: 'en', lang: 'en'}], | ||
charmap: { | ||
// More values would be in this charmap in reality but this enough for the test. | ||
en: {}, // en *would* be empty by default though. | ||
currency_short: {'$': '$'} | ||
} | ||
} | ||
|
||
window.Statamic = { | ||
$config: { | ||
get: (key) => config[key] | ||
} | ||
} | ||
|
||
test('it slugifies', () => { | ||
expect((new Slug).create('One')).toBe('one'); | ||
expect((new Slug).create('One Two Three')).toBe('one-two-three'); | ||
expect((new Slug).create(`Apple's`)).toBe('apples'); | ||
expect((new Slug).create(`Statamic’s latest feature: “Duplicator”`)).toBe('statamics-latest-feature-duplicator'); | ||
expect((new Slug).separatedBy('_').create('JSON-LD Document')).toBe('json_ld_document'); | ||
expect((new Slug).create('Block - Hero')).toBe('block-hero'); | ||
expect((new Slug).create('10% off over $100 & more')).toBe('10-off-over-100-more'); | ||
}) | ||
|
||
test('it slugifies with extra symbols', () => { | ||
// When setting ascii_replace_extra_symbols to true, these would get set by php. | ||
// There would be more in reality but these are enough for the test. | ||
config.asciiReplaceExtraSymbols = true; | ||
config.charmap.en['%'] = ' percent '; | ||
config.charmap.en['&'] = ' and '; | ||
config.charmap.en['&'] = ' and '; | ||
config.charmap.currency = {'$': ' Dollar '} | ||
|
||
expect((new Slug).create('10% off over $100 & more')).toBe('10-percent-off-over-dollar-100-and-more'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters