Skip to content

Commit

Permalink
Added tests for the front matter node
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
  • Loading branch information
susnux committed Jul 28, 2022
1 parent cfa070e commit ad1b431
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
62 changes: 62 additions & 0 deletions cypress/e2e/FrontMatter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @copyright Copyright (c) 2022
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { initUserAndFiles, randHash } from '../utils/index.js'

const randUser = randHash()

describe('Front matter support', function() {
before(function() {
initUserAndFiles(randUser, 'frontmatter.md', 'empty.md')
})

beforeEach(function() {
cy.login(randUser, 'password')
})

it('Open file with front matter', function() {
cy.openFile('frontmatter.md').then(() => {
expect(cy.getContent().find('pre.frontmatter').length === 1)
})
})

it('Add front matter', function() {
cy.openFile('empty.md').clearContent().then(() => {
cy.getContent()
.type('---')
.type('test')
cy.getContent().find('pre.frontmatter').should(pre => {
expect(pre.length === 1)
expect(pre[0].text === 'test')
})
})
})

it('Do not add multiple front matter', function() {
cy.openFile('empty.md').clearContent().then(() => {
cy.getContent()
.type('---test')
.type('{downArrow}')
.type('---test')
cy.getContent().find('pre.frontmatter').should(pre => expect(pre.length === 1))
cy.getContent().find('hr').should(hr => expect(hr.length === 1))
})
})
})
6 changes: 6 additions & 0 deletions cypress/fixtures/frontmatter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
some: value
other: 1.2
---
# Heading
Content
6 changes: 6 additions & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,10 @@ describe('Markdown serializer from html', () => {
`<p class="callout warning">!warning!</p>`
)).toBe(`::: warn\n!warning!\n\n:::`)
})

test('front matter', () => {
expect(markdownThroughEditorHtml('<pre id="frontmatter"><code>some: value</code></pre><h1>Heading</h1>')).toBe('---\nsome: value\n---\n\n# Heading')
// Test --- within front matter is allowed
expect(markdownThroughEditorHtml('<pre id="frontmatter"><code>---</code></pre><h1>Heading</h1>')).toBe('----\n---\n----\n\n# Heading')
})
})

0 comments on commit ad1b431

Please sign in to comment.