mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 08:04:45 -04:00
Improve tests (#944)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
parent
e0e5f2a7dd
commit
3db6bcf892
20 changed files with 342 additions and 295 deletions
115
cypress/integration/fileUpload.spec.ts
Normal file
115
cypress/integration/fileUpload.spec.ts
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
const imageUrl = 'http://example.com/non-existing.png'
|
||||
|
||||
describe('File upload', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('/n/test')
|
||||
cy.get('.CodeMirror')
|
||||
.click()
|
||||
.get('textarea')
|
||||
.as('codeinput')
|
||||
})
|
||||
|
||||
it('doesn\'t prevent drag\'n\'drop of plain text', () => {
|
||||
const dataTransfer = new DataTransfer()
|
||||
cy.get('@codeinput')
|
||||
.fill('line 1\nline 2\ndragline')
|
||||
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')
|
||||
})
|
||||
|
||||
describe('upload works', () => {
|
||||
beforeEach(() => {
|
||||
cy.intercept({
|
||||
method: 'POST',
|
||||
url: '/api/v2/media/upload'
|
||||
}, {
|
||||
statusCode: 201,
|
||||
body: {
|
||||
link: imageUrl
|
||||
}
|
||||
})
|
||||
})
|
||||
it('via button', () => {
|
||||
cy.get('.fa-upload')
|
||||
.click()
|
||||
cy.get('div.btn-group > input[type=file]')
|
||||
.attachFile({ filePath: 'acme.png', mimeType: 'image/png' })
|
||||
cy.get('.CodeMirror-activeline > .CodeMirror-line > span')
|
||||
.should('have.text', ``)
|
||||
})
|
||||
|
||||
it('via paste', () => {
|
||||
cy.fixture('acme.png').then((image: string) => {
|
||||
const pasteEvent = {
|
||||
clipboardData: {
|
||||
files: [Cypress.Blob.base64StringToBlob(image, 'image/png')]
|
||||
}
|
||||
}
|
||||
cy.get('.CodeMirror-scroll').trigger('paste', pasteEvent)
|
||||
cy.get('.CodeMirror-activeline > .CodeMirror-line > span')
|
||||
.should('have.text', ``)
|
||||
})
|
||||
})
|
||||
|
||||
it('via drag and drop', () => {
|
||||
cy.fixture('acme.png').then((image: string) => {
|
||||
const dropEvent = {
|
||||
dataTransfer: {
|
||||
files: [Cypress.Blob.base64StringToBlob(image, 'image/png')],
|
||||
effectAllowed: 'uninitialized'
|
||||
}
|
||||
}
|
||||
cy.get('.CodeMirror-scroll').trigger('dragenter', dropEvent)
|
||||
cy.get('.CodeMirror-scroll').trigger('drop', dropEvent)
|
||||
cy.get('.CodeMirror-activeline > .CodeMirror-line > span')
|
||||
.should('have.text', ``)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('upload fails', () => {
|
||||
cy.get('@codeinput')
|
||||
.type('not empty')
|
||||
cy.intercept({
|
||||
method: 'POST',
|
||||
url: '/api/v2/media/upload'
|
||||
}, {
|
||||
statusCode: 400
|
||||
})
|
||||
cy.get('.fa-upload')
|
||||
.click()
|
||||
cy.fixture('acme.png').then(() => {
|
||||
cy.get('input[type=file]')
|
||||
.attachFile({ filePath: 'acme.png', mimeType: 'image/png' })
|
||||
})
|
||||
cy.get('.CodeMirror-activeline > .CodeMirror-line > span')
|
||||
.should('have.text', 'not empty')
|
||||
})
|
||||
|
||||
it('text paste still works', () => {
|
||||
const testText = 'a long test text'
|
||||
const pasteEvent = {
|
||||
clipboardData: {
|
||||
getData: (type = 'text') => testText
|
||||
}
|
||||
}
|
||||
cy.get('.CodeMirror-scroll').trigger('paste', pasteEvent)
|
||||
cy.get('.CodeMirror-activeline > .CodeMirror-line > span')
|
||||
.should('have.text', `${testText}`)
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue