2020-12-16 17:07:09 -05:00
|
|
|
/*
|
2022-04-15 17:03:15 -04:00
|
|
|
* SPDX-FileCopyrightText: 2022 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(() => {
|
2022-01-30 15:46:43 -05:00
|
|
|
cy.visitTestNote()
|
2022-02-05 13:32:58 -05:00
|
|
|
cy.fixture('demo.png').as('demoImage')
|
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(
|
|
|
|
{
|
2022-04-15 17:03:15 -04:00
|
|
|
method: 'POST',
|
|
|
|
url: '/api/mock-backend/private/media'
|
2021-11-19 12:04:04 -05:00
|
|
|
},
|
|
|
|
{
|
2022-04-15 17:03:15 -04:00
|
|
|
statusCode: 201,
|
2021-11-19 12:04:04 -05:00
|
|
|
body: {
|
2022-04-15 17:03:15 -04:00
|
|
|
url: imageUrl
|
2021-11-19 12:04:04 -05:00
|
|
|
}
|
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-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('editor-toolbar-upload-image-button').should('be.visible')
|
2022-02-05 13:32:58 -05:00
|
|
|
cy.getByCypressId('editor-toolbar-upload-image-input').selectFile(
|
|
|
|
{
|
|
|
|
contents: '@demoImage',
|
|
|
|
fileName: 'demo.png',
|
|
|
|
mimeType: 'image/png'
|
|
|
|
},
|
|
|
|
{ force: true }
|
|
|
|
)
|
2022-02-13 06:14:01 -05:00
|
|
|
cy.get('.cm-line').contains(`![](${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
|
|
|
}
|
2022-02-13 06:14:01 -05:00
|
|
|
cy.get('.cm-content').trigger('paste', pasteEvent)
|
|
|
|
cy.get('.cm-line').contains(`![](${imageUrl})`)
|
2021-11-19 12:04:04 -05:00
|
|
|
})
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('via drag and drop', () => {
|
2022-02-13 06:14:01 -05:00
|
|
|
cy.get('.cm-content').selectFile(
|
2022-02-05 13:32:58 -05:00
|
|
|
{
|
|
|
|
contents: '@demoImage',
|
|
|
|
fileName: 'demo.png',
|
|
|
|
mimeType: 'image/png'
|
|
|
|
},
|
|
|
|
{ action: 'drag-drop', force: true }
|
|
|
|
)
|
2022-02-13 06:14:01 -05:00
|
|
|
cy.get('.cm-line').contains(`![](${imageUrl})`)
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
it('fails', () => {
|
|
|
|
cy.intercept(
|
|
|
|
{
|
2022-04-15 17:03:15 -04:00
|
|
|
method: 'POST',
|
|
|
|
url: '/api/mock-backend/private/media'
|
2021-11-19 12:04:04 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
statusCode: 400
|
|
|
|
}
|
|
|
|
)
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('editor-toolbar-upload-image-button').should('be.visible')
|
2022-02-05 13:32:58 -05:00
|
|
|
cy.getByCypressId('editor-toolbar-upload-image-input').selectFile(
|
|
|
|
{
|
|
|
|
contents: '@demoImage',
|
|
|
|
fileName: 'demo.png',
|
|
|
|
mimeType: 'image/png'
|
|
|
|
},
|
|
|
|
{ force: true }
|
|
|
|
)
|
2022-02-13 06:14:01 -05:00
|
|
|
cy.get('.cm-line').contains('![upload of demo.png failed]()')
|
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
|
|
|
|
}
|
|
|
|
}
|
2022-02-13 06:14:01 -05:00
|
|
|
cy.get('.cm-content').trigger('paste', pasteEvent)
|
|
|
|
cy.get('.cm-line').contains(`${testText}`)
|
2020-12-21 05:58:43 -05:00
|
|
|
})
|
2020-12-16 17:07:09 -05:00
|
|
|
})
|