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-09-16 15:07:27 -04:00
|
|
|
return cy.getMarkdownBody().find('.code-highlighter > 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', () => {
|
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-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().should('not.have.class', 'showGutter')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().find('.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-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().should('not.have.class', 'showGutter').should('have.class', 'wrapLines')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().find('.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-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().should('have.class', 'showGutter')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().find('.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-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().should('have.class', 'showGutter').should('have.class', 'wrapLines')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().find('.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-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().should('have.class', 'showGutter')
|
2021-01-24 14:50:51 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().find('.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-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-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().first().find('.linenumber').last().should('be.visible').text().should('eq', '101')
|
|
|
|
findHljsCodeBlock().last().find('.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-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().should('have.class', 'showGutter').should('have.class', 'wrapLines')
|
|
|
|
findHljsCodeBlock().find('.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-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-11-19 12:04:04 -05:00
|
|
|
findHljsCodeBlock().first().find('.linenumber').last().should('be.visible').text().should('eq', '101')
|
|
|
|
findHljsCodeBlock().last().find('.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-11-19 12:04:04 -05:00
|
|
|
cy.getById('documentIframe').then((element: JQuery<HTMLElement>) => {
|
|
|
|
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-11-19 12:04:04 -05:00
|
|
|
cy.getIframeBody().findById('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
|
|
|
})
|
|
|
|
})
|