2021-01-06 12:09:33 +00:00
|
|
|
/*
|
2021-01-06 20:37:59 +00:00
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
2021-01-06 12:09:33 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare namespace Cypress {
|
|
|
|
interface Chainable {
|
|
|
|
/**
|
|
|
|
* Custom command to fill an input field with text and trigger a change event.
|
|
|
|
* @example cy.get(input).fill('content')
|
|
|
|
*/
|
2021-02-03 21:13:04 +00:00
|
|
|
fill(value: string): Chainable<Element>
|
|
|
|
|
2021-10-04 10:50:39 +00:00
|
|
|
setCodemirrorContent(value: string): Chainable<Element>
|
2021-01-06 12:09:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cypress.Commands.add('fill', {
|
|
|
|
prevSubject: 'element'
|
|
|
|
}, (subject, value) => {
|
2021-01-15 21:54:43 +00:00
|
|
|
return cy.wrap(subject)
|
2021-02-03 21:13:04 +00:00
|
|
|
.invoke('val', value)
|
|
|
|
.trigger('change', { force: true })
|
2021-01-15 21:54:43 +00:00
|
|
|
})
|
|
|
|
|
2021-10-04 10:50:39 +00:00
|
|
|
Cypress.Commands.add('setCodemirrorContent', (content: string) => {
|
2021-02-03 21:13:04 +00:00
|
|
|
const line = content.split('\n')
|
|
|
|
.find(value => value !== '')
|
2021-01-15 21:54:43 +00:00
|
|
|
cy.get('.CodeMirror')
|
|
|
|
.click()
|
|
|
|
.get('textarea')
|
2021-10-04 10:50:39 +00:00
|
|
|
.type('{ctrl}a')
|
|
|
|
.type('{backspace}')
|
2021-01-15 21:54:43 +00:00
|
|
|
.fill(content)
|
2021-02-03 21:13:04 +00:00
|
|
|
if (line) {
|
2021-01-15 21:54:43 +00:00
|
|
|
cy.get('.CodeMirror')
|
2021-02-08 17:29:02 +00:00
|
|
|
.find('.CodeMirror-line')
|
|
|
|
.should('contain.text', line)
|
2021-01-15 21:54:43 +00:00
|
|
|
}
|
2021-01-06 12:09:33 +00:00
|
|
|
})
|