From cfb15dc56931b430991a28fddfaca03f5e7d491c Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 20 Nov 2022 19:42:59 +0100 Subject: [PATCH] Add more tests for the front matter feature 1. Test if the correct front matter content is displayed 2. Test if the front matter survives closing and reopening the editor Skip common mark tests which we correctly interpret as front matter Signed-off-by: Ferdinand Thiessen --- cypress/README.md | 1 + cypress/e2e/FrontMatter.spec.js | 22 +++++++++++++++++++++- cypress/support/commands.js | 4 ++++ src/tests/markdown.spec.js | 7 +++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cypress/README.md b/cypress/README.md index ea071e8fcb0..a0557120a72 100644 --- a/cypress/README.md +++ b/cypress/README.md @@ -22,6 +22,7 @@ cy.getContent() | `createFolder` | Create a folder | `dirName` | | `shareFileToUser` | Share a file with user | `userId`, `password`, `path`, `targetUserId`| | `openFile` | Open file in Viewer / Editor | `fileName`, `clickParams` | +| `closeFile` | Close the current file | | | `getFile` | Get file list element of file | `fileName` | | `deleteFile` | Remove a file | `fileName` | | `reloadFileList` | Refresh the file list | | diff --git a/cypress/e2e/FrontMatter.spec.js b/cypress/e2e/FrontMatter.spec.js index 1a7200779a0..25ac0e9ce0f 100644 --- a/cypress/e2e/FrontMatter.spec.js +++ b/cypress/e2e/FrontMatter.spec.js @@ -33,7 +33,10 @@ describe('Front matter support', function() { it('Open file with front matter', function() { cy.openFile('frontmatter.md').then(() => { - expect(cy.getContent().find('pre.frontmatter').length === 1) + cy.getContent().find('pre.frontmatter').should(pre => { + expect(pre.length === 1) + expect(pre[0].text === 'some: value\nother: 1.2') + }) }) }) @@ -59,4 +62,21 @@ describe('Front matter support', function() { cy.getContent().find('hr').should(hr => expect(hr.length === 1)) }) }) + + it('Reopen front matter', function() { + cy.openFile('frontmatter.md').then(() => { + cy.getContent() + .type('{moveToEnd}New line{enter}') + .find('pre.frontmatter').should(pre => { + expect(pre.length === 1) + }) + .closeFile().then(() => { + cy.openFile('frontmatter.md').then(() => { + cy.getContent().then(() => { + expect(cy.getContent().find('pre.frontmatter').length === 1) + }) + }) + }) + }) + }) }) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 027d4250930..cd0e66ad1d9 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -280,6 +280,10 @@ Cypress.Commands.add('openFile', (fileName, params = {}) => { cy.get(`.files-fileList tr[data-file="${fileName}"] a.name`).click(params) }) +Cypress.Commands.add('closeFile', (fileName, params = {}) => { + cy.get('#viewer .modal-header button.header-close').click(params) +}) + Cypress.Commands.add('getFile', fileName => { return cy.get(`.files-fileList tr[data-file="${fileName}"]`) }) diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index 53b5f659ab1..0e294cd1354 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -24,6 +24,8 @@ const markdownThroughEditorHtml = (html) => { describe('Commonmark', () => { const skippedMarkdownTests = [ + // we interpret this as front matter + 96, 98, // contain HTML 21, 31, 201, 344, 474, 475, 476, 490, 493, 523, 535, 642, 643, // contain comments @@ -174,6 +176,11 @@ describe('Markdown though editor', () => { }) }) + test('front matter', () => { + expect(markdownThroughEditor('---\nhello: world\n---')).toBe('---\nhello: world\n---') + expect(markdownThroughEditor('---\n---')).toBe('---\n---') + }) + test('mentions', () => { expect(markdownThroughEditor('@[username](mention://user/id)')).toBe(' @[username](mention://user/id) ') })