2021-01-06 07:09:33 -05:00
|
|
|
/*
|
2021-01-06 15:37:59 -05:00
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
2021-01-06 07:09:33 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
|
|
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 16:13:04 -05:00
|
|
|
fill(value: string): Chainable<Element>
|
|
|
|
|
|
|
|
codemirrorFill(value: string): Chainable<Element>
|
2021-01-06 07:09:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cypress.Commands.add('fill', {
|
|
|
|
prevSubject: 'element'
|
|
|
|
}, (subject, value) => {
|
2021-01-15 16:54:43 -05:00
|
|
|
return cy.wrap(subject)
|
2021-02-03 16:13:04 -05:00
|
|
|
.invoke('val', value)
|
|
|
|
.trigger('change', { force: true })
|
2021-01-15 16:54:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add('codemirrorFill', (content: string) => {
|
2021-02-03 16:13:04 -05:00
|
|
|
const line = content.split('\n')
|
|
|
|
.find(value => value !== '')
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.get('.CodeMirror')
|
|
|
|
.click()
|
|
|
|
.get('textarea')
|
|
|
|
.fill(content)
|
2021-02-03 16:13:04 -05:00
|
|
|
if (line) {
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.get('.CodeMirror')
|
2021-02-08 12:29:02 -05:00
|
|
|
.find('.CodeMirror-line')
|
|
|
|
.should('contain.text', line)
|
2021-01-15 16:54:43 -05:00
|
|
|
}
|
2021-01-06 07:09:33 -05:00
|
|
|
})
|