first
This commit is contained in:
commit
fa9d154db9
260 files changed
+17643
No files matched your search
@@ -0,0 +1,42 @@
|
||||
from urllib.parse import quote
|
||||
|
||||
import pytest
|
||||
|
||||
from apps.accounts.models import User
|
||||
from tests.e2e.pages.auth import AuthenticationPage
|
||||
|
||||
|
||||
pytestmark = [pytest.mark.e2e, pytest.mark.pwa, pytest.mark.django_db(transaction=True)]
|
||||
PASSWORD = "E2e-safe-password-2026"
|
||||
|
||||
|
||||
def test_pwa_registers_versioned_worker_and_matching_cache(live_server, browser_page):
|
||||
customer = User.objects.create_user(
|
||||
username="e2e-pwa-version",
|
||||
mobile="09120009010",
|
||||
password=PASSWORD,
|
||||
account_type=User.AccountType.CUSTOMER,
|
||||
)
|
||||
|
||||
with browser_page(service_workers="allow") as page:
|
||||
AuthenticationPage(page, live_server.url).login_customer(customer, PASSWORD)
|
||||
|
||||
state = page.evaluate(
|
||||
"""async () => {
|
||||
const registration = await navigator.serviceWorker.ready;
|
||||
const worker = registration.active || registration.waiting || registration.installing;
|
||||
return {
|
||||
version: document.documentElement.dataset.staticVersion,
|
||||
scriptURL: worker && worker.scriptURL,
|
||||
cacheNames: await caches.keys(),
|
||||
};
|
||||
}"""
|
||||
)
|
||||
|
||||
assert state["version"]
|
||||
assert f"/service-worker.js?v={quote(state['version'])}" in state["scriptURL"]
|
||||
assert f"sales-ticket-{state['version']}" in state["cacheNames"]
|
||||
|
||||
worker_response = page.request.get(state["scriptURL"])
|
||||
assert worker_response.ok
|
||||
assert worker_response.headers["cache-control"] == "no-cache, no-store, must-revalidate"
|
||||
Reference in new issue
Block a user