| 1 | import asyncio |
| 2 | |
| 3 | from patchright.async_api import async_playwright |
| 4 | |
| 5 | from uploader.ks_uploader.main import _click_visible_publish_confirm |
| 6 | |
| 7 | |
| 8 | def test_click_visible_publish_confirm_uses_modal_primary_button(): |
| 9 | async def scenario(): |
| 10 | async with async_playwright() as playwright: |
| 11 | browser = await playwright.chromium.launch(headless=True, channel="chrome") |
| 12 | page = await browser.new_page() |
| 13 | await page.set_content( |
| 14 | """ |
| 15 | <div class="ant-modal-confirm-centered"> |
| 16 | <button type="button">取消</button> |
| 17 | <button type="button" class="ant-btn-primary">确认发布</button> |
| 18 | </div> |
| 19 | """ |
| 20 | ) |
| 21 | await page.locator("button.ant-btn-primary").evaluate( |
| 22 | "button => button.addEventListener('click', () => window.publishConfirmed = true)" |
| 23 | ) |
| 24 | |
| 25 | assert await _click_visible_publish_confirm(page) is True |
| 26 | assert await page.evaluate("window.publishConfirmed") is True |
| 27 | await browser.close() |
| 28 | |
| 29 | asyncio.run(scenario()) |
| 30 | |
| 31 | |
| 32 | def test_click_visible_publish_confirm_is_noop_without_modal(): |
| 33 | async def scenario(): |
| 34 | async with async_playwright() as playwright: |
| 35 | browser = await playwright.chromium.launch(headless=True, channel="chrome") |
| 36 | page = await browser.new_page() |
| 37 | await page.set_content("<button>发布</button>") |
| 38 | |
| 39 | assert await _click_visible_publish_confirm(page) is False |
| 40 | await browser.close() |
| 41 | |
| 42 | asyncio.run(scenario()) |
| 43 |