Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <[email protected]>
  • Loading branch information
susnux committed Nov 24, 2022
commit 536eb4a506a43d89f51e1c2bc78d7bd9f104ae81
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 @@ -269,6 +269,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
9 changes: 8 additions & 1 deletion src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ describe('Commonmark', () => {

// failures because of some additional newline in markdownit
const skippedMarkdownTests = [
187, 209, 210
187, 209, 210,
// We interpret these as front matter
66, 68
];

const normalize = (str) => {
Expand Down Expand Up @@ -188,6 +190,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