add datastar and render shim
This commit is contained in:
parent
9ce576e7e8
commit
2accb26546
6 changed files with 173 additions and 42 deletions
59
tests/test_web.py
Normal file
59
tests/test_web.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from repub.web import create_app
|
||||
|
||||
|
||||
def test_root_get_serves_datastar_shim() -> None:
|
||||
async def run() -> None:
|
||||
client = create_app().test_client()
|
||||
|
||||
response = await client.get("/")
|
||||
body = await response.get_data(as_text=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["ETag"]
|
||||
assert body.startswith("<!doctype html>")
|
||||
assert (
|
||||
'<script id="js" defer type="module" src="/static/datastar@1.0.0-RC.8.js"></script>'
|
||||
in body
|
||||
)
|
||||
assert 'data-signals:tabid="self.crypto.randomUUID().substring(0,8)"' in body
|
||||
assert 'data-init="@post(window.location.pathname +' in body
|
||||
assert "retryMaxCount: Infinity" in body
|
||||
assert "data-on:online__window=" in body
|
||||
assert '<main id="morph"></main>' in body
|
||||
|
||||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_root_get_honors_if_none_match() -> None:
|
||||
async def run() -> None:
|
||||
client = create_app().test_client()
|
||||
|
||||
initial = await client.get("/")
|
||||
etag = initial.headers["ETag"]
|
||||
|
||||
response = await client.get("/", headers={"If-None-Match": etag})
|
||||
|
||||
assert response.status_code == 304
|
||||
assert response.headers["ETag"] == etag
|
||||
|
||||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_root_post_serves_morph_component() -> None:
|
||||
async def run() -> None:
|
||||
client = create_app().test_client()
|
||||
|
||||
response = await client.post("/?u=shim")
|
||||
body = await response.get_data(as_text=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.content_type == "text/html; charset=utf-8"
|
||||
assert body.startswith('<main id="morph"')
|
||||
assert "Admin UI" in body
|
||||
assert "All on one page for the v1 spike" not in body
|
||||
|
||||
asyncio.run(run())
|
||||
Loading…
Add table
Add a link
Reference in a new issue