From d0ea4ad8b84998d9eecd41d0f518530615cb0fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 22 Nov 2018 05:20:26 +0100 Subject: [PATCH 1/5] Add acceptance tests for switching to the comments of another file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- .../acceptance/features/app-comments.feature | 23 +++++++++++++++ .../features/bootstrap/CommentsAppContext.php | 28 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/tests/acceptance/features/app-comments.feature b/tests/acceptance/features/app-comments.feature index a5bdb0aa74..1ee113d0aa 100644 --- a/tests/acceptance/features/app-comments.feature +++ b/tests/acceptance/features/app-comments.feature @@ -6,3 +6,26 @@ Feature: app-comments And I open the "Comments" tab in the details view When I create a new comment with "Hello world" as message Then I see a comment with "Hello world" as message + + Scenario: open the comments for a different file + Given I am logged in + And I create a new folder named "Folder" + And I open the details view for "welcome.txt" + And I open the "Comments" tab in the details view + And I create a new comment with "Hello world" as message + And I see a comment with "Hello world" as message + When I open the details view for "Folder" + # The "Comments" tab should already be opened + Then I see that there are no comments + + Scenario: write a comment in a file right after writing a comment in another file + Given I am logged in + And I create a new folder named "Folder" + And I open the details view for "Folder" + And I open the "Comments" tab in the details view + And I create a new comment with "Comment in Folder" as message + And I open the details view for "welcome.txt" + # The "Comments" tab should already be opened + When I create a new comment with "Comment in welcome.txt" as message + Then I see a comment with "Comment in welcome.txt" as message + And I see that there is no comment with "Comment in Folder" as message diff --git a/tests/acceptance/features/bootstrap/CommentsAppContext.php b/tests/acceptance/features/bootstrap/CommentsAppContext.php index 13d8af4e60..5d19412c30 100644 --- a/tests/acceptance/features/bootstrap/CommentsAppContext.php +++ b/tests/acceptance/features/bootstrap/CommentsAppContext.php @@ -62,6 +62,15 @@ class CommentsAppContext implements Context, ActorAwareInterface { describedAs("Comment with text \"$text\" in details view in Files app"); } + /** + * @return Locator + */ + public static function emptyContent() { + return Locator::forThe()->css(".emptycontent")-> + descendantOf(FilesAppContext::detailsView())-> + describedAs("Empty content in details view in Files app"); + } + /** * @When /^I create a new comment with "([^"]*)" as message$/ */ @@ -70,6 +79,14 @@ class CommentsAppContext implements Context, ActorAwareInterface { $this->actor->find(self::submitNewCommentButton())->click(); } + /** + * @Then /^I see that there are no comments$/ + */ + public function iSeeThatThereAreNoComments() { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::emptyContent(), 10)->isVisible()); + } + /** * @Then /^I see a comment with "([^"]*)" as message$/ */ @@ -77,4 +94,15 @@ class CommentsAppContext implements Context, ActorAwareInterface { PHPUnit_Framework_Assert::assertTrue( $this->actor->find(self::commentWithText($commentText), 10)->isVisible()); } + + /** + * @Then /^I see that there is no comment with "([^"]*)" as message$/ + */ + public function iSeeThatThereIsNoCommentWithAsMessage($commentText) { + try { + PHPUnit_Framework_Assert::assertFalse( + $this->actor->find(self::commentWithText($commentText))->isVisible()); + } catch (NoSuchElementException $exception) { + } + } } From 400d42a47a4a5e14fa53fcc2a015c9e9d20ef32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 22 Nov 2018 05:25:12 +0100 Subject: [PATCH 2/5] Add acceptance tests for marking a file as favorite in the details view 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 | 19 ++++++ .../features/bootstrap/FilesAppContext.php | 61 +++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/tests/acceptance/features/app-files.feature b/tests/acceptance/features/app-files.feature index 74490180ad..c37c5054ea 100644 --- a/tests/acceptance/features/app-files.feature +++ b/tests/acceptance/features/app-files.feature @@ -262,3 +262,22 @@ Feature: app-files When I unmark "welcome.txt" as favorite Then I see that "welcome.txt" is not marked as favorite And I see that "A name alphabetically lower than welcome.txt" precedes "welcome.txt" in the file list + + Scenario: mark a file as favorite in the details view + Given I am logged in + And I open the details view for "welcome.txt" + And I see that the details view is open + When I mark the file as favorite in the details view + Then I see that "welcome.txt" is marked as favorite + And I see that the file is marked as favorite in the details view + + Scenario: unmark a file as favorite in the details view + Given I am logged in + And I open the details view for "welcome.txt" + And I see that the details view is open + And I mark the file as favorite in the details view + And I see that "welcome.txt" is marked as favorite + And I see that the file is marked as favorite in the details view + When I unmark the file as favorite in the details view + Then I see that "welcome.txt" is not marked as favorite + And I see that the file is not marked as favorite in the details view diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php index ab9fc8fe29..8758678494 100644 --- a/tests/acceptance/features/bootstrap/FilesAppContext.php +++ b/tests/acceptance/features/bootstrap/FilesAppContext.php @@ -86,6 +86,33 @@ class FilesAppContext implements Context, ActorAwareInterface { describedAs("File name in details view in Files app"); } + /** + * @return Locator + */ + public static function favoriteActionInFileDetailsInDetailsView() { + return Locator::forThe()->css(".action-favorite")-> + descendantOf(self::fileDetailsInDetailsView())-> + describedAs("Favorite action in file details in details view in Files app"); + } + + /** + * @return Locator + */ + public static function notFavoritedStateIconInFileDetailsInDetailsView() { + return Locator::forThe()->css(".icon-star")-> + descendantOf(self::favoriteActionInFileDetailsInDetailsView())-> + describedAs("Not favorited state icon in file details in details view in Files app"); + } + + /** + * @return Locator + */ + public static function favoritedStateIconInFileDetailsInDetailsView() { + return Locator::forThe()->css(".icon-starred")-> + descendantOf(self::favoriteActionInFileDetailsInDetailsView())-> + describedAs("Favorited state icon in file details in details view in Files app"); + } + /** * @return Locator */ @@ -316,6 +343,24 @@ class FilesAppContext implements Context, ActorAwareInterface { $this->actor->getSharedNotebook()["shared link"] = $this->actor->find(self::copyUrlMenuItem(), 2)->getWrappedElement()->getAttribute("data-clipboard-text"); } + /** + * @When I mark the file as favorite in the details view + */ + public function iMarkTheFileAsFavoriteInTheDetailsView() { + $this->iSeeThatTheFileIsNotMarkedAsFavoriteInTheDetailsView(); + + $this->actor->find(self::favoriteActionInFileDetailsInDetailsView(), 10)->click(); + } + + /** + * @When I unmark the file as favorite in the details view + */ + public function iUnmarkTheFileAsFavoriteInTheDetailsView() { + $this->iSeeThatTheFileIsMarkedAsFavoriteInTheDetailsView(); + + $this->actor->find(self::favoriteActionInFileDetailsInDetailsView(), 10)->click(); + } + /** * @When I check the tag :tag in the dropdown for tags in the details view */ @@ -400,6 +445,22 @@ class FilesAppContext implements Context, ActorAwareInterface { $this->actor->find(self::fileNameInDetailsView(), 10)->getText(), $fileName); } + /** + * @Then I see that the file is marked as favorite in the details view + */ + public function iSeeThatTheFileIsMarkedAsFavoriteInTheDetailsView() { + PHPUnit_Framework_Assert::assertNotNull( + $this->actor->find(self::favoritedStateIconInFileDetailsInDetailsView(), 10)); + } + + /** + * @Then I see that the file is not marked as favorite in the details view + */ + public function iSeeThatTheFileIsNotMarkedAsFavoriteInTheDetailsView() { + PHPUnit_Framework_Assert::assertNotNull( + $this->actor->find(self::notFavoritedStateIconInFileDetailsInDetailsView(), 10)); + } + /** * @Then I see that the input field for tags in the details view is shown */ From f9efd3162340c9e7a9a625d179b4670311243e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 22 Nov 2018 05:26:01 +0100 Subject: [PATCH 3/5] Add acceptance tests for opening and closing again the details view 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 | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/acceptance/features/app-files.feature b/tests/acceptance/features/app-files.feature index c37c5054ea..89d622493c 100644 --- a/tests/acceptance/features/app-files.feature +++ b/tests/acceptance/features/app-files.feature @@ -1,5 +1,42 @@ Feature: app-files + Scenario: open and close the details view + Given I am logged in + When I open the details view for "welcome.txt" + And I see that the details view is open + And I close the details view + Then I see that the details view is closed + + Scenario: open and close the details view twice + Given I am logged in + And I open the details view for "welcome.txt" + And I see that the details view is open + And I close the details view + And I see that the details view is closed + When I open the details view for "welcome.txt" + And I see that the details view is open + And I close the details view + Then I see that the details view is closed + + Scenario: open and close the details view again after coming back from a different section + Given I am logged in + And I open the details view for "welcome.txt" + And I see that the details view is open + And I close the details view + And I see that the details view is closed + And I open the "Recent" section + And I see that the current section is "Recent" + And I open the details view for "welcome.txt" + And I see that the details view is open + And I close the details view + And I see that the details view is closed + When I open the "All files" section + And I see that the current section is "All files" + And I open the details view for "welcome.txt" + And I see that the details view is open + And I close the details view + Then I see that the details view is closed + Scenario: viewing a favorite file in its folder shows the correct sidebar view Given I am logged in And I create a new folder named "other" From 2d58826d422549d42858420883cf22dba62715cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 22 Nov 2018 05:26:45 +0100 Subject: [PATCH 4/5] Add acceptance tests for showing again the input field for tags 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-tags.feature | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/acceptance/features/app-files-tags.feature b/tests/acceptance/features/app-files-tags.feature index 3da24b7e1c..d606c7a88a 100644 --- a/tests/acceptance/features/app-files-tags.feature +++ b/tests/acceptance/features/app-files-tags.feature @@ -8,6 +8,17 @@ Feature: app-files-tags When I open the input field for tags in the details view Then I see that the input field for tags in the details view is shown + Scenario: show the input field for tags in the details view after closing and opening the details view again + Given I am logged in + And I open the details view for "welcome.txt" + And I see that the details view is open + And I close the details view + And I see that the details view is closed + And I open the details view for "welcome.txt" + And I see that the details view is open + When I open the input field for tags in the details view + Then I see that the input field for tags in the details view is shown + Scenario: show the input field for tags in the details view after the sharing tab has loaded Given I am logged in And I open the details view for "welcome.txt" From e3d90efdbb6a4f8c0030c52c74b8baea00f32146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 22 Nov 2018 05:58:25 +0100 Subject: [PATCH 5/5] Fix rendering of the sidebar in Files app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a view is rendered it should not be concerned with where it is going to be placed in the document; in general this should be a responsibility of the object using the view. Moreover, when the details view is rendered it should simply prepare a skeleton that includes the root elements provided by the plugins; those elements will be updated by the plugins as needed when a file or a tab is selected. Finally, the details view should not be explicitly rendered. The rendering removes the previous elements, but that is needed only when the details view is in a dirty state, that is, when new plugins were added since the last time that it was rendered. However, that dirty state is internally handled, and the view is automatically rendered again if needed when a file info is set. Due to all that the details view is no longer explicitly rendered when updating it with a different file. Also, as each file list has its own details view, and each details view has its own element, but there can be only one details view/sidebar element in the document, when the file list updates the details view it also replaces the current one in the document with its own details view if needed (that is, if it is not the current one already). Besides that, when the element of a details view is replaced with the element of a different details view the old one should be detached from the document, but never removed. Otherwise the event handlers would not work when that element is attached again later (when changing to a different section in the Files app and then going back to the previous one). Signed-off-by: Daniel Calviño Sánchez --- apps/files/js/detailsview.js | 10 ---------- apps/files/js/filelist.js | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/apps/files/js/detailsview.js b/apps/files/js/detailsview.js index aed1736693..7e2a5f0e8a 100644 --- a/apps/files/js/detailsview.js +++ b/apps/files/js/detailsview.js @@ -117,16 +117,6 @@ * Renders this details view */ render: function() { - // remove old instances - var $appSidebar = $('#app-sidebar'); - if ($appSidebar.length === 0) { - this.$el.insertAfter($('#app-content')); - } else { - if ($appSidebar[0] !== this.el) { - $appSidebar.replaceWith(this.$el) - } - } - var templateVars = { closeLabel: t('files', 'Close') }; diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index a7dadbbab3..0fe5aed020 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -568,11 +568,35 @@ } this._currentFileModel = model; + + this._replaceDetailsViewElementIfNeeded(); + this._detailsView.setFileInfo(model); - this._detailsView.render(); this._detailsView.$el.scrollTop(0); }, + /** + * Replaces the current details view element with the details view + * element of this file list. + * + * Each file list has its own DetailsView object, and each one has its + * own root element, but there can be just one details view/sidebar + * element in the document. This helper method replaces the current + * details view/sidebar element in the document with the element from + * the DetailsView object of this file list. + */ + _replaceDetailsViewElementIfNeeded: function() { + var $appSidebar = $('#app-sidebar'); + if ($appSidebar.length === 0) { + this._detailsView.$el.insertAfter($('#app-content')); + } else if ($appSidebar[0] !== this._detailsView.el) { + // "replaceWith()" can not be used here, as it removes the old + // element instead of just detaching it. + this._detailsView.$el.insertBefore($appSidebar); + $appSidebar.detach(); + } + }, + /** * Event handler for when the window size changed */