from __future__ import annotations import re from uuid import uuid4 from playwright.sync_api import Page, expect from tests.e2e.helpers import expect_sidebar_link, login def test_entry_user_can_search_select_and_save_limited_fields( page: Page, base_url: str, entry_credentials: dict[str, str], ) -> None: login(page, base_url, username=entry_credentials["username"], password=entry_credentials["password"]) expect(page).to_have_url(f"{base_url}/quick-entry/") expect(page.get_by_role("heading", name="快速录入")).to_be_visible() expect_sidebar_link(page, "快速录入") expect(page.get_by_role("link", name="管理首页")).to_have_count(0) page.locator("#quick-entry-search").fill("李阿姨") page.locator("#quick-entry-search").press("Enter") expect(page.get_by_role("heading", name="搜索结果")).to_be_visible() expect(page.get_by_text("李阿姨")).to_have_count(0) page.get_by_label("包含女方").check() expect(page.get_by_text("李阿姨")).to_be_visible() page.get_by_role("link", name="点击编辑").first.click() expect(page.locator("#quick-entry-edit-modal")).to_be_visible() expect(page.locator("#quick-entry-edit-modal")).to_contain_text("李阿姨") expect(page.locator("#attendance_status")).to_have_count(0) expect(page.locator("#gift_method_option_id")).to_have_count(0) expect(page.locator("#gift_scene_option_id")).to_have_count(0) page.locator("#head_name").fill("李阿姨-更新") page.locator("#total_gift_amount").fill("666.66") page.locator("#note").fill("快速录入自动化更新") page.get_by_role("button", name="保存并返回搜索").click() expect(page.get_by_text("已保存 李阿姨-更新 的礼金信息。")).to_be_visible() expect(page).to_have_url(f"{base_url}/quick-entry/?q=%E6%9D%8E%E9%98%BF%E5%A7%A8&include_bride_side=1") expect(page.locator("#quick-entry-search")).to_have_value("李阿姨") expect(page.get_by_label("包含女方")).to_be_checked() expect(page.get_by_role("heading", name="李阿姨-更新")).to_be_visible() def test_quick_editor_can_search_create_and_reedit_household_from_quick_entry( page: Page, base_url: str, quick_editor_credentials: dict[str, str], ) -> None: unique_name = f"专项新增户{uuid4().hex[:6]}" renamed_name = f"{unique_name}-改" login(page, base_url, username=quick_editor_credentials["username"], password=quick_editor_credentials["password"]) expect(page).to_have_url(f"{base_url}/quick-entry/") expect(page.get_by_role("link", name="管理首页")).to_have_count(0) page.locator("#quick-entry-search").fill(unique_name) page.locator("#quick-entry-search").press("Enter") expect(page.get_by_text("没有找到匹配的户")).to_be_visible() page.get_by_role("link", name="新增").first.click() expect(page).to_have_url(re.compile(rf".*/quick-entry/households/new\?q=.*{re.escape(unique_name[-6:])}$")) expect(page.get_by_role("heading", name="新增一户", exact=True)).to_be_visible() page.locator("#quick-create-head-name").fill(unique_name) page.locator("#quick-create-total-gift-amount").fill("388.00") page.locator("#quick-create-note").fill("E2E 快速新增") page.get_by_role("button", name="保存并返回搜索").click() expect(page).to_have_url(re.compile(rf".*/quick-entry/\?q=.*{re.escape(unique_name[-6:])}$")) expect(page.get_by_text(f"已快速创建 {unique_name} 并记录礼金。")).to_be_visible() expect(page.get_by_role("heading", name=unique_name)).to_be_visible() page.get_by_role("link", name="点击编辑").first.click() expect(page.locator("#quick-entry-edit-modal")).to_be_visible() page.locator("#head_name").fill(renamed_name) page.locator("#note").fill("E2E 二次编辑备注") page.get_by_role("button", name="保存并返回搜索").click() expect(page.get_by_text(f"已保存 {renamed_name} 的礼金信息。")).to_be_visible() expect(page.get_by_role("heading", name=renamed_name)).to_be_visible()