93 lines
3.6 KiB
Python
93 lines
3.6 KiB
Python
"""The Roles page's shell: the feed and a role's reader are one page, so
|
|
`/roles/{uid}` renders what `/` renders with that role open. The script
|
|
itself is exercised in a browser, not here; this holds what the server
|
|
decides."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Iterator
|
|
from datetime import UTC, datetime
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.config import Config, ServerConfig
|
|
from app.main import create_app
|
|
from app.storage import Store
|
|
from desk.models import Item
|
|
|
|
|
|
def posting(source_id: str = "1", **raw: object) -> Item:
|
|
item = Item(source_id=source_id, location=f"https://boards.example/acme/{source_id}",
|
|
title="Senior Backend Engineer", body="Build things.",
|
|
published_at=datetime(2026, 9, 20, tzinfo=UTC), raw=dict(raw))
|
|
item.source = "ats"
|
|
return item
|
|
|
|
|
|
@pytest.fixture
|
|
def app(tmp_path: Path) -> FastAPI:
|
|
return create_app(Config(server=ServerConfig(host="127.0.0.1", port=0),
|
|
database=tmp_path / "roledesk.db"))
|
|
|
|
|
|
@pytest.fixture
|
|
def store(app: FastAPI) -> Store:
|
|
return app.state.store
|
|
|
|
|
|
@pytest.fixture
|
|
def client(app: FastAPI) -> Iterator[TestClient]:
|
|
with TestClient(app) as c:
|
|
yield c
|
|
|
|
|
|
def test_the_roles_page_is_the_rail_the_feed_and_a_shut_reader(client: TestClient) -> None:
|
|
page = client.get("/").text
|
|
for part in ('id="rail"', 'id="list"', 'id="roles-list"', 'id="reader"',
|
|
'id="rail-toggle"', 'id="search"', 'id="sort"', 'id="period"', 'id="tags"'):
|
|
assert part in page, part
|
|
assert '<article id="reader" aria-label="Role" hidden>' in page
|
|
assert "data-reader" not in page.split("<header", 1)[0]
|
|
assert "<title>Roles — roledesk</title>" in page
|
|
assert "/static/roles.js" in page and "/static/judge.js" in page
|
|
|
|
|
|
def test_the_rail_opens_on_viewing_as_then_filters_then_order(client: TestClient) -> None:
|
|
rail = client.get("/").text.split('<aside id="rail"', 1)[1].split("</aside>", 1)[0]
|
|
for part in ('id="agent"', 'id="agent-none"', 'href="/settings/agents"'):
|
|
assert part in rail, part
|
|
headings = [rail.index(h) for h in ("Viewing as", "<h3>Filters</h3>", "<h3>Order</h3>",
|
|
"<h3>Tags")]
|
|
assert headings == sorted(headings)
|
|
# The agent is not an order any more: the segmented control is the order.
|
|
assert rail.index('id="sort"') > rail.index("<h3>Order</h3>")
|
|
assert rail.count('id="agent"') == 1
|
|
|
|
|
|
def test_a_role_address_is_the_same_page_with_its_reader_open(
|
|
client: TestClient, store: Store) -> None:
|
|
store.upsert_role(posting("1", company="Acme"))
|
|
uid = posting("1").uid
|
|
|
|
page = client.get(f"/roles/{uid}")
|
|
assert page.status_code == 200
|
|
assert 'id="roles-list"' in page.text and "/static/roles.js" in page.text
|
|
assert '<body data-reader="open">' in page.text
|
|
assert '<article id="reader" aria-label="Role">' in page.text
|
|
assert "<title>Senior Backend Engineer — roledesk</title>" in page.text
|
|
# Roles stays the lit tab, though the path is not its own.
|
|
assert 'href="/"\n class="active" aria-current="page">Roles' in page.text
|
|
|
|
missing = client.get("/roles/nope")
|
|
assert missing.status_code == 404 and "text/html" in missing.headers["content-type"]
|
|
|
|
|
|
def test_the_read_page_of_its_own_is_gone(client: TestClient) -> None:
|
|
assert client.get("/static/role.js").status_code == 404
|
|
other = client.get("/applications").text
|
|
assert 'id="rail-toggle"' not in other and 'id="search"' not in other
|
|
assert "<main>" in other
|