File size: 2,493 Bytes
a281968
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import re
from playwright.sync_api import Page, expect
from conftest import wait_for_sync_idle

def test_system_truth_data_consistency(authenticated_page: Page):
    """Create, edit, reload, and verify UI matches DB consistency."""
    page = authenticated_page
    
    sidebar = page.locator("#docs-sidebar")
    sidebar.wait_for(state="attached")
    
    # Open sidebar if needed
    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")
    
    # Create doc
    page.once("dialog", lambda dialog: dialog.accept("Truth Validation Doc"))
    new_btn = page.locator("#docs-new-btn")
    new_btn.wait_for(state="visible", timeout=10000)
    new_btn.evaluate("el => el.click()")
    
    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("Deterministic truth data consistency test.", delay=10)
    
    wait_for_sync_idle(page)
    
    # Verify title in sidebar
    expect(page.locator(".doc-list-item__title").last).to_contain_text("Truth Validation Doc", timeout=5000)
    
    # Reload and verify
    page.reload()
    page.wait_for_load_state("networkidle")
    
    editor = page.locator("#editor-container")
    editor.wait_for(state="visible")
    expect(editor).to_contain_text("Deterministic truth data consistency test.", timeout=10000)

def test_system_truth_crash_recovery(authenticated_page: Page):
    """Simulate refresh during active save and ensure recovery."""
    page = authenticated_page
    
    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})); }")
    
    # Type and immediately crash/reload before debounce triggers
    editor.press_sequentially("Crash recovery testing payload.", delay=10)
    page.reload()
    page.wait_for_load_state("networkidle")
    
    # Verify recovery from localStorage queue
    editor = page.locator("#editor-container")
    editor.wait_for(state="visible")
    expect(editor).to_contain_text("Crash recovery testing payload.", timeout=10000)
    
    # Ensure it ultimately saves to cloud
    wait_for_sync_idle(page)