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 = () => {
|
2021-12-25 10:44:24 -05:00
|
|
|
return cy.getMarkdownBody().findByCypressId('code-highlighter').should('be.visible')
|
2021-01-24 14:50:51 -05:00
|
|
|
}
|
|
|
|
|
2021-01-13 05:52:06 -05:00
|
|
|
describe('Code', () => {
|
|
|
|
beforeEach(() => {
|
2022-01-30 15:46:43 -05:00
|
|
|
cy.visitTestNote()
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('with just the language', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
it("doesn't show a gutter", () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript \nlet x = 0\n```')
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'false')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('not.be.visible')
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
it("doesn't show a gutter", () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript! \nlet x = 0\n```')
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'false')
|
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-wrapLines', 'true')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('not.be.visible')
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with the language and show gutter', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript= \nlet x = 0\n```')
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('be.visible').text().should('eq', '1')
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript=! \nlet x = 0\n```')
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-wrapLines', 'true')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('be.visible').text().should('eq', '1')
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with the language, show gutter with a start number', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript=100 \nlet x = 0\n```')
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().findByCypressId('linenumber').should('be.visible').text().should('eq', '100')
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows the correct line number and continues in another codeblock', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript=100 \nlet x = 0\nlet y = 1\n```\n\n```javascript=+\nlet y = 2\n```\n')
|
2021-12-25 10:44:24 -05: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 05:52:06 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('and line wrapping', () => {
|
|
|
|
it('shows the correct line number', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript=100! \nlet x = 0\n```')
|
2021-12-25 10:44:24 -05: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 05:52:06 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows the correct line number and continues in another codeblock', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript=100! \nlet x = 0\nlet y = 1\n```\n\n```javascript=+\nlet y = 2\n```\n')
|
2021-12-25 10:44:24 -05:00
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-showgutter', 'true')
|
|
|
|
findHljsCodeBlock().should('have.attr', 'data-cypress-wrapLines', 'true')
|
2021-01-24 14:50:51 -05:00
|
|
|
findHljsCodeBlock()
|
2021-01-13 05:52:06 -05:00
|
|
|
.first()
|
2021-12-25 10:44:24 -05:00
|
|
|
.findByCypressId('linenumber')
|
2021-01-13 05:52:06 -05:00
|
|
|
.first()
|
|
|
|
.should('be.visible')
|
|
|
|
.text()
|
|
|
|
.should('eq', '100')
|
2021-12-25 10:44:24 -05: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 05:52:06 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('has a working copy button', () => {
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('```javascript \nlet x = 0\n```')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('documentIframe').then((element: JQuery<HTMLElement>) => {
|
2021-11-19 12:04:04 -05:00
|
|
|
const frame = element.get(0) as HTMLIFrameElement
|
|
|
|
if (frame === null || frame.contentWindow === null) {
|
|
|
|
return cy.wrap(null)
|
|
|
|
}
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.spy(frame.contentWindow.navigator.clipboard, 'writeText').as('copy')
|
|
|
|
})
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getIframeBody().findByCypressId('copy-code-button').click()
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('@copy').should('be.calledWithExactly', 'let x = 0\n')
|
2021-01-13 05:52:06 -05:00
|
|
|
})
|
|
|
|
})
|