| from playwright.sync_api import Page, expect |
| from conftest import wait_for_sync_idle |
|
|
| def test_document_lifecycle(authenticated_page: Page): |
| """Test creating, switching, and reloading documents deterministically.""" |
| page = authenticated_page |
| |
| sidebar = page.locator("#docs-sidebar") |
| sidebar.wait_for(state="attached") |
| |
| |
| expected_title_ref = ["Test Document 0"] |
| page.on("dialog", lambda dialog: dialog.accept(expected_title_ref[0])) |
| |
| |
| for i in range(3): |
| |
| if "is-open" not in sidebar.get_attribute("class"): |
| page.evaluate("document.getElementById('docs-sidebar-toggle').click()") |
| |
| expect(sidebar).to_have_class("docs-sidebar is-open") |
| |
| expected_title_ref[0] = f"Test Document {i}" |
| |
| |
| new_btn = page.locator("#docs-new-btn") |
| new_btn.wait_for(state="visible", timeout=10000) |
| new_btn.evaluate("el => el.click()") |
| |
| |
| expect(page.locator(f".doc-list-item__title:has-text('{expected_title_ref[0]}')").first).to_be_visible(timeout=10000) |
| |
| |
| editor = page.locator("#editor-container") |
| editor.wait_for(state="visible") |
| editor.click() |
| editor.focus() |
| editor.evaluate("el => { el.innerHTML = ''; el.dispatchEvent(new Event('input', {bubbles: true})); }") |
| editor.press_sequentially(f"Content for document {i}", delay=10) |
| |
| |
| wait_for_sync_idle(page) |
| |
| |
| if "is-open" not in sidebar.get_attribute("class"): |
| page.evaluate("document.getElementById('docs-sidebar-toggle').click()") |
| expect(sidebar).to_have_class("docs-sidebar is-open") |
| |
| docs = page.locator(".doc-list-item__title").all() |
| assert len(docs) >= 3, "Not all documents were created" |
| |
| |
| docs[-1].evaluate("el => el.click()") |
| |
| |
| editor = page.locator("#editor-container") |
| expect(editor).to_contain_text("Content for document 0", timeout=10000) |
| |
| |
| page.reload() |
| page.wait_for_load_state("networkidle") |
| |
| editor = page.locator("#editor-container") |
| editor.wait_for(state="visible") |
| expect(editor).to_contain_text("Content for document 0", timeout=10000) |
|
|