Skip to content

Commit

Permalink
✅ (#107): add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
  • Loading branch information
Vinicius Reis committed Jul 8, 2022
1 parent eb4b7d6 commit fbb3dc6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cypress/e2e/outline.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { randHash } from '../utils/index.js'

const currentUser = randHash()

const refresh = () => cy.get('#controls .crumb:not(.hidden) a')
.last()
.click({ force: true })

const createMarkdown = (fileName, content) => {
return cy.createFile(fileName, content, 'text/markdown')
.then(refresh)
}

describe('Table of Contents', () => {
before(() => {
// Init user
cy.nextcloudCreateUser(currentUser, 'password')
cy.login(currentUser, 'password')
})

beforeEach(() => {
cy.login(currentUser, 'password')
})

it('sidebar toc', () => {
const fileName = 'toc.md'

createMarkdown(fileName, '# T1 \n ## T2 \n ### T3 \n #### T4 \n ##### T5 \n ###### T6')
.then(refresh)
.then(() => cy.openFile(fileName))

cy.getTOC()
.find('ul li')
.should('have.length', 6)
cy.getTOC()
.find('ul li')
.each((el, index) => {
cy.wrap(el)
.should('have.attr', 'data-toc-level')
.and('equal', String(index + 1))

cy.wrap(el)
.find('a')
.should('have.attr', 'href')
.and('equal', `#t${index + 1}`)
})
})
})
8 changes: 8 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ Cypress.Commands.add('getContent', () => {
return cy.getEditor().find('.ProseMirror')
})

Cypress.Commands.add('getOutline', () => {
return cy.getEditor().find('[data-text-el="editor-outline"]')
})

Cypress.Commands.add('getTOC', () => {
return cy.getEditor().find('[data-text-el="editor-table-of-contents"]')
})

Cypress.Commands.add('clearContent', () => {
return cy.getContent()
.type('{selectall}')
Expand Down
1 change: 1 addition & 0 deletions src/components/TableOfContents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class="editor--toc__list">
<li v-for="(heading) in headings"
:key="heading.id"
:data-toc-level="heading.level"
class="editor--toc__item"
:class="`editor--toc__item--${heading.level}`">
<a :href="`#${heading.id}`" @click.prevent="goto(heading)">
Expand Down

0 comments on commit fbb3dc6

Please sign in to comment.