Replace "cypress-file-upload" with cypress selectFile

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-02-05 19:32:58 +01:00
parent a32984e052
commit 57f01e8903
6 changed files with 79 additions and 56 deletions

View file

@ -9,6 +9,7 @@ const imageUrl = 'http://example.com/non-existing.png'
describe('File upload', () => {
beforeEach(() => {
cy.visitTestNote()
cy.fixture('demo.png').as('demoImage')
})
it("doesn't prevent drag'n'drop of plain text", () => {
@ -41,10 +42,14 @@ describe('File upload', () => {
})
it('via button', () => {
cy.getByCypressId('editor-toolbar-upload-image-button').should('be.visible')
cy.getByCypressId('editor-toolbar-upload-image-input').attachFixture({
filePath: 'demo.png',
mimeType: 'image/png'
})
cy.getByCypressId('editor-toolbar-upload-image-input').selectFile(
{
contents: '@demoImage',
fileName: 'demo.png',
mimeType: 'image/png'
},
{ force: true }
)
cy.get('.CodeMirror-activeline').contains(`![](${imageUrl})`)
})
@ -62,17 +67,15 @@ describe('File upload', () => {
})
it('via drag and drop', () => {
cy.fixture('demo.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').contains(`![](${imageUrl})`)
})
cy.get('.CodeMirror-scroll').selectFile(
{
contents: '@demoImage',
fileName: 'demo.png',
mimeType: 'image/png'
},
{ action: 'drag-drop', force: true }
)
cy.get('.CodeMirror-activeline').contains(`![](${imageUrl})`)
})
})
@ -87,10 +90,14 @@ describe('File upload', () => {
}
)
cy.getByCypressId('editor-toolbar-upload-image-button').should('be.visible')
cy.getByCypressId('editor-toolbar-upload-image-input').attachFixture({
filePath: 'demo.png',
mimeType: 'image/png'
})
cy.getByCypressId('editor-toolbar-upload-image-input').selectFile(
{
contents: '@demoImage',
fileName: 'demo.png',
mimeType: 'image/png'
},
{ force: true }
)
cy.get('.CodeMirror-activeline').contains('![upload of demo.png failed]()')
})

View file

@ -133,39 +133,58 @@ describe('History', () => {
})
cy.visitHistory()
cy.logout()
cy.fixture('history.json').as('history')
cy.fixture('history-2.json').as('history-2')
cy.fixture('invalid-history.txt').as('invalid-history')
})
it('works with valid file', () => {
cy.getByCypressId('import-history-file-button').should('be.visible')
cy.getByCypressId('import-history-file-input').attachFixture({
filePath: 'history.json',
mimeType: 'application/json'
})
cy.getByCypressId('import-history-file-input').selectFile(
{
contents: '@history',
fileName: 'history.json',
mimeType: 'application/json'
},
{ force: true }
)
cy.getByCypressId('history-entry-title').should('have.length', 1).contains('cy-Test')
})
it('fails on invalid file', () => {
cy.getByCypressId('import-history-file-button').should('be.visible')
cy.getByCypressId('import-history-file-input').attachFixture({
filePath: 'invalid-history.txt',
mimeType: 'text/plain'
})
cy.getByCypressId('import-history-file-input').selectFile(
{
contents: '@invalid-history',
fileName: 'invalid-history.txt',
mimeType: 'text/plain'
},
{ force: true }
)
cy.getByCypressId('notification-toast').should('be.visible')
})
it('works when selecting two files with the same name', () => {
cy.getByCypressId('import-history-file-button').should('be.visible')
cy.getByCypressId('import-history-file-input').attachFixture({
filePath: 'history.json',
mimeType: 'application/json'
})
cy.getByCypressId('import-history-file-input').selectFile(
{
contents: '@history',
fileName: 'history.json',
mimeType: 'application/json'
},
{ force: true }
)
cy.getByCypressId('history-entry-title').should('have.length', 1).contains('cy-Test')
cy.getByCypressId('import-history-file-button').should('be.visible')
cy.getByCypressId('import-history-file-input').attachFixture({
filePath: 'history-2.json',
fileName: 'history.json',
mimeType: 'application/json'
})
cy.getByCypressId('import-history-file-input').selectFile(
{
contents: '@history-2',
fileName: 'history.json',
mimeType: 'application/json'
},
{ force: true }
)
cy.getByCypressId('history-entry-title').should('have.length', 2).contains('cy-Test2')
})
})

View file

@ -7,15 +7,20 @@
describe('Import markdown file', () => {
beforeEach(() => {
cy.visitTestNote()
cy.fixture('import.md').as('import')
})
it('import on blank note', () => {
cy.getByCypressId('menu-import').click()
cy.getByCypressId('menu-import-markdown-button').should('be.visible')
cy.getByCypressId('menu-import-markdown-input').attachFixture({
filePath: 'import.md',
mimeType: 'text/markdown'
})
cy.getByCypressId('menu-import-markdown-input').selectFile(
{
contents: '@import',
fileName: 'import.md',
mimeType: 'text/markdown'
},
{ force: true }
)
cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span').should(
'have.text',
'# Some short import test file'
@ -27,10 +32,14 @@ describe('Import markdown file', () => {
cy.setCodemirrorContent('test\nabc')
cy.getByCypressId('menu-import').click()
cy.getByCypressId('menu-import-markdown-button').should('be.visible')
cy.getByCypressId('menu-import-markdown-input').attachFixture({
filePath: 'import.md',
mimeType: 'text/markdown'
})
cy.getByCypressId('menu-import-markdown-input').selectFile(
{
contents: '@import',
fileName: 'import.md',
mimeType: 'text/markdown'
},
{ force: true }
)
cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span').should('have.text', 'test')
cy.get('.CodeMirror-code > div:nth-of-type(2) > .CodeMirror-line > span > span').should('have.text', 'abc')
cy.get('.CodeMirror-code > div:nth-of-type(3) > .CodeMirror-line > span > span').should(