Files
devplacepy/tests/e2e/comments/edit.py
T
retoor 8a48e3ef85
DevPlace CI / test (push) Failing after 3h10m39s
Keep composers usable, group actions and notifications, and drop the tool-count cap
Comment and post layouts stay full width on small screens. Secondary actions live in the More menu. Notifications can be grouped and throttled, and Enter can submit when that profile setting is on. Emulated-tool models accept large catalogs, with reserved names aliased on the wire and the catalog cached per owner. A dropped service-worker navigation is retried once. The test server waits 120s to finish importing before it is stopped.
2026-11-12 15:29:27 +01:00

141 lines
5.9 KiB
Python

# retoor <retoor@molodetz.nl>
from playwright.sync_api import expect
from tests.conftest import BASE_URL, assert_no_horizontal_overflow
from tests.e2e.post import create_post
def _post_comment(page, body):
textarea = page.locator(".comment-form textarea[name='content']")
textarea.fill(body)
page.locator(".comment-form button:has-text('Post')").click()
comment = page.locator(f".comment-text:has-text('{body}')")
expect(comment).to_be_visible()
return comment
def test_inline_edit_own_comment(alice):
page, _ = alice
create_post(page, "devlog", "Post for inline comment edit")
comment = _post_comment(page, "Original comment body")
edit_btn = page.locator(".comment-action-btn:has-text('Edit')").last
expect(edit_btn).to_be_visible()
edit_btn.click()
edit_textarea = page.locator(".comment-edit-form textarea[name='content']")
expect(edit_textarea).to_be_visible()
expect(edit_textarea).to_have_value("Original comment body")
edit_textarea.fill("Edited comment body")
page.locator(".comment-edit-form button:has-text('Save')").click()
expect(page.locator(".comment-text:has-text('Edited comment body')")).to_be_visible()
expect(page.locator(".comment-text:has-text('Original comment body')")).to_have_count(0)
def test_cancel_inline_edit(alice):
page, _ = alice
create_post(page, "fun", "Post for cancel edit")
_post_comment(page, "Keep this body")
page.locator(".comment-action-btn:has-text('Edit')").last.click()
edit_textarea = page.locator(".comment-edit-form textarea[name='content']")
expect(edit_textarea).to_be_visible()
edit_textarea.fill("Discarded body")
page.locator(".comment-edit-form button:has-text('Cancel')").click()
expect(page.locator(".comment-edit-form")).to_have_count(0)
expect(page.locator(".comment-text:has-text('Keep this body')")).to_be_visible()
def _composer_metrics(textarea):
return textarea.evaluate(
"""el => {
const form = el.closest("form");
const actions = form.querySelector(".comment-form-actions");
const field = el.getBoundingClientRect();
const formBox = form.getBoundingClientRect();
const actionBox = actions.getBoundingClientRect();
const column = document.querySelector(".post-page, .feed-main");
const columnBox = column ? column.getBoundingClientRect() : formBox;
return {
field: field.width,
fieldHeight: field.height,
form: formBox.width,
column: columnBox.width,
actionsTop: actionBox.top,
actionsWidth: actionBox.width,
fieldBottom: field.bottom,
overflow: document.documentElement.scrollWidth - document.documentElement.clientWidth,
};
}"""
)
def _assert_composer_has_room(metrics, minimum_field, full_width=False):
slack = 8 if full_width else 64
assert metrics["field"] >= metrics["form"] - slack, metrics
assert metrics["field"] >= minimum_field, metrics
assert metrics["fieldHeight"] < 90, metrics
assert metrics["actionsTop"] >= metrics["fieldBottom"] - 2, metrics
assert metrics["actionsWidth"] <= metrics["form"] + 1, metrics
assert metrics["overflow"] <= 1, metrics
def _check_composer(page, textarea, minimum_field, full_width, min_column):
textarea.fill("helps a lot.")
metrics = _composer_metrics(textarea)
_assert_composer_has_room(metrics, minimum_field, full_width)
assert metrics["column"] >= min_column, metrics
def test_comment_composer_field_keeps_its_width(alice):
page, _ = alice
page.set_viewport_size({"width": 1280, "height": 800})
create_post(page, "devlog", "Post for the comment composer width")
_post_comment(page, "Parent for the reply box")
composer = page.locator(".comment-form:not(.comment-reply-form) textarea[name='content']").last
_check_composer(page, composer, 320, False, 480)
page.locator("[data-action='reply']").last.click()
reply = page.locator(".comment-reply-form textarea[name='content']")
expect(reply).to_be_visible()
_check_composer(page, reply, 320, False, 480)
page.set_viewport_size({"width": 768, "height": 1024})
_check_composer(page, reply, 280, False, 480)
page.set_viewport_size({"width": 390, "height": 844})
_check_composer(page, reply, 200, True, 300)
_check_composer(page, composer, 200, True, 300)
page.set_viewport_size({"width": 360, "height": 740})
_check_composer(page, reply, 180, True, 280)
assert_no_horizontal_overflow(page, ".post-page-layout")
page.set_viewport_size({"width": 1280, "height": 800})
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
card = page.locator(".post-card").filter(has_text="Parent for the reply box").first
expect(card).to_be_visible()
card.locator("[data-action='reply']").first.click()
feed_reply = card.locator(".comment-reply-form textarea[name='content']")
expect(feed_reply).to_be_visible()
_check_composer(page, feed_reply, 200, False, 480)
page.set_viewport_size({"width": 768, "height": 1024})
_check_composer(page, feed_reply, 200, False, 400)
page.set_viewport_size({"width": 390, "height": 844})
_check_composer(page, feed_reply, 160, True, 300)
page.set_viewport_size({"width": 360, "height": 740})
_check_composer(page, feed_reply, 140, True, 280)
assert_no_horizontal_overflow(page, ".feed-layout")
def test_non_owner_sees_no_edit_button(alice, bob):
page, _ = alice
create_post(page, "random", "Post owned by alice")
_post_comment(page, "Alice only comment")
post_url = page.url
bob_page, _ = bob
bob_page.goto(post_url, wait_until="domcontentloaded")
expect(bob_page.locator(".comment-text:has-text('Alice only comment')")).to_be_visible()
expect(bob_page.locator(".comment-action-btn:has-text('Edit')")).to_have_count(0)