diff --git a/cypress/integration/04_document_spec.js b/cypress/integration/04_document_spec.js index d86afd63..4596b972 100644 --- a/cypress/integration/04_document_spec.js +++ b/cypress/integration/04_document_spec.js @@ -160,7 +160,7 @@ context('Document Operations', () => { .type('{esc}') }) - it('should upload a document', () => { + it('should upload a document using drag and drop', () => { cy.extendedFiles().then(win => { const file = new win.ExFile('/', [new Blob(['sample text content.'])], 'upload_test.txt', { type: 'text/plain' }) @@ -182,6 +182,38 @@ context('Document Operations', () => { }) }) + it('should upload a document using the upload dialog', () => { + cy.writeFile(require('path').resolve(Cypress.env('homedir'), 'upload_file_test.txt'), 'sample text content'); + cy.get('[node-id$=test]') + .rightclick() + cy.get('[data-command="fusion.upload-document"]') + .should('be.visible') + .contains('Upload document(s)') + .click() + cy.get('.dialogBlock .theia-Tree.theia-FileTree') + const timer = Date.now(); + new Cypress.Promise((resolve, reject) => { + function tick() { + const file = cy.$$('.theia-TreeNode:contains(upload_file_test.txt)'); + if (file.length) { + cy.wrap(file[0]) + .click({ force: true }) + cy.get('.main').click(); + fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxqs/fusiondb/document?uri=/db/test/upload_file_test.txt', { method: 'PUT' }) + cy.get('[node-id$="test\\/upload_file_test.txt"]') + .should('be.visible') + resolve(); + } else { + if (Date.now() < timer + 5000) { + cy.get('.theia-FileTree.theia-FileDialog.ps .ps__rail-y').click('bottom', { force: true }) + cy.wait(100).then(tick); + } + } + } + tick() + }) + }) + it('should move a document', () => { const dataTransfer = new DataTransfer(); cy.get('[node-id$="test\\/test.xml"]') diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index aa9918d2..15e3b93e 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -18,4 +18,6 @@ module.exports = (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config + config.env.homedir = require('os').homedir(); + return config; }