Skip to content

Test delay in search bar on webUI #33493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions core/search/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
var lastSize = 30;
var lastResults = [];
var timeoutID = null;
/* For delaying search*/
var timeout = null;

this.getLastQuery = function() {
return lastQuery;
Expand Down Expand Up @@ -319,18 +321,24 @@
renderCurrent();
}
} else {
var query = $searchBox.val();
if (lastQuery !== query) {
currentResult = -1;
if (query.length > 2) {
self.search(query);
} else {
self.hideResults();
}
if(self.hasFilter(getCurrentApp())) {
self.getFilter(getCurrentApp())(query);
/**
* Search begins 500 millisoconds after the user stops typing
*/
clearTimeout(timeout);
timeout = setTimeout(function () {
var query = $searchBox.val();
if (lastQuery !== query) {
currentResult = -1;
if (query.length > 2) {
self.search(query);
} else {
self.hideResults();
}
if(self.hasFilter(getCurrentApp())) {
self.getFilter(getCurrentApp())(query);
}
}
}
}, 500);
}
});
$(document).keyup(function(event) {
Expand Down
37 changes: 37 additions & 0 deletions tests/acceptance/features/bootstrap/WebUISearchContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,43 @@ public function fileShouldNotBeListedSearchResultOtherFolders($fileName, $should
);
}

/**
* @When the user enters search text :searchTerm in the search box using the webUI
*
* @param string $searchTerm
*
* @return void
*/
public function theUserEntersSearchTextInTheSearchBoxUsingTheWebui($searchTerm) {
$this->filesPage->waitTillPageIsLoaded($this->getSession());
$searchbox = $this->filesPage->findById($this->filesPage->getSearchBoxId());
$this->filesPage->assertElementNotNull(
$searchbox,
__METHOD__ .
"could not find searchbox / button"
);
$searchbox->click();
$searchbox->setValue($searchTerm);
}

/**
* @Then the ajax call should not start immediately
*
* @return void
*/
public function theAjaxCallShouldNotStartImmediately() {
// delay for search box in UI
$wait_time_msec = 500;

$start = \microtime(true);
// give 1000ms extra for timeout to make sure that the function terminates only after it finds a ajax call
$this->filesPage->waitForAjaxCallsToStart($this->getSession(), $wait_time_msec + 1000);

$end = \microtime(true);
$timeout_msec = (($end - $start) * 1000);
PHPUnit_Framework_Assert::assertGreaterThan($wait_time_msec, $timeout_msec);
}

/**
* This will run before EVERY scenario.
* It will set the properties for this object.
Expand Down
7 changes: 7 additions & 0 deletions tests/acceptance/features/lib/OwncloudPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,11 @@ public function assertElementNotNull($element, $message) {
throw new ElementNotFoundException($message);
}
}

/**
* @return string the id of search box
*/
public function getSearchBoxId() {
return $this->searchBoxId;
}
}
6 changes: 5 additions & 1 deletion tests/acceptance/features/webUIFiles/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,8 @@ Feature: Search
And user "user1" has uploaded file with content "does-not-matter" to "/strängé नेपाली folder/strängéनेपालीloremfile.txt"
When the user searches for "strängéनेपाली" using the webUI
Then the file "strängéनेपालीloremfile.txt" with the path "/" should be listed in the search results in other folders section on the webUI
And the file "strängéनेपालीloremfile.txt" with the path "/strängé नेपाली folder" should be listed in the search results in other folders section on the webUI
And the file "strängéनेपालीloremfile.txt" with the path "/strängé नेपाली folder" should be listed in the search results in other folders section on the webUI

Scenario: Search file with delay
When the user enters search text "lorem" in the search box using the webUI
Then the ajax call should not start immediately