intent/tests/test_a11y.py
Alec Perkins 5811e72a0c Add issues and comment threads (Phase 3)
Issues: per-project numbers, statuses (open, accepted, rejected,
withdrawn, duplicate), feature links, edits, and a timeline of comments
and events. From an issue, collaborators create or update a feature
with the revision tied to the issue and an option to accept it.

Comments: general and line-anchored threads on features, one
discussion thread per issue, edit history, tombstone deletes, resolve,
and promoting a feature thread to an issue. Line threads attach to
top-level Markdown blocks and go outdated only when the text changes.

HTMX swaps threads in place with focus management; every action also
works as a plain form post. Markdown headings are re-levelled so user
text never skips heading levels on the page.

The example flow from concept.md (steps 1-7) is covered end to end in
tests/test_example_flow.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 09:18:45 -04:00

129 lines
5.5 KiB
Python

import pytest
from django.urls import reverse
from intent.comments.services import edit_comment, reply, start_feature_thread
from intent.features.services import create_feature, update_feature
from intent.issues.services import create_issue, set_status, update_issue
from intent.orgs.services import invite
from .a11y import assert_accessible_html
@pytest.fixture
def populated(project, owner, make_user, org):
parent = create_feature(project, owner, title="Accounts", description="# Goal\n\nText\n")
child = create_feature(project, owner, title="Sign in", parent=parent)
update_feature(child, owner, note="Detail", description="Steps\n\n1. One\n2. Two\n")
invite(org, owner, email="new@example.com")
# Discussion: a line thread that goes outdated, a current one, a general one, an issue.
old = start_feature_thread(child, owner, body="# Old\n\nOn steps", revision=2,
line_start=1, line_end=1) # fmt: skip
update_feature(child, owner, note="Reword", description="Steps\n\n1. One\n2. Two\n3. Three\n")
start_feature_thread(child, owner, body="On the list", revision=3, line_start=3, line_end=5)
general = start_feature_thread(child, owner, body="General")
reply(general, owner, body="## Reply heading")
edit_comment(general.comments.first(), owner, body="General, edited")
reply(old, owner, body="Still relevant?")
issue = create_issue(project, owner, title="Bug", body="# Heading\n\nText", features=[child])
reply(issue.threads.get(), owner, body="### Deep heading")
update_issue(issue, owner, title="Bug!", body="## New")
set_status(issue, owner, "rejected")
return child
def _pages(org, project, feature):
o, p, k = org.slug, project.slug, feature.key
pk = {"org_slug": o, "project_slug": p}
fk = {**pk, "feature_key": k}
return [
reverse("home"),
reverse("invites:list"),
reverse("account_email"),
reverse("orgs:detail", kwargs={"org_slug": o}),
reverse("orgs:members", kwargs={"org_slug": o}),
reverse("project_create", kwargs={"org_slug": o}),
reverse("projects:home", kwargs=pk),
reverse("projects:settings", kwargs=pk),
reverse("projects:delete", kwargs=pk),
reverse("projects:members", kwargs=pk),
reverse("features:list", kwargs=pk),
reverse("features:create", kwargs=pk),
reverse("features:detail", kwargs=fk),
reverse("features:edit", kwargs=fk),
reverse("features:history", kwargs=fk),
reverse("features:revision", kwargs={**fk, "revision": 1}),
reverse("features:compare", kwargs=fk),
reverse("features:create", kwargs=pk) + "?issue=1",
reverse("features:edit", kwargs=fk) + "?issue=1",
reverse("issues:list", kwargs=pk),
reverse("issues:list", kwargs=pk) + "?status=closed",
reverse("issues:create", kwargs=pk),
reverse("issues:detail", kwargs={**pk, "number": 1}),
reverse("issues:edit", kwargs={**pk, "number": 1}),
reverse("comments:promote", kwargs={**pk, "thread_id": _thread_id(feature)}),
reverse("comments:history", kwargs={**pk, "comment_id": _edited_comment_id(feature)}),
]
def _thread_id(feature):
return feature.threads.filter(kind="feature").get().pk
def _edited_comment_id(feature):
return feature.threads.filter(kind="feature").get().comments.first().pk
def test_signed_in_pages(client, owner, org, project, populated):
client.force_login(owner)
for path in _pages(org, project, populated):
response = client.get(path)
assert response.status_code == 200, path
try:
assert_accessible_html(response.content.decode())
except AssertionError as exc:
raise AssertionError(f"{path}: {exc}") from None
def test_outsider_pages_on_open_project(client, outsider, org, project, populated):
project.visibility, project.open_contribution = "public", True
project.save()
client.force_login(outsider)
pk = {"org_slug": org.slug, "project_slug": project.slug}
for path in [
reverse("features:detail", kwargs={**pk, "feature_key": populated.key}),
reverse("issues:detail", kwargs={**pk, "number": 1}),
]:
assert_accessible_html(client.get(path).content.decode())
def test_comment_not_posted_page(client, owner, project, populated):
client.force_login(owner)
url = reverse(
"features:thread_create",
kwargs={"org_slug": "catbriar", "project_slug": "intent", "feature_key": populated.key},
)
response = client.post(url, {"body": "x", "revision": 1, "line_start": 1, "line_end": 1})
assert response.status_code == 400
assert_accessible_html(response.content.decode())
@pytest.mark.parametrize(
"html, problem",
[
("<html><body><h1>a</h1></body></html>", "no lang"),
('<html lang="en"><h2>a</h2></html>', "one <h1>"),
('<html lang="en"><h1>a</h1><h3>b</h3></html>', "skips"),
('<html lang="en"><h1 id="x">a</h1><p id="x"></p></html>', "duplicate ids"),
('<html lang="en"><h1>a</h1><input name="q"></html>', "without a label"),
('<html lang="en"><h1>a</h1><img src="x"></html>', "without alt"),
],
)
def test_checker_catches_problems(html, problem):
with pytest.raises(AssertionError, match=problem):
assert_accessible_html(html)
@pytest.mark.parametrize("name", ["account_login", "account_signup", "account_request_login_code"])
def test_signed_out_pages(client, db, name):
assert_accessible_html(client.get(reverse(name)).content.decode())