Skip to content

Commit

Permalink
Add more tests for the front matter feature
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
susnux committed Nov 20, 2022
1 parent 9e820c6 commit cfb15dc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
22 changes: 21 additions & 1 deletion cypress/e2e/FrontMatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})

Expand All @@ -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)
})
})
})
})
})
})
4 changes: 4 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]`)
})
Expand Down
7 changes: 7 additions & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) ')
})
Expand Down

0 comments on commit cfb15dc

Please sign in to comment.