|
import re
|
|
|
|
from playwright.sync_api import expect
|
|
|
|
from tests.conftest import BASE_URL
|
|
|
|
|
|
def _open_composer(page):
|
|
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()
|
|
|
|
|
|
def _create_plain_post(page, content):
|
|
_open_composer(page)
|
|
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_poll_builder_hidden_until_add_poll(alice):
|
|
page, _ = alice
|
|
_open_composer(page)
|
|
expect(page.locator("[data-poll-builder]")).to_be_hidden()
|
|
page.locator("[data-poll-toggle]").click()
|
|
expect(page.locator("[data-poll-builder]")).to_be_visible()
|
|
|
|
|
|
def test_create_poll_and_vote(alice):
|
|
page, _ = alice
|
|
_open_composer(page)
|
|
page.fill("#post-content", "Post that carries a poll for the UI test.")
|
|
page.locator("[data-poll-toggle]").click()
|
|
page.fill("#create-post-modal input[name='poll_question']", "Tabs or spaces?")
|
|
options = page.locator("#create-post-modal input[name='poll_options']")
|
|
options.nth(0).fill("Tabs")
|
|
options.nth(1).fill("Spaces")
|
|
page.locator("#create-post-modal button.btn-primary:has-text('Post')").click()
|
|
page.wait_for_url(f"{BASE_URL}/posts/*", wait_until="domcontentloaded")
|
|
|
|
expect(page.locator(".poll-question")).to_have_text("Tabs or spaces?")
|
|
expect(page.locator(".poll-option")).to_have_count(2)
|
|
|
|
page.locator(".poll-option").first.click()
|
|
expect(page.locator(".poll-option").first).to_have_class(re.compile(r"\bchosen\b"))
|
|
expect(page.locator(".poll-option").first.locator(".poll-option-pct")).to_be_visible()
|
|
|
|
|
|
def test_remove_poll_does_not_create_poll(alice):
|
|
page, _ = alice
|
|
_open_composer(page)
|
|
page.fill("#post-content", "Post where the poll is added then removed before posting.")
|
|
page.locator("[data-poll-toggle]").click()
|
|
page.fill("#create-post-modal input[name='poll_question']", "Discarded question?")
|
|
options = page.locator("#create-post-modal input[name='poll_options']")
|
|
options.nth(0).fill("One")
|
|
options.nth(1).fill("Two")
|
|
page.locator("[data-poll-toggle]").click()
|
|
page.locator("#create-post-modal button.btn-primary:has-text('Post')").click()
|
|
page.wait_for_url(f"{BASE_URL}/posts/*", wait_until="domcontentloaded")
|
|
expect(page.locator(".poll")).to_have_count(0)
|
|
|
|
|
|
def test_reaction_palette_toggle_and_react(alice):
|
|
page, _ = alice
|
|
_create_plain_post(page, "Post to react to in the reaction UI test.")
|
|
|
|
expect(page.locator(".reaction-chip:visible")).to_have_count(0)
|
|
expect(page.locator(".reaction-palette").first).to_be_hidden()
|
|
|
|
page.locator(".reaction-add-btn").first.click()
|
|
expect(page.locator(".reaction-palette").first).to_be_visible()
|
|
|
|
page.locator(".reaction-palette-btn").first.click()
|
|
expect(page.locator(".reaction-chip.reacted").first).to_be_visible()
|
|
expect(page.locator(".reaction-chip.reacted").first.locator(".reaction-count")).to_have_text("1")
|