# retoor import time from playwright.sync_api import expect from tests.conftest import BASE_URL, assert_no_horizontal_overflow def _create(page, title, visibility=None): page.goto(f"{BASE_URL}/projects", wait_until="domcontentloaded") page.locator("#create-project-btn").click() page.fill("#title", title) page.fill("#description", "visibility e2e project") if visibility: page.select_option("#project-visibility", visibility) page.click("button:has-text('Create Project')") page.wait_for_url(f"{BASE_URL}/projects/*", wait_until="domcontentloaded") return page.url def _open_edit(page): page.locator("[data-menu-label='Edit']").first.evaluate("el => el.click()") def _edit_visibility(page, url, value): page.goto(url, wait_until="domcontentloaded") _open_edit(page) page.select_option("#edit-project-visibility", value) page.locator("#edit-project-modal button.btn-primary").click() page.wait_for_url(url, wait_until="domcontentloaded") def _listed(page, title): page.goto(f"{BASE_URL}/projects?search={title}", wait_until="domcontentloaded") return page.locator(f"text={title}").count() > 0 def _title(prefix): return f"{prefix}{int(time.time() * 1000)}" def test_project_create_form_offers_the_three_visibility_choices(alice): page, _ = alice page.goto(f"{BASE_URL}/projects", wait_until="domcontentloaded") page.locator("#create-project-btn").click() options = page.locator("#project-visibility option") assert options.all_text_contents() == ["Published", "Hidden", "Offline"] expect(page.locator("#project-visibility")).to_have_value("published") def test_project_created_offline_is_only_visible_to_its_owner(alice, bob): page, _ = alice other, _ = bob title = _title("VisProjOffline") url = _create(page, title, "offline") assert not _listed(other, title) other.goto(url, wait_until="domcontentloaded") assert other.locator(f"h1:has-text('{title}')").count() == 0 page.goto(url, wait_until="domcontentloaded") expect(page.locator(f"h1:has-text('{title}')").first).to_be_visible() def test_project_edit_form_toggles_visibility(alice, bob): page, _ = alice other, _ = bob title = _title("VisProjToggle") url = _create(page, title) assert _listed(other, title) _edit_visibility(page, url, "hidden") assert not _listed(other, title) other.goto(url, wait_until="domcontentloaded") expect(other.locator(f"h1:has-text('{title}')").first).to_be_visible() _edit_visibility(page, url, "published") assert _listed(other, title) def test_project_edit_form_shows_the_current_status(alice): page, _ = alice url = _create(page, _title("VisProjCurrent"), "hidden") page.goto(url, wait_until="domcontentloaded") _open_edit(page) expect(page.locator("#edit-project-visibility")).to_have_value("hidden") def test_project_visibility_field_fits_a_phone(mobile_page): page, _ = mobile_page _create(page, _title("VisProjPhone"), "hidden") assert_no_horizontal_overflow(page, ".project-page")