File size: 2,705 Bytes
f91bd05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
"""
Playwright E2E tests for FireTracker.

Requires:
  - Server running: cd ~/Projekte/FireTracker && .venv/bin/uvicorn main:app --port 8050
  - Browsers installed: playwright install chromium
"""
import pytest

pw = pytest.importorskip("playwright")
from playwright.sync_api import Page, expect


def test_setup_flow(page: Page, base_url: str) -> None:
    """Fill the 3-field setup wizard and assert redirect to dashboard."""
    page.goto(f"{base_url}/setup")

    # Verify we are on the setup page
    expect(page.locator("h1")).to_contain_text("Willkommen")

    # Fill the three required fields (name= attributes from setup.html)
    page.fill('input[name="monthly_income"]', "4200")
    page.fill('input[name="monthly_expenses"]', "2100")
    page.fill('input[name="birth_year"]', "1995")

    # Submit — /api/setup returns 303 redirect to /
    page.click('button[type="submit"]')

    # After redirect the URL must be the dashboard
    page.wait_for_url(f"{base_url}/", timeout=5000)

    # Dashboard heading must be present
    expect(page.locator("h1")).to_contain_text("Dashboard")


def test_dashboard_loads_after_setup(page: Page, base_url: str) -> None:
    """Dashboard shows FI metrics and the Chart.js projection canvas."""
    page.goto(base_url)

    # If no profile exists yet we would land on /setup — skip gracefully
    if "/setup" in page.url:
        pytest.skip("No profile present; run test_setup_flow first or use seed.py")

    # FI progress section (dashboard.html line 26 — "FI Fortschritt")
    expect(page.locator("text=FI Fortschritt")).to_be_visible()

    # Savings-rate card (dashboard.html line 43 — "Sparrate")
    expect(page.locator("text=Sparrate")).to_be_visible()

    # Chart.js canvas for the 30-year projection (id="timelineChart")
    expect(page.locator("#timelineChart")).to_be_visible()


def test_asset_crud_flow(page: Page, base_url: str) -> None:
    """Add an asset via the /assets form and verify it appears in the list."""
    page.goto(f"{base_url}/assets")

    # The "Neues Asset" form (assets.html lines 15-52)
    page.fill('input[name="name"]', "Test-ETF")

    # Select asset type — default is "depot" which is fine; set explicitly
    page.select_option('select[name="asset_type"]', "depot")

    page.fill('input[name="current_value"]', "10000")
    page.fill('input[name="monthly_contribution"]', "500")

    # Submit — /api/assets returns 303 redirect to /assets
    page.click('button[type="submit"]')

    # Wait for the redirect back to /assets
    page.wait_for_url(f"{base_url}/assets", timeout=5000)

    # The new asset name must appear somewhere on the page
    expect(page.locator("text=Test-ETF")).to_be_visible()