2020-12-16 22:07:09 +00:00
|
|
|
/*
|
2022-04-15 21:03:15 +00:00
|
|
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
2020-12-16 22:07:09 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
const imageUrl = 'http://example.com/non-existing.png'
|
|
|
|
|
2021-01-11 22:22:11 +00:00
|
|
|
describe('File upload', () => {
|
2020-12-16 22:07:09 +00:00
|
|
|
beforeEach(() => {
|
2022-01-30 20:46:43 +00:00
|
|
|
cy.visitTestNote()
|
2022-02-05 18:32:58 +00:00
|
|
|
cy.fixture('demo.png').as('demoImage')
|
2020-12-16 22:07:09 +00:00
|
|
|
})
|
|
|
|
|
2021-11-19 17:04:04 +00:00
|
|
|
describe('works', () => {
|
2020-12-16 22:07:09 +00:00
|
|
|
beforeEach(() => {
|
2021-11-19 17:04:04 +00:00
|
|
|
cy.intercept(
|
|
|
|
{
|
2022-04-15 21:03:15 +00:00
|
|
|
method: 'POST',
|
|
|
|
url: '/api/mock-backend/private/media'
|
2021-11-19 17:04:04 +00:00
|
|
|
},
|
|
|
|
{
|
2022-04-15 21:03:15 +00:00
|
|
|
statusCode: 201,
|
2021-11-19 17:04:04 +00:00
|
|
|
body: {
|
2022-04-15 21:03:15 +00:00
|
|
|
url: imageUrl
|
2021-11-19 17:04:04 +00:00
|
|
|
}
|
2020-12-16 22:07:09 +00:00
|
|
|
}
|
2021-11-19 17:04:04 +00:00
|
|
|
)
|
2020-12-16 22:07:09 +00:00
|
|
|
})
|
|
|
|
it('via button', () => {
|
2021-12-25 15:44:24 +00:00
|
|
|
cy.getByCypressId('editor-toolbar-upload-image-button').should('be.visible')
|
2022-02-05 18:32:58 +00:00
|
|
|
cy.getByCypressId('editor-toolbar-upload-image-input').selectFile(
|
|
|
|
{
|
|
|
|
contents: '@demoImage',
|
|
|
|
fileName: 'demo.png',
|
|
|
|
mimeType: 'image/png'
|
|
|
|
},
|
|
|
|
{ force: true }
|
|
|
|
)
|
2022-02-13 11:14:01 +00:00
|
|
|
cy.get('.cm-line').contains(`![](${imageUrl})`)
|
2020-12-16 22:07:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('via paste', () => {
|
2021-11-19 17:04:04 +00:00
|
|
|
cy.fixture('demo.png').then((image: string) => {
|
|
|
|
const pasteEvent = {
|
|
|
|
clipboardData: {
|
|
|
|
files: [Cypress.Blob.base64StringToBlob(image, 'image/png')],
|
|
|
|
getData: (_: string) => ''
|
2021-01-06 12:09:33 +00:00
|
|
|
}
|
2021-11-19 17:04:04 +00:00
|
|
|
}
|
2022-02-13 11:14:01 +00:00
|
|
|
cy.get('.cm-content').trigger('paste', pasteEvent)
|
|
|
|
cy.get('.cm-line').contains(`![](${imageUrl})`)
|
2021-11-19 17:04:04 +00:00
|
|
|
})
|
2020-12-16 22:07:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('via drag and drop', () => {
|
2022-02-13 11:14:01 +00:00
|
|
|
cy.get('.cm-content').selectFile(
|
2022-02-05 18:32:58 +00:00
|
|
|
{
|
|
|
|
contents: '@demoImage',
|
|
|
|
fileName: 'demo.png',
|
|
|
|
mimeType: 'image/png'
|
|
|
|
},
|
|
|
|
{ action: 'drag-drop', force: true }
|
|
|
|
)
|
2022-02-13 11:14:01 +00:00
|
|
|
cy.get('.cm-line').contains(`![](${imageUrl})`)
|
2020-12-16 22:07:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-11-19 17:04:04 +00:00
|
|
|
it('fails', () => {
|
|
|
|
cy.intercept(
|
|
|
|
{
|
2022-04-15 21:03:15 +00:00
|
|
|
method: 'POST',
|
|
|
|
url: '/api/mock-backend/private/media'
|
2021-11-19 17:04:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
statusCode: 400
|
|
|
|
}
|
|
|
|
)
|
2021-12-25 15:44:24 +00:00
|
|
|
cy.getByCypressId('editor-toolbar-upload-image-button').should('be.visible')
|
2022-02-05 18:32:58 +00:00
|
|
|
cy.getByCypressId('editor-toolbar-upload-image-input').selectFile(
|
|
|
|
{
|
|
|
|
contents: '@demoImage',
|
|
|
|
fileName: 'demo.png',
|
|
|
|
mimeType: 'image/png'
|
|
|
|
},
|
|
|
|
{ force: true }
|
|
|
|
)
|
2022-02-13 11:14:01 +00:00
|
|
|
cy.get('.cm-line').contains('![upload of demo.png failed]()')
|
2020-12-16 22:07:09 +00:00
|
|
|
})
|
2020-12-21 10:58:43 +00:00
|
|
|
|
2021-11-19 17:04:04 +00:00
|
|
|
it('lets text paste still work', () => {
|
2020-12-21 10:58:43 +00:00
|
|
|
const testText = 'a long test text'
|
|
|
|
const pasteEvent = {
|
|
|
|
clipboardData: {
|
|
|
|
getData: (type = 'text') => testText
|
|
|
|
}
|
|
|
|
}
|
2022-02-13 11:14:01 +00:00
|
|
|
cy.get('.cm-content').trigger('paste', pasteEvent)
|
|
|
|
cy.get('.cm-line').contains(`${testText}`)
|
2020-12-21 10:58:43 +00:00
|
|
|
})
|
2020-12-16 22:07:09 +00:00
|
|
|
})
|