Files
jobboard/tests/test_pages.py
T
WolfandClaude Fable 5.1 a9290a6926 Roles is newsdesk's feed: rail, feed and reader, with read state and tags
The Roles tab takes newsdesk's shell, ported from its index.html and
app.css rather than rewritten: a filter rail (Show read, Best first or
Newest first, first seen, tag chips with counts, the old filters behind a
disclosure), the feed in newsdesk's row layout (score gutter, title,
company, place, badges, age, tags, the summary as excerpt, judge buttons)
and the reader as a third column that replaces the list on a phone. The
router pushes /roles/{uid}, which the server also renders with the reader
open, so the separate read page and role.js go. j/k, u/n/d, S, Enter,
Escape, o, /, f and c work as in newsdesk. The phone rules come with their
comments.

Two things the row lacked: roles.read_at, stamped when the reader opens a
role or a vote is cast, behind include_read on /api/roles; and role_tags,
written by summarise alongside the summary and served with counts by
/api/filters, filtered in SQL before LIMIT. Migration 5.

PyCharm run configurations in .run/ for serve, pull, seed and pytest.
core.autocrlf=input is set locally so a Windows-side checkout commits LF.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-28 12:37:45 +02:00

81 lines
2.9 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_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