From e1112c93ec91bb74c37897058aacddcfa9a3219f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Fri, 1 Sep 2023 18:01:54 +0200 Subject: [PATCH 1/2] fix: remove old fileUploadSpec jsunit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/files/tests/js/fileUploadSpec.js | 303 -------------------------- 1 file changed, 303 deletions(-) delete mode 100644 apps/files/tests/js/fileUploadSpec.js diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js deleted file mode 100644 index e15514b39e224..0000000000000 --- a/apps/files/tests/js/fileUploadSpec.js +++ /dev/null @@ -1,303 +0,0 @@ -/** -* @copyright 2014 Vincent Petry - * - * @author Christoph Wurst - * @author Jan-Christoph Borchardt - * @author Julius Härtl - * @author Morris Jobke - * @author Tomasz Grobelny - * @author Vincent Petry - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -describe('OC.Upload tests', function() { - var $dummyUploader; - var testFile; - var uploader; - var failStub; - var progressBarStub; - - beforeEach(function() { - testFile = { - name: 'test.txt', - size: 5000, // 5 KB - type: 'text/plain', - lastModifiedDate: new Date() - }; - // need a dummy button because file-upload checks on it - $('#testArea').append( - '' + - '' + // 50 MB - // TODO: handlebars! - '
' + - 'New' + - '
    ' + - '
  • Text file

  • ' + - '
' + - '
' - ); - $dummyUploader = $('#file_upload_start'); - progressBarStub = {on: function(){}}; - uploader = new OC.Uploader($dummyUploader, {progressBar: progressBarStub}); - failStub = sinon.stub(); - uploader.on('fail', failStub); - }); - afterEach(function() { - $dummyUploader = undefined; - failStub = undefined; - }); - - /** - * Add file for upload - * @param {Array.} files array of file data to simulate upload - * @return {Array.} array of uploadinfo or null if add() returned false - */ - function addFiles(uploader, files) { - return _.map(files, function(file) { - var jqXHR = {status: 200}; - var uploadInfo = { - originalFiles: files, - files: [file], - jqXHR: jqXHR, - response: sinon.stub().returns(jqXHR), - targetDir: "/", - submit: sinon.stub(), - abort: sinon.stub() - }; - if (uploader.fileUploadParam.add.call( - $dummyUploader[0], - {}, - uploadInfo - )) { - return uploadInfo; - } - return null; - }); - } - - describe('Adding files for upload', function() { - it('adds file when size is below limits', function(done) { - var result = addFiles(uploader, [testFile]); - expect(result[0]).not.toEqual(null); - result[0].submit.callsFake(function(){ - expect(result[0].submit.calledOnce).toEqual(true); - done(); - }); - }); - it('adds file when free space is unknown', function(done) { - var result; - $('#free_space').val(-2); - - result = addFiles(uploader, [testFile]); - expect(result[0]).not.toEqual(null); - result[0].submit.callsFake(function(){ - expect(result[0].submit.calledOnce).toEqual(true); - expect(failStub.notCalled).toEqual(true); - done(); - }); - }); - it('does not add file if it exceeds free space', function(done) { - var result; - $('#free_space').val(1000); - - failStub.callsFake(function(){ - expect(failStub.calledOnce).toEqual(true); - expect(failStub.getCall(0).args[1].textStatus).toEqual('notenoughspace'); - expect(failStub.getCall(0).args[1].errorThrown).toEqual( - 'Not enough free space, you are uploading 5 KB but only 1 KB is left' - ); - setTimeout(done, 0); - }); - result = addFiles(uploader, [testFile]); - - expect(result[0]).toEqual(null); - }); - }); - describe('Upload conflicts', function() { - var conflictDialogStub; - var clock; - var fileList; - - beforeEach(function() { - $('#testArea').append( - '
' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
' + - '
' - ); - fileList = new OCA.Files.FileList($('#tableContainer')); - - fileList.add({name: 'conflict.txt', mimetype: 'text/plain'}); - fileList.add({name: 'conflict2.txt', mimetype: 'text/plain'}); - - conflictDialogStub = sinon.stub(OC.dialogs, 'fileexists'); - - uploader = new OC.Uploader($dummyUploader, { - progressBar: progressBarStub, - fileList: fileList - }); - - var deferred = $.Deferred(); - conflictDialogStub.returns(deferred.promise()); - deferred.resolve(); - }); - afterEach(function() { - if (clock) { - clock.restore(); - clock = undefined - } - - conflictDialogStub.restore(); - - fileList.destroy(); - }); - it('does not show conflict dialog when no client side conflict', function(done) { - $('#free_space').val(200000); - var counter = 0; - var fun = function() { - counter++; - if(counter != 2) { - return; - } - expect(result[0].submit.calledOnce).toEqual(true); - expect(result[1].submit.calledOnce).toEqual(true); - setTimeout(done, 0); - }; - var result = addFiles(uploader, [{name: 'noconflict.txt'}, {name: 'noconflict2.txt'}]); - result[0].submit.callsFake(fun); - result[1].submit.callsFake(fun); - - expect(conflictDialogStub.notCalled).toEqual(true); - - }); - it('shows conflict dialog when no client side conflict', function(done) { - var counter = 0; - conflictDialogStub.callsFake(function(){ - counter++; - if(counter != 3) { - return $.Deferred().resolve().promise(); - } - setTimeout(function() { - expect(conflictDialogStub.callCount).toEqual(3); - expect(conflictDialogStub.getCall(1).args[0].getFileName()) - .toEqual('conflict.txt'); - expect(conflictDialogStub.getCall(1).args[1]) - .toEqual({ name: 'conflict.txt', mimetype: 'text/plain', directory: '/' }); - expect(conflictDialogStub.getCall(1).args[2]).toEqual({ name: 'conflict.txt' }); - - // yes, the dialog must be called several times... - expect(conflictDialogStub.getCall(2).args[0].getFileName()).toEqual('conflict2.txt'); - expect(conflictDialogStub.getCall(2).args[1]) - .toEqual({ name: 'conflict2.txt', mimetype: 'text/plain', directory: '/' }); - expect(conflictDialogStub.getCall(2).args[2]).toEqual({ name: 'conflict2.txt' }); - - expect(result[0].submit.calledOnce).toEqual(false); - expect(result[1].submit.calledOnce).toEqual(false); - expect(result[2].submit.calledOnce).toEqual(true); - done(); - }, 10); - }); - var result = addFiles(uploader, [ - {name: 'conflict.txt'}, - {name: 'conflict2.txt'}, - {name: 'noconflict.txt'} - ]); - - }); - it('cancels upload when skipping file in conflict mode', function(done) { - var fileData = {name: 'conflict.txt'}; - var uploadData = addFiles(uploader, [ - fileData - ]); - - var upload = new OC.FileUpload(uploader, uploadData[0]); - var deleteStub = sinon.stub(upload, 'deleteUpload'); - deleteStub.callsFake(function(){ - expect(deleteStub.calledOnce).toEqual(true); - done(); - }); - - uploader.onSkip(upload); - }); - it('overwrites file when choosing replace in conflict mode', function(done) { - var fileData = {name: 'conflict.txt'}; - var uploadData = addFiles(uploader, [ - fileData - ]); - - expect(uploadData[0].submit.notCalled).toEqual(true); - - var upload = new OC.FileUpload(uploader, uploadData[0]); - uploadData[0].submit.callsFake(function(){ - expect(upload.getConflictMode()).toEqual(OC.FileUpload.CONFLICT_MODE_OVERWRITE); - expect(uploadData[0].submit.callCount).toEqual(1); - done(); - }); - uploader.onReplace(upload); - }); - it('autorenames file when choosing replace in conflict mode', function(done) { - var fileData = {name: 'conflict.txt'}; - var uploadData = addFiles(uploader, [ - fileData - ]); - - expect(uploadData[0].submit.notCalled).toEqual(true); - - var upload = new OC.FileUpload(uploader, uploadData[0]); - var getResponseStatusStub = sinon.stub(upload, 'getResponseStatus'); - var counter = 0; - uploadData[0].submit.callsFake(function(){ - counter++; - if(counter===1) - { - expect(upload.getConflictMode()).toEqual(OC.FileUpload.CONFLICT_MODE_AUTORENAME); - expect(upload.getFileName()).toEqual('conflict (2).txt'); - expect(uploadData[0].submit.calledOnce).toEqual(true); - getResponseStatusStub.returns(412); - uploader.fileUploadParam.fail.call($dummyUploader[0], {}, uploadData[0]); - } - if(counter===2) - { - _.defer(function() { - expect(upload.getFileName()).toEqual('conflict (3).txt'); - expect(uploadData[0].submit.calledTwice).toEqual(true); - - done(); - }) - } - }); - - uploader.onAutorename(upload); - - // in case of server-side conflict, tries to rename again - }); - }); -}); From 2a31bc7fd36b9ffaa1eec2ba42f74eec40c5f7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Fri, 1 Sep 2023 18:24:05 +0200 Subject: [PATCH 2/2] fix(files): fix flaky cypress files test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- cypress/e2e/files.cy.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cypress/e2e/files.cy.ts b/cypress/e2e/files.cy.ts index 9bdb05c8c7279..490ddff2d0e1c 100644 --- a/cypress/e2e/files.cy.ts +++ b/cypress/e2e/files.cy.ts @@ -33,5 +33,7 @@ describe('Login with a new user and open the files app', function() { it('See the default file welcome.txt in the files list', function() { cy.visit('/apps/files') cy.get('[data-cy-files-list] [data-cy-files-list-row-name="welcome.txt"]').should('be.visible') + // eslint-disable-next-line cypress/no-unnecessary-waiting -- Wait for all to finish loading + cy.wait(500) }) })