2020-11-22 20:50:07 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2020-09-22 21:17:19 +00:00
|
|
|
describe('Code', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-28 21:35:14 +00:00
|
|
|
cy.visit('/n/test', {
|
|
|
|
onBeforeLoad (win: Window): void {
|
|
|
|
cy.spy(win.navigator.clipboard, 'writeText').as('copy')
|
|
|
|
}
|
|
|
|
})
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.btn.active.btn-outline-secondary > i.fa-columns')
|
|
|
|
.should('exist')
|
|
|
|
cy.get('.CodeMirror textarea')
|
|
|
|
.type('{ctrl}a', { force: true })
|
|
|
|
.type('{backspace}')
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('without = doesn\'t show gutter', () => {
|
2020-11-01 20:38:17 +00:00
|
|
|
it('without wrapLines active', () => {
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.CodeMirror textarea')
|
2020-11-01 20:38:17 +00:00
|
|
|
.type('```javascript \nlet x = 0\n```')
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.markdown-body > pre > code')
|
|
|
|
.should('have.class', 'hljs')
|
|
|
|
})
|
|
|
|
|
2020-11-01 20:38:17 +00:00
|
|
|
it('with wrapLines active', () => {
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.CodeMirror textarea')
|
2020-11-01 20:38:17 +00:00
|
|
|
.type('```javascript!\nlet x = 0\n```')
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.markdown-body > pre > code')
|
|
|
|
.should('have.class', 'hljs')
|
|
|
|
.should('have.class', 'wrapLines')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with = shows gutter', () => {
|
2020-11-01 20:38:17 +00:00
|
|
|
it('without wrapLines active', () => {
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.CodeMirror textarea')
|
2020-11-01 20:38:17 +00:00
|
|
|
.type('```javascript=\nlet x = 0\n```')
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.markdown-body > pre > code')
|
|
|
|
.should('have.class', 'hljs')
|
|
|
|
.should('have.class', 'showGutter')
|
|
|
|
cy.get('.markdown-body > pre > code > span')
|
|
|
|
.should('have.class', 'linenumber')
|
|
|
|
.should('have.attr', 'data-line-number', '1')
|
|
|
|
})
|
|
|
|
|
2020-11-01 20:38:17 +00:00
|
|
|
it('with wrapLines active', () => {
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.CodeMirror textarea')
|
2020-11-01 20:38:17 +00:00
|
|
|
.type('```javascript=! \nlet x = 0\n```')
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.markdown-body > pre > code')
|
|
|
|
.should('have.class', 'hljs')
|
|
|
|
.should('have.class', 'showGutter')
|
|
|
|
.should('have.class', 'wrapLines')
|
|
|
|
cy.get('.markdown-body > pre > code > span')
|
|
|
|
.should('have.class', 'linenumber')
|
|
|
|
.should('have.attr', 'data-line-number', '1')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with = shows gutter and number is used as startline', () => {
|
2020-11-01 20:38:17 +00:00
|
|
|
it('without wrapLines active', () => {
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.CodeMirror textarea')
|
2020-11-01 20:38:17 +00:00
|
|
|
.type('```javascript=100\nlet x = 0\n```')
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.markdown-body > pre > code')
|
|
|
|
.should('have.class', 'hljs')
|
|
|
|
.should('have.class', 'showGutter')
|
|
|
|
cy.get('.markdown-body > pre > code > span')
|
|
|
|
.should('have.class', 'linenumber')
|
|
|
|
.should('have.attr', 'data-line-number', '100')
|
|
|
|
})
|
|
|
|
|
2020-11-01 20:38:17 +00:00
|
|
|
it('with wrapLines active', () => {
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.CodeMirror textarea')
|
2020-11-01 20:38:17 +00:00
|
|
|
.type('```javascript=100! \nlet x = 0\n```')
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.markdown-body > pre > code')
|
|
|
|
.should('have.class', 'hljs')
|
|
|
|
.should('have.class', 'showGutter')
|
|
|
|
.should('have.class', 'wrapLines')
|
|
|
|
cy.get('.markdown-body > pre > code > span')
|
|
|
|
.should('have.class', 'linenumber')
|
|
|
|
.should('have.attr', 'data-line-number', '100')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('has a button', () => {
|
|
|
|
cy.get('.CodeMirror textarea')
|
2020-11-01 20:38:17 +00:00
|
|
|
.type('```javascript \nlet x = 0\n```')
|
2020-09-22 21:17:19 +00:00
|
|
|
cy.get('.markdown-body > pre > div > button > i')
|
|
|
|
.should('have.class', 'fa-files-o')
|
|
|
|
.click()
|
2020-11-28 21:35:14 +00:00
|
|
|
cy.get('@copy').should('be.calledWithExactly', 'let x = 0\n');
|
2020-09-22 21:17:19 +00:00
|
|
|
})
|
|
|
|
})
|