Skip to content

Commit

Permalink
Simplifie les tests sur slugify
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Jun 15, 2023
1 parent bcc5d9a commit 51f691e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion front/src/components/Export.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Export ({ bookId, articleVersionId, articleId, bib, name
const [tld, setTld] = useState('false')
const { exportFormats, exportStyles, exportStylesPreview, isLoading } = useStyloExport({ csl, bib })
const { host } = window.location
const exportId = useMemo(() => slugify(name, { strict: true }) || (articleVersionId ?? articleId ?? bookId), [name])
const exportId = useMemo(() => slugify(name, { strict: true, lower: true }) || (articleVersionId ?? articleId ?? bookId), [name])

const exportUrl = bookId
? `${processEndpoint}/cgi-bin/exportBook/exec.cgi?id=${exportId}&book=${bookId}&processor=xelatex&source=${exportEndpoint}/&format=${format}&bibstyle=${csl}&toc=${Boolean(toc)}&tld=${tld}&unnumbered=${unnumbered}`
Expand Down
2 changes: 1 addition & 1 deletion front/src/hooks/pandoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function usePandocAnchoring () {
const state = new Map()

return function getAnchor (string) {
let slug = slugify(string, { strict: true })
let slug = slugify(string, { strict: true, lower: true })

if (state.has(slug)) {
const index = state.get(slug)
Expand Down
24 changes: 5 additions & 19 deletions front/src/hooks/pandoc.test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
import { usePandocAnchoring } from './pandoc.js'

describe('slugify', () => {
test('should match pandoc anchoring', () => {
// echo '# Coucou, comment ça va ?' | pandoc -f markdown -t html
expect(slugify('Coucou, comment ça va ?')).toEqual('coucou-comment-ça-va')
// echo '# [SHARED] How To Stylo?' | pandoc -f markdown -t html
expect(slugify('[SHARED] How To Stylo?')).toEqual('shared-how-to-stylo')
})

test('should match legacy export expectations', () => {
// echo '# Coucou, comment ça va ?' | pandoc -f markdown -t html
expect(slugify('Coucou, comment ça va ?', { diacritics: false })).toEqual('coucou-comment-ca-va')
})
})

describe('usePandocAnchoring()', () => {
test('generate expected anchors', () => {
const getAnchor = usePandocAnchoring()

expect(getAnchor('# Test')).toEqual('test')
expect(getAnchor('## Section Title')).toEqual('section-title')
expect(getAnchor('## Héo')).toEqual('héo')
expect(getAnchor('## Héo')).toEqual('heo')
})

test('handle duplicate headings', () => {
const getAnchor = usePandocAnchoring()

expect(getAnchor('## Héo')).toEqual('héo')
expect(getAnchor('## Héo')).toEqual('héo-1')
expect(getAnchor('## Héo')).toEqual('heo')
expect(getAnchor('## Héo')).toEqual('heo-1')

expect(getAnchor('## Héo 1')).toEqual('héo-1-1')
expect(getAnchor('## Héo 1')).toEqual('héo-1-2')
expect(getAnchor('## Héo 1')).toEqual('heo-1-1')
expect(getAnchor('## Héo 1')).toEqual('heo-1-2')
})
})

0 comments on commit 51f691e

Please sign in to comment.