Page norm matches and finish finder release
This commit is contained in:
@@ -19,7 +19,28 @@ def test_search_rejects_empty_query_and_uses_existing_fsnb(monkeypatch):
|
||||
found = norm_finder.search("извещатель", "2022", 12)
|
||||
assert found["items"][0]["code"] == "10-08-002-02"
|
||||
assert found["items"][0]["match_reason"].startswith("Совпали слова")
|
||||
assert seen == [("извещатель", "2022", 12)]
|
||||
assert seen == [("извещатель", "2022", 60)]
|
||||
|
||||
|
||||
def test_search_pages_keep_the_same_ranked_window(monkeypatch):
|
||||
import fsnb_ref
|
||||
import norm_finder
|
||||
calls = []
|
||||
def find(*, query, base, limit):
|
||||
calls.append(limit)
|
||||
return {"status": "ok", "works": [
|
||||
{"code": f"11-01-{i:03d}-01", "name": f"Стяжка пола {i}",
|
||||
"base": "ГЭСН-2022", "base_type": "ГЭСН", "unit": "100 м2"}
|
||||
for i in range(20)]}
|
||||
monkeypatch.setattr(fsnb_ref, "find_works", find)
|
||||
monkeypatch.setattr(fsnb_ref, "count_works", lambda term: 0)
|
||||
first = norm_finder.search("стяжка", "2022", 8, 0)
|
||||
second = norm_finder.search("стяжка", "2022", 8, 8)
|
||||
assert first["has_more"] is True
|
||||
assert len({row["code"] for row in first["items"] + second["items"]}) == 16
|
||||
assert calls == [60, 60]
|
||||
with pytest.raises(ValueError):
|
||||
norm_finder.search("стяжка", "2022", 8, 60)
|
||||
|
||||
|
||||
def test_search_falls_back_to_subject_term_and_ranks_relevant_work(monkeypatch):
|
||||
|
||||
@@ -194,3 +194,33 @@ def test_guest_can_search_and_read_norm_but_not_see_price_controls(browser, site
|
||||
if screenshot_dir:
|
||||
page.screenshot(path=str(Path(screenshot_dir) / 'norm-finder-guest-mobile.png'), full_page=True)
|
||||
page.close()
|
||||
|
||||
|
||||
def test_guest_can_open_next_page_without_losing_first_results(browser, site):
|
||||
page = browser.new_page(viewport={"width": 390, "height": 844})
|
||||
offsets = []
|
||||
|
||||
def handle(route):
|
||||
url = urlsplit(route.request.url)
|
||||
if url.path.endswith("/catalog"):
|
||||
data = {"bases": [{"base": "ГЭСН-2022", "count": 56192}]}
|
||||
else:
|
||||
from urllib.parse import parse_qs
|
||||
offset = int(parse_qs(url.query).get("offset", ["0"])[0])
|
||||
offsets.append(offset)
|
||||
data = {"items": [{"base": "ГЭСН-2022", "base_type": "ГЭСН",
|
||||
"code": f"11-01-{offset + i:03d}-01", "name": f"Стяжка {offset + i}",
|
||||
"unit": "100 м2"} for i in range(8)], "has_more": offset == 0}
|
||||
route.fulfill(status=200, content_type="application/json", body=json.dumps(data, ensure_ascii=False))
|
||||
|
||||
page.route("**/api/public/norm-finder/**", handle)
|
||||
page.goto(site)
|
||||
page.locator('#query').fill('стяжка')
|
||||
page.locator('#search-form button[type="submit"]').click()
|
||||
page.locator('#results .card').nth(7).wait_for()
|
||||
page.locator('#more-results').click()
|
||||
page.locator('#results .card').nth(15).wait_for()
|
||||
assert offsets == [0, 8]
|
||||
assert page.locator('#results .card').count() == 16
|
||||
assert page.locator('#more-results').is_hidden()
|
||||
page.close()
|
||||
|
||||
Reference in New Issue
Block a user