2020-11-22 15:50:07 -05:00
|
|
|
/*
|
2021-01-06 15:37:59 -05:00
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
2020-11-22 15:50:07 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
describe('Toolbar Buttons', () => {
|
2021-01-11 17:22:11 -05:00
|
|
|
const testText = 'textText'
|
|
|
|
const testLink = 'http://hedgedoc.org'
|
|
|
|
|
2020-08-14 19:39:48 -04:00
|
|
|
beforeEach(() => {
|
2021-02-01 16:55:49 -05:00
|
|
|
cy.visitTestEditor()
|
2021-01-11 17:22:11 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror').click().get('textarea').as('codeinput')
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
describe('for single line text', () => {
|
|
|
|
beforeEach(() => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(testText)
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror-line > span').should('exist').should('have.text', testText)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
2020-08-14 19:39:48 -04:00
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
describe('with selection', () => {
|
|
|
|
beforeEach(() => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('@codeinput').type('{ctrl}a')
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format as bold', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-bold').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `**${testText}**`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format as italic', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-italic').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `*${testText}*`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format as underline', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-underline').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `++${testText}++`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format as strikethrough', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.btn-toolbar [data-cypress-id="format-strikethrough').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `~~${testText}~~`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format as subscript', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-subscript').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `~${testText}~`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format as superscript', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-superscript').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `^${testText}^`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format the line as code block', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-code-block').click()
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span').should('have.text', '```')
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(2) > .CodeMirror-line > span span').should('have.text', testText)
|
|
|
|
cy.get('.CodeMirror-code > div.CodeMirror-activeline > .CodeMirror-line > span span').should(
|
|
|
|
'have.text',
|
|
|
|
'```'
|
|
|
|
)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format links', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-link').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `[${testText}](https://)`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should format as image', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-image').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `![${testText}](https://)`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
})
|
2020-08-14 19:39:48 -04:00
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should format line as heading', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-heading').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `# ${testText}`)
|
|
|
|
cy.get('.fa-header').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `## ${testText}`)
|
2020-08-19 15:26:22 -04:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should format the line as code', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-code-block').click()
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span').should('have.text', '```')
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(2) > .CodeMirror-line > span span').should('have.text', testText)
|
|
|
|
cy.get('.CodeMirror-code > div.CodeMirror-activeline > .CodeMirror-line > span span').should('have.text', '```')
|
2020-08-19 15:26:22 -04:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should add a quote', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-block-quote').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `> ${testText}`)
|
|
|
|
cy.getById('format-block-quote').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `> > ${testText}`)
|
2020-08-19 15:26:22 -04:00
|
|
|
})
|
2020-08-14 19:39:48 -04:00
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should format as unordered list', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-unordered-list').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `- ${testText}`)
|
|
|
|
cy.getById('format-unordered-list').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `- - ${testText}`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
2020-08-14 19:39:48 -04:00
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should format as ordered list', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-ordered-list').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `1. ${testText}`)
|
|
|
|
cy.getById('format-ordered-list').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `1. 1. ${testText}`)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
2020-08-14 19:39:48 -04:00
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should format as check list', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-check-list').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `- [ ] ${testText}`)
|
|
|
|
cy.getById('format-check-list').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `- [ ] - [ ] ${testText}`)
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should insert links', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-link').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `${testText}[](https://)`)
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should insert an empty image link', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-image').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `${testText}![](https://)`)
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
describe('for single line link with selection', () => {
|
|
|
|
beforeEach(() => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent(testLink)
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror-line > span').should('exist').should('have.text', testLink)
|
|
|
|
cy.get('@codeinput').type('{ctrl}a')
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should format as link', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-link').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `[](${testLink})`)
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should format as image', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-image').click()
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `![](${testLink})`)
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
describe('for no text', () => {
|
|
|
|
it('should add an empty code block', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-code-block').click()
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span').should('have.text', '```')
|
|
|
|
cy.get('.CodeMirror-code > div.CodeMirror-activeline > .CodeMirror-line > span span').should('have.text', '```')
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should insert lines', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-add-line').click()
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(2) > .CodeMirror-line > span span').should('have.text', '----')
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should add a collapsable block', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-collapsable-block').click()
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(2) > .CodeMirror-line > span span').should(
|
|
|
|
'have.text',
|
|
|
|
':::spoiler Toggle label'
|
|
|
|
)
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should add a comment', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('format-add-comment').click()
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(2) > .CodeMirror-line > span span').should('have.text', '> []')
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('for new tables', () => {
|
2020-11-29 07:17:40 -05:00
|
|
|
beforeEach(() => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.table-picker-container').should('not.be.visible')
|
|
|
|
cy.getById('show-table-overlay').last().click()
|
|
|
|
cy.get('.table-picker-container').should('be.visible')
|
2020-11-29 07:17:40 -05:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should open an overlay', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.table-container > div:nth-of-type(25)').trigger('mouseover')
|
|
|
|
cy.get('.table-cell.bg-primary').should('have.length', 15)
|
|
|
|
cy.get('.table-picker-container > p').contains('5x3')
|
|
|
|
cy.get('.table-container > div:nth-of-type(25)').click()
|
2020-11-29 07:17:40 -05:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
it('should open a modal for custom table sizes in the overlay', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.modal-dialog').should('not.exist')
|
|
|
|
cy.getById('show-custom-table-modal').first().click()
|
|
|
|
cy.get('.modal-dialog').should('be.visible')
|
|
|
|
cy.get('.modal-content > .d-flex > input').first().type('5')
|
|
|
|
cy.get('.modal-content > .d-flex > input').last().type('3')
|
|
|
|
cy.get('.modal-footer > button').click()
|
2020-11-29 07:17:40 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(2) > .CodeMirror-line > span span').should(
|
|
|
|
'have.text',
|
|
|
|
'| # 1 | # 2 | # 3 | # 4 | # 5 |'
|
|
|
|
)
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(3) > .CodeMirror-line > span span').should(
|
|
|
|
'have.text',
|
|
|
|
'| ---- | ---- | ---- | ---- | ---- |'
|
|
|
|
)
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(4) > .CodeMirror-line > span span').should(
|
|
|
|
'have.text',
|
|
|
|
'| Text | Text | Text | Text | Text |'
|
|
|
|
)
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(5) > .CodeMirror-line > span span').should(
|
|
|
|
'have.text',
|
|
|
|
'| Text | Text | Text | Text | Text |'
|
|
|
|
)
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span ').should(
|
|
|
|
'have.text',
|
|
|
|
'| Text | Text | Text | Text | Text |'
|
|
|
|
)
|
2020-11-29 07:17:40 -05:00
|
|
|
})
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
|
2021-01-15 16:54:43 -05:00
|
|
|
describe('for the emoji-picker', () => {
|
|
|
|
it('should open overlay', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('emoji-picker').should('not.be.visible')
|
|
|
|
cy.getById('show-emoji-picker').click()
|
|
|
|
cy.get('emoji-picker').should('be.visible')
|
2020-08-14 19:39:48 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|