File size: 3,727 Bytes
f87fe7f
 
 
2b5a90d
f87fe7f
 
 
 
 
 
 
 
2b5a90d
 
 
 
 
 
 
f87fe7f
 
 
2b5a90d
f87fe7f
 
 
 
 
 
2b5a90d
 
 
f87fe7f
2b5a90d
f87fe7f
2b5a90d
f87fe7f
 
 
2b5a90d
f87fe7f
2b5a90d
f87fe7f
 
 
2b5a90d
f87fe7f
 
 
2b5a90d
f87fe7f
 
 
 
 
 
 
 
 
 
 
 
2b5a90d
f87fe7f
2b5a90d
 
f87fe7f
 
2b5a90d
f87fe7f
2b5a90d
f87fe7f
 
 
 
 
 
2b5a90d
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
"""
Chat interaction tests β€” verify the chat responds correctly to user input.

Tests navigate to the Chat sub-tab before interacting.

Run with: pytest tests/e2e_chat.py -v
"""
import pytest
from playwright.sync_api import Page, expect
from tests.conftest import logged_in_page, get_chat_textarea, wait_for_response  # noqa: F401


def go_to_chat(page: Page):
    """Navigate to the Chat sub-tab."""
    page.click('button[role=tab]:has-text("Chat")')
    page.wait_for_timeout(1000)
    expect(page.locator('button:has-text("Send")')).to_be_visible(timeout=15000)


def send_message(page: Page, text: str):
    """Type and send a chat message."""
    chat_input = get_chat_textarea(page)
    expect(chat_input).to_be_visible(timeout=30000)
    chat_input.click()
    chat_input.fill(text)
    page.click('button:has-text("Send")')


class TestChatBasics:
    def test_chat_input_responds(self, logged_in_page: Page):
        """Chat input accepts text and Send works."""
        go_to_chat(logged_in_page)
        send_message(logged_in_page, "help")
        wait_for_response(logged_in_page, timeout_ms=60000)
        body_text = logged_in_page.inner_text('body')
        assert len(body_text) > 200

    def test_message_clears_after_send(self, logged_in_page: Page):
        """Chat input is cleared after sending a message."""
        go_to_chat(logged_in_page)
        chat_input = get_chat_textarea(logged_in_page)
        expect(chat_input).to_be_visible(timeout=30000)
        chat_input.click()
        chat_input.fill("hello")
        logged_in_page.click('button:has-text("Send")')
        expect(chat_input).to_have_value("", timeout=10000)

    def test_invalid_input_gets_response(self, logged_in_page: Page):
        """Nonsense input still gets a graceful response."""
        go_to_chat(logged_in_page)
        send_message(logged_in_page, "asdfghjkl zxcvbnm")
        wait_for_response(logged_in_page, timeout_ms=30000)
        body_text = logged_in_page.inner_text('body')
        assert len(body_text) > 200


class TestTabNavigation:
    def test_can_switch_to_settings_tab(self, logged_in_page: Page):
        """Settings tab is clickable and shows settings content."""
        logged_in_page.click('button[role=tab]:has-text("βš™οΈ Settings")')
        logged_in_page.wait_for_timeout(1000)
        body_text = logged_in_page.inner_text('body')
        assert any(word in body_text.lower() for word in ["settings", "save", "model"])

    def test_can_switch_back_to_app(self, logged_in_page: Page):
        """Can navigate away from and back to the App tab."""
        logged_in_page.click('button[role=tab]:has-text("βš™οΈ Settings")')
        logged_in_page.wait_for_timeout(500)
        logged_in_page.click('button[role=tab]:has-text("πŸ“± App")')
        logged_in_page.wait_for_timeout(500)
        expect(logged_in_page.locator('button:has-text("β†’ GO")')).to_be_visible(timeout=10000)

    def test_live_progress_tab_loads(self, logged_in_page: Page):
        """Live Progress tab is accessible and renders."""
        logged_in_page.click('button[role=tab]:has-text("Live Progress")')
        logged_in_page.wait_for_timeout(1000)
        tab = logged_in_page.locator('button[role=tab]:has-text("Live Progress")')
        expect(tab).to_have_attribute('aria-selected', 'true', timeout=5000)

    def test_demo_assets_tab_loads(self, logged_in_page: Page):
        """Demo Assets tab is accessible."""
        logged_in_page.click('button[role=tab]:has-text("🎬 Demo Assets")')
        logged_in_page.wait_for_timeout(1000)
        tab = logged_in_page.locator('button[role=tab]:has-text("🎬 Demo Assets")')
        expect(tab).to_have_attribute('aria-selected', 'true', timeout=5000)