You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.1 KiB
60 lines
2.1 KiB
from __future__ import annotations
|
|
|
|
from uuid import uuid4
|
|
|
|
from playwright.sync_api import Page, expect
|
|
|
|
from tests.e2e.helpers import expect_flash, expect_path, login
|
|
|
|
|
|
def _unique_suffix() -> str:
|
|
return uuid4().hex[:8]
|
|
|
|
|
|
def test_admin_can_filter_audit_logs_and_open_detail(
|
|
page: Page,
|
|
base_url: str,
|
|
admin_credentials: dict[str, str],
|
|
) -> None:
|
|
suffix = _unique_suffix()
|
|
username = f"audit-user-{suffix}"
|
|
display_name = f"审计账号{suffix}"
|
|
|
|
login(
|
|
page,
|
|
base_url,
|
|
username=admin_credentials["username"],
|
|
password=admin_credentials["password"],
|
|
expected_path="/",
|
|
)
|
|
|
|
page.get_by_role("link", name="账号管理").click()
|
|
page.get_by_role("link", name="新增账号").click()
|
|
page.locator("#username").fill(username)
|
|
page.locator("#display_name").fill(display_name)
|
|
page.locator("#role").select_option("entry_only")
|
|
page.locator("#password").fill("EntryPass123!")
|
|
page.locator("#confirm_password").fill("EntryPass123!")
|
|
page.get_by_role("button", name="创建账号").click()
|
|
expect_flash(page, f"已创建账号 {username}。")
|
|
|
|
page.get_by_role("link", name="审计日志").click()
|
|
expect_path(page, base_url, "/admin/audit-logs")
|
|
expect(page.get_by_role("heading", name="审计日志")).to_be_visible()
|
|
|
|
page.locator("select[name='action_type']").select_option("create_account")
|
|
page.get_by_role("button", name="筛选").click()
|
|
|
|
audit_row = page.locator("tbody tr").first
|
|
expect(audit_row.get_by_text("create_account", exact=True)).to_be_visible()
|
|
|
|
audit_row.get_by_role("link", name="查看").click()
|
|
expect(page.get_by_role("heading", name="审计详情")).to_be_visible()
|
|
expect(page.get_by_text("Before 快照")).to_be_visible()
|
|
expect(page.get_by_text("After 快照")).to_be_visible()
|
|
expect(page.get_by_text("动作")).to_be_visible()
|
|
expect(page.locator("dd").filter(has_text="create_account")).to_be_visible()
|
|
expect(page.locator("pre").nth(1)).to_contain_text(username)
|
|
|
|
page.get_by_role("link", name="返回日志列表").click()
|
|
expect_path(page, base_url, "/admin/audit-logs")
|
|
|