Skip to content
This repository has been archived by the owner on Nov 25, 2023. It is now read-only.

Commit

Permalink
Test endless scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Dec 31, 2017
1 parent 3b09dda commit 4f70166
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion mainapp/assets/js/EndlessScrolling.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* https://stackoverflow.com/a/4842226/3549270
*/
export default class EndlessScrolling {
loadFurtherHeight = 500;

constructor($button) {
this.$button = $button;
this.reset();
Expand All @@ -21,7 +23,8 @@ export default class EndlessScrolling {
if (this.isLoading || !this.isActive) {
return;
}
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 500) {

if ($(window).scrollTop() >= $(document).height() - $(window).height() - this.loadFurtherHeight) {
this.isLoading = true;
let url = this.$button.data("url") + "?after=" + this.$target.find("> li").length;
$.get(url, (data) => {
Expand Down
22 changes: 17 additions & 5 deletions mainapp/tests/live/test_facetted_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from datetime import date
from typing import Any, List
from unittest import mock
Expand All @@ -21,19 +22,20 @@
}


def mock_search_to_results(search: Search) -> (List[Any], int):
def mock_search_to_results(_) -> (List[Any], int):
return [template], 1


def mock_search_for_endless_scroll(search: Search) -> (List[Any], int):
print(search.to_dict()["from"], search.to_dict()["from"])
out = []
for position in range(search.to_dict()["from"], search.to_dict()["from"] + search.to_dict()["size"]):
result = template.copy()
result["name"] = position
result["name_escaped"] = position
result["id"] = position
out.append(result)
return out, len(out)
return out, len(out) * 2


class FacettedSearchTest(ChromeDriverTestCase):
Expand Down Expand Up @@ -140,10 +142,20 @@ def test_dropdown_filter(self, _):
def test_endless_scroll(self, _):
self.browser.visit('%s%s' % (self.live_server_url, '/search/query/word/'))

self.assertEqual(20, len(self.browser.find_by_css(".results-list > li")))
single_length = settings.SEARCH_PAGINATION_LENGTH
self.assertEqual(single_length, len(self.browser.find_by_css(".results-list > li")))
numbers = [int(i.text) for i in self.browser.find_by_css(".results-list > li .result-title")]
numbers.sort()
self.assertEqual(numbers, list(range(0, 20)))
self.assertEqual(numbers, list(range(0, single_length)))

self.click_by_id1
self.click_by_id("start-endless-scroll")

# semi-busy waiting
# (it does work without wating on my machine, but I won't risk having any timing based test failures)
while single_length == len(self.browser.find_by_css(".results-list > li")):
time.sleep(0.01)

self.assertEqual(single_length * 2, len(self.browser.find_by_css(".results-list > li")))
numbers = [int(i.text) for i in self.browser.find_by_css(".results-list > li .result-title")]
numbers.sort()
self.assertEqual(numbers, list(range(0, single_length * 2)))
2 changes: 1 addition & 1 deletion mainapp/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def search_results_only(request, query):
params = search_string_to_params(query)
options, search, _ = params_to_query(params)
after = int(request.GET.get('after', 0))
search = search[after:][:settings.SEARCH_PAGINATION_LENGTH]
search = search[after:settings.SEARCH_PAGINATION_LENGTH+after]
results, total_hits = _search_to_results(search)
context = _search_to_context(query, params, options, results, total_hits, request)

Expand Down

0 comments on commit 4f70166

Please sign in to comment.