mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
refactor(common): extract frontmatter code into commons
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
a78ac5f097
commit
8bd7fd1be8
26 changed files with 433 additions and 121 deletions
58
commons/src/title-extraction/generate-note-title.spec.ts
Normal file
58
commons/src/title-extraction/generate-note-title.spec.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { generateNoteTitle } from './generate-note-title.js'
|
||||
import { NoteFrontmatter, NoteTextDirection } from './types/frontmatter.js'
|
||||
import { NoteType } from './types/frontmatter.js'
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
|
||||
const testFrontmatter: NoteFrontmatter = {
|
||||
title: '',
|
||||
description: '',
|
||||
tags: [],
|
||||
robots: '',
|
||||
lang: 'en',
|
||||
dir: NoteTextDirection.LTR,
|
||||
newlinesAreBreaks: true,
|
||||
GA: '',
|
||||
disqus: '',
|
||||
license: '',
|
||||
type: NoteType.DOCUMENT,
|
||||
opengraph: {},
|
||||
slideOptions: {
|
||||
transition: 'zoom',
|
||||
autoSlide: 0,
|
||||
autoSlideStoppable: true,
|
||||
backgroundTransition: 'fade',
|
||||
slideNumber: false
|
||||
}
|
||||
}
|
||||
|
||||
describe('generate note title', () => {
|
||||
it('will choose the frontmatter title first', () => {
|
||||
const actual = generateNoteTitle(
|
||||
{
|
||||
...testFrontmatter,
|
||||
title: 'frontmatter',
|
||||
opengraph: { title: 'opengraph' }
|
||||
},
|
||||
'first-heading'
|
||||
)
|
||||
expect(actual).toEqual('frontmatter')
|
||||
})
|
||||
|
||||
it('will choose the opengraph title second', () => {
|
||||
const actual = generateNoteTitle(
|
||||
{ ...testFrontmatter, opengraph: { title: 'opengraph' } },
|
||||
'first-heading'
|
||||
)
|
||||
expect(actual).toEqual('opengraph')
|
||||
})
|
||||
|
||||
it('will choose the first heading third', () => {
|
||||
const actual = generateNoteTitle({ ...testFrontmatter }, 'first-heading')
|
||||
expect(actual).toEqual('first-heading')
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue