2020-12-16 17:07:09 -05:00
|
|
|
/*
|
2021-01-06 15:37:59 -05:00
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
2020-12-16 17:07:09 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
const imageUrl = 'http://example.com/non-existing.png'
|
|
|
|
|
2021-01-11 17:22:11 -05:00
|
|
|
describe('File upload', () => {
|
2020-12-16 17:07:09 -05:00
|
|
|
beforeEach(() => {
|
2021-02-01 16:55:49 -05:00
|
|
|
cy.visitTestEditor()
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
it("doesn't prevent drag'n'drop of plain text", () => {
|
2020-12-16 17:07:09 -05:00
|
|
|
const dataTransfer = new DataTransfer()
|
2021-10-04 06:50:39 -04:00
|
|
|
cy.setCodemirrorContent('line 1\nline 2\ndragline')
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror').click()
|
|
|
|
cy.get('.CodeMirror-line > span').last().dblclick()
|
|
|
|
cy.get('.CodeMirror-line > span > .cm-matchhighlight').trigger('dragstart', { dataTransfer })
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span').trigger('drop', { dataTransfer })
|
|
|
|
cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span').should(
|
|
|
|
'have.text',
|
|
|
|
'lindraglinee 1'
|
|
|
|
)
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
describe('works', () => {
|
2020-12-16 17:07:09 -05:00
|
|
|
beforeEach(() => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.intercept(
|
|
|
|
{
|
|
|
|
method: 'GET',
|
|
|
|
url: '/mock-backend/api/private/media/upload-post'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statusCode: 200,
|
|
|
|
body: {
|
|
|
|
link: imageUrl
|
|
|
|
}
|
2020-12-16 17:07:09 -05:00
|
|
|
}
|
2021-11-19 12:04:04 -05:00
|
|
|
)
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
|
|
|
it('via button', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.getById('editor-toolbar-upload-image-button').click()
|
|
|
|
cy.getById('editor-toolbar-upload-image-input').attachFile({ filePath: 'demo.png', mimeType: 'image/png' })
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `![](${imageUrl})`)
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('via paste', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.fixture('demo.png').then((image: string) => {
|
|
|
|
const pasteEvent = {
|
|
|
|
clipboardData: {
|
|
|
|
files: [Cypress.Blob.base64StringToBlob(image, 'image/png')],
|
|
|
|
getData: (_: string) => ''
|
2021-01-06 07:09:33 -05:00
|
|
|
}
|
2021-11-19 12:04:04 -05:00
|
|
|
}
|
|
|
|
cy.get('.CodeMirror-scroll').trigger('paste', pasteEvent)
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `![](${imageUrl})`)
|
|
|
|
})
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('via drag and drop', () => {
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.fixture('demo.png').then((image: string) => {
|
|
|
|
const dropEvent = {
|
|
|
|
dataTransfer: {
|
|
|
|
files: [Cypress.Blob.base64StringToBlob(image, 'image/png')],
|
|
|
|
effectAllowed: 'uninitialized'
|
2021-01-06 07:09:33 -05:00
|
|
|
}
|
2021-11-19 12:04:04 -05:00
|
|
|
}
|
|
|
|
cy.get('.CodeMirror-scroll').trigger('dragenter', dropEvent)
|
|
|
|
cy.get('.CodeMirror-scroll').trigger('drop', dropEvent)
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `![](${imageUrl})`)
|
|
|
|
})
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
it('fails', () => {
|
|
|
|
cy.intercept(
|
|
|
|
{
|
|
|
|
method: 'GET',
|
|
|
|
url: '/mock-backend/api/private/media/upload-post'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statusCode: 400
|
|
|
|
}
|
|
|
|
)
|
|
|
|
cy.getById('editor-toolbar-upload-image-button').click()
|
|
|
|
cy.fixture('demo.png').then(() => {
|
|
|
|
cy.getById('editor-toolbar-upload-image-input').attachFile({ filePath: 'demo.png', mimeType: 'image/png' })
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span > span').should('have.text', String.fromCharCode(8203)) //thanks codemirror....
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
2020-12-21 05:58:43 -05:00
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
it('lets text paste still work', () => {
|
2020-12-21 05:58:43 -05:00
|
|
|
const testText = 'a long test text'
|
|
|
|
const pasteEvent = {
|
|
|
|
clipboardData: {
|
|
|
|
getData: (type = 'text') => testText
|
|
|
|
}
|
|
|
|
}
|
2021-11-19 12:04:04 -05:00
|
|
|
cy.get('.CodeMirror-scroll').trigger('paste', pasteEvent)
|
|
|
|
cy.get('.CodeMirror-activeline > .CodeMirror-line > span').should('have.text', `${testText}`)
|
2020-12-21 05:58:43 -05:00
|
|
|
})
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|