Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFerdinand Thiessen <rpm@fthiessen.de>2022-07-26 10:59:05 +0300
committerFerdinand Thiessen <rpm@fthiessen.de>2022-07-29 17:07:56 +0300
commit22dbde70bca429a6913d072888e9c31679069406 (patch)
tree8e7f87d68dabc518528d1df199baefc1a6473530
parent9642367e94ff22877b153b091bb5997f8c10efb7 (diff)
Added tests for the front matter node
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
-rw-r--r--cypress/e2e/FrontMatter.spec.js62
-rw-r--r--cypress/fixtures/frontmatter.md6
-rw-r--r--src/tests/markdown.spec.js6
3 files changed, 74 insertions, 0 deletions
diff --git a/cypress/e2e/FrontMatter.spec.js b/cypress/e2e/FrontMatter.spec.js
new file mode 100644
index 000000000..1a7200779
--- /dev/null
+++ b/cypress/e2e/FrontMatter.spec.js
@@ -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))
+ })
+ })
+})
diff --git a/cypress/fixtures/frontmatter.md b/cypress/fixtures/frontmatter.md
new file mode 100644
index 000000000..5698c55c5
--- /dev/null
+++ b/cypress/fixtures/frontmatter.md
@@ -0,0 +1,6 @@
+---
+some: value
+other: 1.2
+---
+# Heading
+Content \ No newline at end of file
diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js
index ae7ed3cfe..ca4b26436 100644
--- a/src/tests/markdown.spec.js
+++ b/src/tests/markdown.spec.js
@@ -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')
+ })
})