From 270a8cb796079c829a57274f104c95a37362e463 Mon Sep 17 00:00:00 2001 From: Swati-007 Date: Tue, 2 Oct 2018 01:52:22 +0530 Subject: [PATCH 1/2] Added delay in search Added proper indentation after review --- core/search/js/search.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/core/search/js/search.js b/core/search/js/search.js index ef99cf7e9616..aec1c9f88d9c 100644 --- a/core/search/js/search.js +++ b/core/search/js/search.js @@ -86,6 +86,8 @@ var lastSize = 30; var lastResults = []; var timeoutID = null; + /* For delaying search*/ + var timeout = null; this.getLastQuery = function() { return lastQuery; @@ -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) { From facd47e625abec2912b2e304a640da3dfcdfaff2 Mon Sep 17 00:00:00 2001 From: Dipak Acharya Date: Tue, 13 Nov 2018 14:28:12 +0545 Subject: [PATCH 2/2] Add acceptance tests for delay in searchbox in webUI --- .../features/bootstrap/WebUISearchContext.php | 37 +++++++++++++++++++ .../acceptance/features/lib/OwncloudPage.php | 7 ++++ .../features/webUIFiles/search.feature | 6 ++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/features/bootstrap/WebUISearchContext.php b/tests/acceptance/features/bootstrap/WebUISearchContext.php index 3689db2d3819..cca48b6989b7 100644 --- a/tests/acceptance/features/bootstrap/WebUISearchContext.php +++ b/tests/acceptance/features/bootstrap/WebUISearchContext.php @@ -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. diff --git a/tests/acceptance/features/lib/OwncloudPage.php b/tests/acceptance/features/lib/OwncloudPage.php index 1679bb37a95f..cbbd1e3e20b2 100644 --- a/tests/acceptance/features/lib/OwncloudPage.php +++ b/tests/acceptance/features/lib/OwncloudPage.php @@ -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; + } } diff --git a/tests/acceptance/features/webUIFiles/search.feature b/tests/acceptance/features/webUIFiles/search.feature index e778004987d7..2d4b1eec6600 100644 --- a/tests/acceptance/features/webUIFiles/search.feature +++ b/tests/acceptance/features/webUIFiles/search.feature @@ -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 \ No newline at end of file + 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