import os from pathlib import Path import pytest if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1": pytest.skip("packaged adaptive Queues journey runs only in its gated CI job", allow_module_level=True) pytest.importorskip("playwright.sync_api") from playwright.sync_api import expect, sync_playwright ROOT = Path(__file__).parents[2] FRONTEND = ROOT / "frontend" @pytest.mark.parametrize("viewport", [ {"width": 320, "height": 568}, {"width": 375, "height": 667}, {"width": 430, "height": 932}, ]) def test_adaptive_queues_put_truthful_next_action_above_the_fold(viewport): with sync_playwright() as playwright: browser = playwright.chromium.launch(headless=True) page = browser.new_page(viewport=viewport) page.set_content((FRONTEND / "index.html").read_text()) page.add_style_tag(path=FRONTEND / "dashboard.css") page.add_script_tag(path=FRONTEND / "mobile-queue-launcher.js") page.evaluate("""() => { const rows = Object.fromEntries(Array.from(document.querySelectorAll('[data-mobile-queue]')) .map(row => [row.dataset.mobileQueue, row])); window.adaptiveQueueLauncher = createMobileQueueLauncher({ getCounts:() => ({delivery:1, gate:2, today:3, attentionUnavailable:true}), rows, nextAction:document.querySelector('#mobile-queue-next-action'), activeList:document.querySelector('#mobile-queue-active-list'), planningList:document.querySelector('#mobile-queue-planning-list'), allList:document.querySelector('#mobile-queue-all-list'), activeSection:document.querySelector('#mobile-queue-active-list').parentElement, }); window.adaptiveQueueLauncher.renderPresentation(); document.querySelector('#mobile-queue-sheet').showModal(); }""") next_action = page.locator("#mobile-queue-next-action") expect(next_action).to_be_visible() expect(next_action).to_have_text("Recover Delivery (1)") bounds = next_action.bounding_box() assert bounds and bounds["height"] >= 44 assert bounds["x"] >= 0 and bounds["x"] + bounds["width"] <= viewport["width"] assert bounds["y"] + bounds["height"] <= viewport["height"] assert page.locator("#mobile-queue-active-list [data-mobile-queue]").evaluate_all( "rows => rows.map(row => row.dataset.mobileQueue)" ) == ["delivery", "gate", "attention"] expect(page.locator('[data-mobile-queue="attention"]')).to_have_attribute("data-unavailable", "true") assert page.locator("#mobile-queue-planning-list [data-mobile-queue]").evaluate_all( "rows => rows.map(row => row.dataset.mobileQueue)" ) == ["today", "tomorrow", "week"] expect(page.locator(".mobile-queue-all")).not_to_have_attribute("open", "") assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth") browser.close()