From 7a088cfcf56a841f16023a64a442620fd20c0c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 11 Jan 2018 02:36:00 +0100 Subject: [PATCH 1/3] Move adding test files to "beforeEach()" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All the tests in the "Renaming files" section added the test files, although those calling "doRename()" added them by setting a path for the file too. However, the path is ignored in the other tests, so adding the files can be unified and moved to "beforeEach()". This would be needed, for example, to show the details view for a file before calling "doRename()". Signed-off-by: Daniel Calviño Sánchez --- apps/files/tests/js/filelistSpec.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index fc5a6c18f95..a03d2fa1cc7 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -612,6 +612,12 @@ describe('OCA.Files.FileList tests', function() { beforeEach(function() { deferredRename = $.Deferred(); renameStub = sinon.stub(filesClient, 'move').returns(deferredRename.promise()); + + for (var i = 0; i < testFiles.length; i++) { + var file = testFiles[i]; + file.path = '/some/subdir'; + fileList.add(file, {silent: true}); + } }); afterEach(function() { renameStub.restore(); @@ -619,9 +625,6 @@ describe('OCA.Files.FileList tests', function() { function doCancelRename() { var $input; - for (var i = 0; i < testFiles.length; i++) { - fileList.add(testFiles[i]); - } // trigger rename prompt fileList.rename('One.txt'); @@ -636,12 +639,6 @@ describe('OCA.Files.FileList tests', function() { function doRename() { var $input; - for (var i = 0; i < testFiles.length; i++) { - var file = testFiles[i]; - file.path = '/some/subdir'; - fileList.add(file, {silent: true}); - } - // trigger rename prompt fileList.rename('One.txt'); $input = fileList.$fileList.find('input.filename'); @@ -731,10 +728,6 @@ describe('OCA.Files.FileList tests', function() { it('Validates the file name', function() { var $input, $tr; - for (var i = 0; i < testFiles.length; i++) { - fileList.add(testFiles[i], {silent: true}); - } - $tr = fileList.findFileEl('One.txt'); expect($tr.find('a.name').css('display')).not.toEqual('none'); From f29c1cf13ae4f5dd38c7476c55ff5e23916bd6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 11 Jan 2018 02:47:11 +0100 Subject: [PATCH 2/3] Fix empty details view after renaming a file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "FileList._updateDetailsView" expects either a file name (as a string) or a file model (as an "OCA.File.FileInfoModel"), but when called through "updateInList" an "OC.Files.FileInfo" object was given instead. As the given attribute was not a model "_updateDetailsView" treated it as a file name and tried to get the model for that file, which failed and caused the details view to be emptied. Signed-off-by: Daniel Calviño Sánchez --- apps/files/js/filelist.js | 2 +- apps/files/tests/js/filelistSpec.js | 30 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 7a4ea492752..e50b402dea8 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -2266,7 +2266,7 @@ function updateInList(fileInfo) { self.updateRow(tr, fileInfo); - self._updateDetailsView(fileInfo, false); + self._updateDetailsView(fileInfo.name, false); } // TODO: too many nested blocks, move parts into functions diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index a03d2fa1cc7..08da15b8a88 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -674,6 +674,36 @@ describe('OCA.Files.FileList tests', function() { expect(notificationStub.calledOnce).toEqual(true); }); + it('Shows renamed file details if rename ajax call suceeded', function() { + fileList.showDetailsView('One.txt'); + + expect($('#app-sidebar').hasClass('disappear')).toEqual(false); + expect(fileList._detailsView.getFileInfo().get('id')).toEqual(1); + expect(fileList._detailsView.getFileInfo().get('name')).toEqual('One.txt'); + + doRename(); + + deferredRename.resolve(201); + + expect($('#app-sidebar').hasClass('disappear')).toEqual(false); + expect(fileList._detailsView.getFileInfo().get('id')).toEqual(1); + expect(fileList._detailsView.getFileInfo().get('name')).toEqual('Tu_after_three.txt'); + }); + it('Shows again file details if rename ajax call failed', function() { + fileList.showDetailsView('One.txt'); + + expect($('#app-sidebar').hasClass('disappear')).toEqual(false); + expect(fileList._detailsView.getFileInfo().get('id')).toEqual(1); + expect(fileList._detailsView.getFileInfo().get('name')).toEqual('One.txt'); + + doRename(); + + deferredRename.reject(403); + + expect($('#app-sidebar').hasClass('disappear')).toEqual(false); + expect(fileList._detailsView.getFileInfo().get('id')).toEqual(1); + expect(fileList._detailsView.getFileInfo().get('name')).toEqual('One.txt'); + }); it('Correctly updates file link after rename', function() { var $tr; doRename(); From dab4a70bcf75878cf1542d010f5894e5c7e272ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 11 Jan 2018 04:30:52 +0100 Subject: [PATCH 3/3] Add acceptance test for renaming a file with the details view open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- tests/acceptance/features/app-files.feature | 7 +++ .../features/bootstrap/FilesAppContext.php | 50 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/tests/acceptance/features/app-files.feature b/tests/acceptance/features/app-files.feature index 2cb43611b9a..ef3d07ae499 100644 --- a/tests/acceptance/features/app-files.feature +++ b/tests/acceptance/features/app-files.feature @@ -23,6 +23,13 @@ Feature: app-files When I open the details view for "welcome.txt" Then I see that the details view for "All files" section is open + Scenario: rename a file with the details view open + Given I am logged in + And I open the details view for "welcome.txt" + When I rename "welcome.txt" to "farewell.txt" + Then I see that the file list contains a file named "farewell.txt" + And I see that the file name shown in the details view is "farewell.txt" + Scenario: open the menu in a public shared link Given I act as John And I am logged in diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php index 4951dc43f1d..117f3b54fb8 100644 --- a/tests/acceptance/features/bootstrap/FilesAppContext.php +++ b/tests/acceptance/features/bootstrap/FilesAppContext.php @@ -86,6 +86,15 @@ class FilesAppContext implements Context, ActorAwareInterface { describedAs("Close current section details view in Files app"); } + /** + * @return Locator + */ + public static function fileNameInCurrentSectionDetailsView() { + return Locator::forThe()->css(".fileName")-> + descendantOf(self::currentSectionDetailsView())-> + describedAs("File name in current section details view in Files app"); + } + /** * @return Locator */ @@ -316,6 +325,14 @@ class FilesAppContext implements Context, ActorAwareInterface { describedAs("Main link for file $fileName in Files app"); } + /** + * @return Locator + */ + public static function renameInputForFile($fileName) { + return Locator::forThe()->css("input.filename")->descendantOf(self::rowForFile($fileName))-> + describedAs("Rename input for file $fileName in Files app"); + } + /** * @return Locator */ @@ -347,6 +364,13 @@ class FilesAppContext implements Context, ActorAwareInterface { return self::fileActionsMenuItemFor("Details"); } + /** + * @return Locator + */ + public static function renameMenuItem() { + return self::fileActionsMenuItemFor("Rename"); + } + /** * @return Locator */ @@ -417,6 +441,17 @@ class FilesAppContext implements Context, ActorAwareInterface { $this->actor->find(self::tabHeaderInCurrentSectionDetailsViewNamed($tabName), 10)->click(); } + /** + * @Given I rename :fileName1 to :fileName2 + */ + public function iRenameTo($fileName1, $fileName2) { + $this->actor->find(self::fileActionsMenuButtonForFile($fileName1), 10)->click(); + + $this->actor->find(self::renameMenuItem(), 2)->click(); + + $this->actor->find(self::renameInputForFile($fileName1), 10)->setValue($fileName2 . "\r"); + } + /** * @Given I mark :fileName as favorite */ @@ -542,6 +577,13 @@ class FilesAppContext implements Context, ActorAwareInterface { } } + /** + * @Then I see that the file list contains a file named :fileName + */ + public function iSeeThatTheFileListContainsAFileNamed($fileName) { + PHPUnit_Framework_Assert::assertNotNull($this->actor->find(self::rowForFile($fileName), 10)); + } + /** * @Then I see that :fileName1 precedes :fileName2 in the file list */ @@ -563,6 +605,14 @@ class FilesAppContext implements Context, ActorAwareInterface { PHPUnit_Framework_Assert::assertNotNull($this->actor->find(self::notFavoritedStateIconForFile($fileName), 10)); } + /** + * @Then I see that the file name shown in the details view is :fileName + */ + public function iSeeThatTheFileNameShownInTheDetailsViewIs($fileName) { + PHPUnit_Framework_Assert::assertEquals( + $this->actor->find(self::fileNameInCurrentSectionDetailsView(), 10)->getText(), $fileName); + } + /** * @Then I see that the input field for tags in the details view is shown */