2021-01-13 05:52:06 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-01-24 14:50:51 -05:00
|
|
|
const findHljsCodeBlock = () => {
|
|
|
|
return cy.getMarkdownBody()
|
2021-02-03 16:13:04 -05:00
|
|
|
.find('pre > code.hljs')
|
|
|
|
.should('be.visible')
|
2021-01-24 14:50:51 -05:00
|
|
|
}
|
|
|
|
|
2021-01-13 05:52:06 -05:00
|
|
|
describe('Code', () => {
|
|
|
|
beforeEach(() => {
|
2021-02-01 16:55:49 -05:00
|
|
|
cy.visitTestEditor()
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('with just the language', () => {
|
|
|
|
it('doesn\'t show a gutter', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript \nlet x = 0\n```')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('not.have.class', 'showGutter')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
|
|
|
findHljsCodeBlock()
|
|
|
|
.find('.linenumber')
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('not.be.visible')
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
|
|
|
it('doesn\'t show a gutter', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript! \nlet x = 0\n```')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('not.have.class', 'showGutter')
|
|
|
|
.should('have.class', 'wrapLines')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
|
|
|
findHljsCodeBlock()
|
|
|
|
.find('.linenumber')
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('not.be.visible')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with the language and show gutter', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript= \nlet x = 0\n```')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('have.class', 'showGutter')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
|
|
|
findHljsCodeBlock()
|
|
|
|
.find('.linenumber')
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '1')
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript=! \nlet x = 0\n```')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('have.class', 'showGutter')
|
|
|
|
.should('have.class', 'wrapLines')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
|
|
|
findHljsCodeBlock()
|
|
|
|
.find('.linenumber')
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '1')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with the language, show gutter with a start number', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript=100 \nlet x = 0\n```')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('have.class', 'showGutter')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
|
|
|
findHljsCodeBlock()
|
|
|
|
.find('.linenumber')
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '100')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows the correct line number and continues in another codeblock', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript=100 \nlet x = 0\nlet y = 1\n```\n\n```javascript=+\nlet y = 2\n```\n')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('have.class', 'showGutter')
|
|
|
|
.first()
|
|
|
|
.find('.linenumber')
|
|
|
|
.first()
|
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '100')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.first()
|
|
|
|
.find('.linenumber')
|
|
|
|
.last()
|
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '101')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.last()
|
|
|
|
.find('.linenumber')
|
|
|
|
.first()
|
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '102')
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript=100! \nlet x = 0\n```')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('have.class', 'showGutter')
|
|
|
|
.should('have.class', 'wrapLines')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
|
|
|
.find('.linenumber')
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '100')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows the correct line number and continues in another codeblock', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript=100! \nlet x = 0\nlet y = 1\n```\n\n```javascript=+\nlet y = 2\n```\n')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.should('have.class', 'showGutter')
|
|
|
|
.should('have.class', 'wrapLines')
|
|
|
|
.first()
|
|
|
|
.find('.linenumber')
|
|
|
|
.first()
|
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '100')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.first()
|
|
|
|
.find('.linenumber')
|
|
|
|
.last()
|
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '101')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.last()
|
|
|
|
.find('.linenumber')
|
|
|
|
.first()
|
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '102')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('has a working copy button', () => {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill('```javascript \nlet x = 0\n```')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
|
|
|
cy.get(`iframe[data-cy="documentIframe"]`)
|
|
|
|
.then(($element: JQuery) => {
|
|
|
|
const frame = $element[0] as HTMLIFrameElement
|
|
|
|
if (frame === null || frame.contentWindow === null) {
|
|
|
|
return cy.wrap(null)
|
|
|
|
}
|
|
|
|
|
2021-02-03 16:13:04 -05:00
|
|
|
cy.spy(frame.contentWindow.navigator.clipboard, 'writeText')
|
|
|
|
.as('copy')
|
2021-01-24 14:50:51 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
cy.getMarkdownRenderer()
|
|
|
|
.find('[data-cy="copy-code-button"]')
|
2021-01-13 05:52:06 -05:00
|
|
|
.click()
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-02-03 16:13:04 -05:00
|
|
|
cy.get('@copy')
|
2021-01-24 14:50:51 -05:00
|
|
|
.should('be.calledWithExactly', 'let x = 0\n')
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
})
|