2021-01-13 10:52:06 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-01-24 19:50:51 +00:00
|
|
|
const findHljsCodeBlock = () => {
|
2021-12-25 15:44:24 +00:00
|
|
|
return cy.getMarkdownBody().findByCypressId('code-highlighter').should('be.visible')
|
2021-01-24 19:50:51 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 10:52:06 +00:00
|
|
|
describe('Code', () => {
|
|
|
|
beforeEach(() => {
|
2021-02-01 21:55:49 +00:00
|
|
|
cy.visitTestEditor()
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('with just the language', () => {
|
2021-11-19 17:04:04 +00:00
|
|
|
it("doesn't show a gutter", () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript \nlet x = 0\n```')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'false')
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('not.be.visible')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
2021-11-19 17:04:04 +00:00
|
|
|
it("doesn't show a gutter", () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript! \nlet x = 0\n```')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'false')
|
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-wrapLines', 'true')
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('not.be.visible')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with the language and show gutter', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript= \nlet x = 0\n```')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('be.visible').text().should('eq', '1')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript=! \nlet x = 0\n```')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-wrapLines', 'true')
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('be.visible').text().should('eq', '1')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with the language, show gutter with a start number', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript=100 \nlet x = 0\n```')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('be.visible').text().should('eq', '100')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows the correct line number and continues in another codeblock', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript=100 \nlet x = 0\nlet y = 1\n```\n\n```javascript=+\nlet y = 2\n```\n')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
|
|
|
findHljsCodeBlock().first().findByCypressId('linenumber').first().should('be.visible').text().should('eq', '100')
|
|
|
|
findHljsCodeBlock().first().findByCypressId('linenumber').last().should('be.visible').text().should('eq', '101')
|
|
|
|
findHljsCodeBlock().last().findByCypressId('linenumber').first().should('be.visible').text().should('eq', '102')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript=100! \nlet x = 0\n```')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-wrapLines', 'true')
|
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('be.visible').text().should('eq', '100')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows the correct line number and continues in another codeblock', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript=100! \nlet x = 0\nlet y = 1\n```\n\n```javascript=+\nlet y = 2\n```\n')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-wrapLines', 'true')
|
2021-01-24 19:50:51 +00:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 10:52:06 +00:00
|
|
|
.first()
|
2021-12-25 15:44:24 +00:00
|
|
|
.findByCypressId('linenumber')
|
2021-01-13 10:52:06 +00:00
|
|
|
.first()
|
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '100')
|
2021-12-25 15:44:24 +00:00
|
|
|
findHljsCodeBlock().first().findByCypressId('linenumber').last().should('be.visible').text().should('eq', '101')
|
|
|
|
findHljsCodeBlock().last().findByCypressId('linenumber').first().should('be.visible').text().should('eq', '102')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('has a working copy button', () => {
|
2021-10-04 10:50:39 +00:00
|
|
|
cy.setCodemirrorContent('```javascript \nlet x = 0\n```')
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-12-25 15:44:24 +00:00
|
|
|
cy.getByCypressId('documentIframe').then((element: JQuery<HTMLElement>) => {
|
2021-11-19 17:04:04 +00:00
|
|
|
const frame = element.get(0) as HTMLIFrameElement
|
|
|
|
if (frame === null || frame.contentWindow === null) {
|
|
|
|
return cy.wrap(null)
|
|
|
|
}
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-11-19 17:04:04 +00:00
|
|
|
cy.spy(frame.contentWindow.navigator.clipboard, 'writeText').as('copy')
|
|
|
|
})
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-12-25 15:44:24 +00:00
|
|
|
cy.getIframeBody().findByCypressId('copy-code-button').click()
|
2021-01-24 19:50:51 +00:00
|
|
|
|
2021-11-19 17:04:04 +00:00
|
|
|
cy.get('@copy').should('be.calledWithExactly', 'let x = 0\n')
|
2021-01-13 10:52:06 +00:00
|
|
|
})
|
|
|
|
})
|