Skip to content

Commit fc7f208

Browse files
authored
Merge pull request #13253 from nextcloud/backport/13227/stable15
[stable15] Fix opening search results for comments
2 parents b5e844f + 5f3d6b5 commit fc7f208

File tree

5 files changed

+246
-1
lines changed

5 files changed

+246
-1
lines changed

apps/comments/js/search.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@
9292
.css('background-image', 'url(' + OC.imagePath('core', 'actions/comment') + ')')
9393
.css('opacity', '.4');
9494
var dir = OC.dirname(result.path);
95-
if (dir === '') {
95+
// "result.path" does not include a leading "/", so "OC.dirname"
96+
// returns the path itself for files or folders in the root.
97+
if (dir === result.path) {
9698
dir = '/';
9799
}
98100
$row.find('td.info a').attr('href',

tests/acceptance/config/behat.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ default:
2020
- LoginPageContext
2121
- NotificationContext
2222
- PublicShareContext
23+
- SearchContext
2324
- SettingsContext
2425
- SettingsMenuContext
2526
- ThemingAppContext
@@ -47,6 +48,7 @@ default:
4748
- LoginPageContext
4849
- NotificationContext
4950
- PublicShareContext
51+
- SearchContext
5052
- SettingsContext
5153
- SettingsMenuContext
5254
- ThemingAppContext

tests/acceptance/features/app-comments.feature

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,110 @@ Feature: app-comments
216216
And I open the unread comments for "Child folder"
217217
And I see that the details view is open
218218
And I see a comment with "Hello world" as message
219+
220+
221+
222+
Scenario: search a comment
223+
Given I am logged in
224+
And I open the details view for "welcome.txt"
225+
And I open the "Comments" tab in the details view
226+
And I create a new comment with "Hello world" as message
227+
And I see a comment with "Hello world" as message
228+
When I search for "hello"
229+
# Search results for comments also include the user that wrote the comment.
230+
Then I see that the search result 1 is "user0Hello world"
231+
And I see that the search result 1 was found in "welcome.txt"
232+
233+
Scenario: search a comment in a child folder
234+
Given I am logged in
235+
And I create a new folder named "Folder"
236+
And I enter in the folder named "Folder"
237+
And I create a new folder named "Child folder"
238+
And I open the details view for "Child folder"
239+
And I open the "Comments" tab in the details view
240+
And I create a new comment with "Hello world" as message
241+
And I see a comment with "Hello world" as message
242+
# The Files app is open again to reload the file list
243+
And I open the Files app
244+
When I search for "hello"
245+
# Search results for comments also include the user that wrote the comment.
246+
Then I see that the search result 1 is "user0Hello world"
247+
And I see that the search result 1 was found in "Folder/Child folder"
248+
249+
Scenario: search a comment by a another user
250+
Given I act as John
251+
And I am logged in as the admin
252+
And I act as Jane
253+
And I am logged in
254+
And I act as John
255+
And I rename "welcome.txt" to "shared.txt"
256+
And I share "shared.txt" with "user0"
257+
And I see that the file is shared with "user0"
258+
And I act as Jane
259+
# The Files app is open again to reload the file list
260+
And I open the Files app
261+
And I open the details view for "shared.txt"
262+
And I open the "Comments" tab in the details view
263+
And I create a new comment with "Hello world" as message
264+
And I see a comment with "Hello world" as message
265+
When I act as John
266+
And I search for "hello"
267+
# Search results for comments also include the user that wrote the comment.
268+
Then I see that the search result 1 is "user0Hello world"
269+
And I see that the search result 1 was found in "shared.txt"
270+
271+
Scenario: open a search result for a comment in a file
272+
Given I am logged in
273+
And I open the details view for "welcome.txt"
274+
And I open the "Comments" tab in the details view
275+
And I create a new comment with "Hello world" as message
276+
And I see a comment with "Hello world" as message
277+
# Force the details view to change to a different file before closing it
278+
And I create a new folder named "Folder"
279+
And I close the details view
280+
When I search for "hello"
281+
And I open the search result 1
282+
Then I see that the details view is open
283+
And I see that the file name shown in the details view is "welcome.txt"
284+
And I see a comment with "Hello world" as message
285+
And I see that the file list is currently in "Home"
286+
And I see that the file list contains a file named "welcome.txt"
287+
288+
Scenario: open a search result for a comment in a folder named like its child folder
289+
Given I am logged in
290+
And I create a new folder named "Folder"
291+
And I open the details view for "Folder"
292+
And I open the "Comments" tab in the details view
293+
And I create a new comment with "Hello world" as message
294+
And I see a comment with "Hello world" as message
295+
And I enter in the folder named "Folder"
296+
And I create a new folder named "Folder"
297+
# The Files app is open again to reload the file list
298+
And I open the Files app
299+
When I search for "hello"
300+
And I open the search result 1
301+
Then I see that the details view is open
302+
And I see that the file name shown in the details view is "Folder"
303+
And I see a comment with "Hello world" as message
304+
And I see that the file list is currently in "Home"
305+
And I see that the file list contains a file named "welcome.txt"
306+
And I see that the file list contains a file named "Folder"
307+
308+
Scenario: open a search result for a comment in a child folder
309+
Given I am logged in
310+
And I create a new folder named "Folder"
311+
And I enter in the folder named "Folder"
312+
And I create a new folder named "Child folder"
313+
And I open the details view for "Child folder"
314+
And I open the "Comments" tab in the details view
315+
And I create a new comment with "Hello world" as message
316+
And I see a comment with "Hello world" as message
317+
# The Files app is open again to reload the file list
318+
And I open the Files app
319+
When I search for "hello"
320+
And I open the search result 1
321+
Then I see that the details view is open
322+
And I see that the file name shown in the details view is "Child folder"
323+
And I see a comment with "Hello world" as message
324+
And I see that the file list is currently in "Home/Folder"
325+
And I see that the file list contains a file named "Child folder"

tests/acceptance/features/bootstrap/FileListContext.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ public static function mainWorkingIcon($fileListAncestor) {
8787
describedAs("Main working icon in file list");
8888
}
8989

90+
/**
91+
* @return Locator
92+
*/
93+
public static function breadcrumbs($fileListAncestor) {
94+
return Locator::forThe()->css("#controls .breadcrumb")->
95+
descendantOf($fileListAncestor)->
96+
describedAs("Breadcrumbs in file list");
97+
}
98+
9099
/**
91100
* @return Locator
92101
*/
@@ -375,6 +384,16 @@ public function iSeeThatTheFileListIsEventuallyLoaded() {
375384
}
376385
}
377386

387+
/**
388+
* @Then I see that the file list is currently in :path
389+
*/
390+
public function iSeeThatTheFileListIsCurrentlyIn($path) {
391+
// The text of the breadcrumbs is the text of all the crumbs separated
392+
// by white spaces.
393+
PHPUnit_Framework_Assert::assertEquals(
394+
str_replace('/', ' ', $path), $this->actor->find(self::breadcrumbs($this->fileListAncestor), 10)->getText());
395+
}
396+
378397
/**
379398
* @Then I see that it is not possible to create new files
380399
*/
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
/**
4+
*
5+
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
use Behat\Behat\Context\Context;
25+
26+
class SearchContext implements Context, ActorAwareInterface {
27+
28+
use ActorAware;
29+
30+
/**
31+
* @return Locator
32+
*/
33+
public static function searchBoxInput() {
34+
return Locator::forThe()->css("#header .searchbox input")->
35+
describedAs("Search box input in the header");
36+
}
37+
38+
/**
39+
* @return Locator
40+
*/
41+
public static function searchResults() {
42+
return Locator::forThe()->css("#searchresults")->
43+
describedAs("Search results");
44+
}
45+
46+
/**
47+
* @return Locator
48+
*/
49+
public static function searchResult($number) {
50+
return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' result ')][$number]")->
51+
descendantOf(self::searchResults())->
52+
describedAs("Search result $number");
53+
}
54+
55+
/**
56+
* @return Locator
57+
*/
58+
public static function searchResultName($number) {
59+
return Locator::forThe()->css(".name")->
60+
descendantOf(self::searchResult($number))->
61+
describedAs("Name for search result $number");
62+
}
63+
64+
/**
65+
* @return Locator
66+
*/
67+
public static function searchResultPath($number) {
68+
// Currently search results for comments misuse the ".path" class to
69+
// dim the user name, so "div.path" needs to be used to find the proper
70+
// path element.
71+
return Locator::forThe()->css("div.path")->
72+
descendantOf(self::searchResult($number))->
73+
describedAs("Path for search result $number");
74+
}
75+
76+
/**
77+
* @return Locator
78+
*/
79+
public static function searchResultLink($number) {
80+
return Locator::forThe()->css(".link")->
81+
descendantOf(self::searchResult($number))->
82+
describedAs("Link for search result $number");
83+
}
84+
85+
/**
86+
* @When I search for :query
87+
*/
88+
public function iSearchFor($query) {
89+
$this->actor->find(self::searchBoxInput(), 10)->setValue($query . "\r");
90+
}
91+
92+
/**
93+
* @When I open the search result :number
94+
*/
95+
public function iOpenTheSearchResult($number) {
96+
$this->actor->find(self::searchResultLink($number), 10)->click();
97+
}
98+
99+
/**
100+
* @Then I see that the search result :number is :name
101+
*/
102+
public function iSeeThatTheSearchResultIs($number, $name) {
103+
PHPUnit_Framework_Assert::assertEquals(
104+
$name, $this->actor->find(self::searchResultName($number), 10)->getText());
105+
}
106+
107+
/**
108+
* @Then I see that the search result :number was found in :path
109+
*/
110+
public function iSeeThatTheSearchResultWasFoundIn($number, $path) {
111+
PHPUnit_Framework_Assert::assertEquals(
112+
$path, $this->actor->find(self::searchResultPath($number), 10)->getText());
113+
}
114+
115+
}

0 commit comments

Comments
 (0)