2026-06-18 22:09:34 +00:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
from tests.conftest import BASE_URL
|
2026-11-01 11:53:55 +01:00
|
|
|
from tests.unit.embeds import EMBED_CASES, TRACK, VIDEO
|
2026-06-18 22:09:34 +00:00
|
|
|
|
|
|
|
|
ROCKET = "\U0001F680"
|
|
|
|
|
FIRE = "\U0001F525"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _create_post(page, content, title):
|
|
|
|
|
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
|
|
|
page.locator(".feed-fab").first.wait_for(state="visible", timeout=10000)
|
|
|
|
|
page.locator(".feed-fab").first.click()
|
|
|
|
|
page.check("input[value='random']")
|
|
|
|
|
page.fill("#post-content", content)
|
|
|
|
|
page.fill("#post-title", title)
|
|
|
|
|
page.locator("#create-post-modal button.btn-primary:has-text('Post')").click()
|
|
|
|
|
page.wait_for_url(f"{BASE_URL}/posts/*", wait_until="domcontentloaded")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_title_emoji_rendered_server_side(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
_create_post(page, "Body content for the server-rendered title emoji test.", "Launch day :rocket:")
|
|
|
|
|
title = page.locator(".post-detail-title").first
|
|
|
|
|
title.wait_for(state="visible")
|
|
|
|
|
text = title.text_content()
|
|
|
|
|
assert ROCKET in text
|
|
|
|
|
assert ":rocket:" not in text
|
|
|
|
|
assert page.locator("dp-title").count() == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_title_inline_markdown_rendered_server_side(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
_create_post(page, "Body content for the server-rendered title markdown test.", "Ship **v2** today")
|
|
|
|
|
strong = page.locator(".post-detail-title strong").first
|
|
|
|
|
strong.wait_for(state="visible")
|
|
|
|
|
assert strong.text_content().strip() == "v2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_content_youtube_embedded_server_side(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
_create_post(page, "watch https://youtu.be/dQw4w9WgXcQ now", "Embed host post")
|
|
|
|
|
iframe = page.locator(".post-detail-content .embed-youtube iframe").first
|
|
|
|
|
iframe.wait_for(state="attached")
|
|
|
|
|
assert "youtube.com/embed/dQw4w9WgXcQ" in (iframe.get_attribute("src") or "")
|
|
|
|
|
|
|
|
|
|
|
2026-11-01 11:53:55 +01:00
|
|
|
def test_content_music_embedded_server_side(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
_create_post(page, f"hear https://music.youtube.com/watch?v={TRACK} now", "Music host post")
|
|
|
|
|
iframe = page.locator(".post-detail-content .embed-music .embed-youtube iframe").first
|
|
|
|
|
iframe.wait_for(state="attached")
|
|
|
|
|
assert f"youtube.com/embed/{TRACK}" in (iframe.get_attribute("src") or "")
|
|
|
|
|
caption = page.locator(".post-detail-content .embed-music-caption").first
|
|
|
|
|
caption.wait_for(state="visible")
|
|
|
|
|
assert caption.text_content().strip() == "Open in YouTube Music"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_client_embed_parser_matches_server_for_every_case(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
|
|
|
urls = [case[0] for case in EMBED_CASES]
|
|
|
|
|
client = page.evaluate(
|
|
|
|
|
"""async (urls) => {
|
|
|
|
|
const mod = await import('/static/js/EmbedParser.js');
|
|
|
|
|
return urls.map((u) => {
|
|
|
|
|
const e = mod.EmbedParser.parse(u);
|
|
|
|
|
return e ? [mod.EmbedParser.src(e), e.music] : null;
|
|
|
|
|
});
|
|
|
|
|
}""",
|
|
|
|
|
urls,
|
|
|
|
|
)
|
|
|
|
|
for (url, expected, music), got in zip(EMBED_CASES, client):
|
|
|
|
|
if expected is None:
|
|
|
|
|
assert got is None, url
|
|
|
|
|
else:
|
|
|
|
|
assert got == [expected, music], url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_client_renderer_embeds_music_and_caps_it(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
|
|
|
urls = " ".join(f"https://music.youtube.com/watch?v={VIDEO[:-1]}{c}" for c in "abcde")
|
|
|
|
|
result = page.evaluate(
|
|
|
|
|
"""async (text) => {
|
|
|
|
|
const mod = await import('/static/js/ContentRenderer.js');
|
|
|
|
|
const box = document.createElement('div');
|
|
|
|
|
box.innerHTML = mod.contentRenderer.processMedia(text);
|
|
|
|
|
return {
|
|
|
|
|
frames: box.querySelectorAll('.embed-music iframe').length,
|
|
|
|
|
captions: box.querySelectorAll('.embed-music-caption').length,
|
|
|
|
|
links: box.querySelectorAll('a:not(.embed-music-caption)').length,
|
|
|
|
|
};
|
|
|
|
|
}""",
|
|
|
|
|
urls,
|
|
|
|
|
)
|
|
|
|
|
assert result == {"frames": 3, "captions": 3, "links": 2}
|
|
|
|
|
|
|
|
|
|
|
2026-06-18 22:09:34 +00:00
|
|
|
def test_content_code_block_has_copy_button(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
_create_post(page, "snippet\n\n```python\nprint('hi')\n```", "Code copy host post")
|
|
|
|
|
btn = page.locator(".post-detail-content pre.code-has-copy .code-copy-btn").first
|
|
|
|
|
btn.wait_for(state="visible")
|
|
|
|
|
assert btn.inner_text().strip().lower() == "copy"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_feed_title_emoji_rendered_server_side(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
_create_post(page, "Body content for the feed server-rendered title test.", "Feed title :fire:")
|
|
|
|
|
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
|
|
|
card_title = page.locator(".post-title").first
|
|
|
|
|
card_title.wait_for(state="visible")
|
|
|
|
|
assert FIRE in card_title.text_content()
|
|
|
|
|
assert page.locator("dp-title").count() == 0
|