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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 17:04:04 +00:00
|
|
|
Cypress.Commands.add(
|
|
|
|
'fill',
|
|
|
|
{
|
|
|
|
prevSubject: 'element'
|
|
|
|
},
|
|
|
|
(subject, value) => {
|
|
|
|
return cy.wrap(subject).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-11-19 17:04:04 +00:00
|
|
|
const line = content.split('\n').find((value) => value !== '')
|
|
|
|
cy.get('.CodeMirror').click().get('textarea').type('{ctrl}a').type('{backspace}').fill(content)
|
2021-02-03 21:13:04 +00:00
|
|
|
if (line) {
|
2021-11-19 17:04:04 +00:00
|
|
|
cy.get('.CodeMirror').find('.CodeMirror-line').should('contain.text', line)
|
2021-01-15 21:54:43 +00:00
|
|
|
}
|
2021-01-06 12:09:33 +00:00
|
|
|
})
|