# retoor import time from playwright.sync_api import expect from tests.conftest import BASE_URL JSON = {"Accept": "application/json"} def _create_post(page, content): 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.fill("#post-title", f"Requested {int(time.time() * 1000)}") page.fill("#post-content", content) 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_is_first_and_focused(alice): page, _user = alice 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() title = page.locator("#post-title") expect(title).to_be_focused() order = page.evaluate( """() => { const title = document.querySelector('#post-title'); const content = document.querySelector('#post-content'); return (title.compareDocumentPosition(content) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0; }""" ) assert order is True def test_post_detail_groups_secondary_actions_in_more_menu(alice): page, _user = alice _create_post(page, "Menu grouping post content.") expect(page.locator(".post-votes")).to_be_visible() expect(page.locator("[data-action-menu-trigger]")).to_be_visible() panel = page.locator("#post-actions-panel") expect(panel).to_be_hidden() page.locator("[data-action-menu-trigger]").click() expect(panel).to_be_visible() expect(panel.locator("[data-share]")).to_be_visible() expect(panel.locator(".bookmark-btn")).to_be_visible() page.keyboard.press("Escape") expect(panel).to_be_hidden() def test_comment_enter_posts_and_shift_enter_newlines(alice): page, user = alice username = user["username"] try: _create_post(page, "Enter key comment post content.") box = page.locator(".comment-form textarea[name='content']").first box.click() box.fill("First line") box.press("Shift+Enter") box.type("second line") assert "\n" in box.input_value() box.fill("Posted by Enter key") box.press("Enter") expect(page.locator(".comment-text", has_text="Posted by Enter key").first).to_be_visible(timeout=10000) finally: page.request.post( f"{BASE_URL}/profile/{username}/enter-to-submit", form={"value": "true"}, headers=JSON, ) def test_comment_enter_newlines_when_setting_off(alice): page, user = alice username = user["username"] resp = page.request.post( f"{BASE_URL}/profile/{username}/enter-to-submit", form={"value": "false"}, headers=JSON, ) assert resp.status == 200 try: _create_post(page, "Enter off comment post content.") box = page.locator(".comment-form textarea[name='content']").first box.click() box.fill("Not posted yet") box.press("Enter") box.type("still editing") assert "still editing" in box.input_value() expect(page.locator(".comment-text", has_text="Not posted yet")).to_have_count(0) finally: page.request.post( f"{BASE_URL}/profile/{username}/enter-to-submit", form={"value": "true"}, headers=JSON, )