Expose and compare variants of selected norm tables
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
"""The real norm finder lets a person inspect nearby variants in the same table."""
|
||||
import functools
|
||||
import http.server
|
||||
import shutil
|
||||
import socketserver
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from test_password_reset_ui import browser # noqa: E402,F401
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def site(tmp_path_factory):
|
||||
root = tmp_path_factory.mktemp("norm-finder-ui")
|
||||
static = root / "static"
|
||||
static.mkdir()
|
||||
finder = root / "podbor"
|
||||
finder.mkdir()
|
||||
source = Path(__file__).resolve().parents[1] / "static"
|
||||
shutil.copy2(source / "norm-finder.html", finder / "index.html")
|
||||
shutil.copy2(source / "norm-finder.js", static / "norm-finder.js")
|
||||
handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=str(root))
|
||||
|
||||
class Quiet(socketserver.ThreadingTCPServer):
|
||||
allow_reuse_address = True
|
||||
daemon_threads = True
|
||||
|
||||
server = Quiet(("127.0.0.1", 0), handler)
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
yield f"http://127.0.0.1:{server.server_address[1]}/podbor/"
|
||||
server.shutdown()
|
||||
|
||||
|
||||
def test_family_variants_can_be_opened_and_compared_on_phone(browser, site):
|
||||
page = browser.new_page(viewport={"width": 390, "height": 844})
|
||||
page.add_init_script("""(() => {
|
||||
localStorage.setItem('token', 'x.eyJzdWIiOiJ0ZXN0QHgifQ.y');
|
||||
const base = {base:'ГЭСН-2022',base_type:'ГЭСН',unit:'100 м2'};
|
||||
const a = {...base,code:'11-01-011-12',name:'Полусухая цементно-песчаная стяжка'};
|
||||
const b = {...base,code:'11-01-011-01',name:'Цементная стяжка толщиной 20 мм'};
|
||||
window.fetch = async url => {
|
||||
const u = new URL(url, location.href);
|
||||
let value;
|
||||
if (u.pathname.endsWith('/catalog')) value={bases:[{base:'ГЭСН-2022',count:56192}],subjects:[]};
|
||||
else if (u.pathname.endsWith('/search')) value={items:u.searchParams.get('q')==='11-01-011'?[a,b]:[a]};
|
||||
else if (u.pathname.endsWith('/detail')) {
|
||||
const chosen=u.searchParams.get('code')===a.code?a:b;
|
||||
value={...chosen,content:['Устройство стяжки'],resources:[{
|
||||
code:chosen===a?'A-1':'B-1',name:'Ресурс',unit:'шт',quantity:1}],
|
||||
provenance:{decree:'Источник'},current_price_supported:false};
|
||||
}
|
||||
else value={};
|
||||
return new Response(JSON.stringify(value),{status:200,headers:{'Content-Type':'application/json'}});
|
||||
};
|
||||
})()""")
|
||||
page.goto(site)
|
||||
page.locator('#query').fill('стяжка пола')
|
||||
page.locator('#search-form button[type="submit"]').click()
|
||||
page.locator('button', has_text='Варианты таблицы').click()
|
||||
options = page.locator('.variant-option')
|
||||
options.first.wait_for()
|
||||
assert options.count() == 2
|
||||
page.locator('.variant-row').nth(0).locator('button').last.click()
|
||||
page.locator('.variant-row').nth(1).locator('button').last.click()
|
||||
page.locator('#comparison .card').nth(1).wait_for()
|
||||
assert 'Отличающиеся ресурсы' in page.locator('#comparison').inner_text()
|
||||
options.filter(has_text='11-01-011-01').click()
|
||||
page.locator('#detail-title', has_text='11-01-011-01').wait_for()
|
||||
assert page.locator('#detail').inner_text().find('100 м2') >= 0
|
||||
assert page.evaluate('document.documentElement.scrollWidth <= window.innerWidth')
|
||||
page.close()
|
||||
Reference in New Issue
Block a user